2009-06-20 Marcus Brinkmann <marcus@g10code.com>
[gpg4win.git] / src / gpg4win.mk.in
1 # gpg4win.m4.in - Installer for GnuPG 4 Windows Makefile.   -*- makefile -*-
2 # Copyright (C) 2005, 2009 g10 Code GmbH
3
4 # This file is part of GPG4Win.
5
6 # GPG4Win is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # GPG4Win is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
20
21 # No servicable parts below this line :)
22
23
24 # These paths must be absolute, as we switch directories pretty often.
25 root := $(shell pwd)/playground
26 bdir := $(root)/build
27 idir := $(root)/install
28 ipdir := $(root)/install/pkgs
29 tsdir := $(shell pwd)/${top_srcdir}
30 pdir := $(shell pwd)/${top_srcdir}/patches
31
32 # We collect the names of all pkg files used.
33 pkg_files =
34
35 # The playground area is our scratch area, where we unpack, build and
36 # install the packages.
37 stamps/stamp-directories:
38         $(MKDIR) stamps
39         $(MKDIR) playground
40         $(MKDIR) $(bdir)
41         $(MKDIR) $(idir)
42         $(MKDIR) $(ipdir)
43         touch $(bdir)/versioninfo.txt
44         touch stamps/stamp-directories
45
46
47 # Frob the name $1 by converting all '-' and '+' characters to '_'.
48 define FROB_macro
49 $(subst +,_,$(subst -,_,$(1)))
50 endef
51
52 # Get the variable $(1) (which may contain '-' and '+' characters).
53 define GETVAR
54 $($(call FROB_macro,$(1)))
55 endef
56
57 # Set a couple of common variables.
58 define SETVARS
59         pkg="$(call GETVAR,gpg4win_pkg_$(1))";                          \
60         pkg_version="$(1)-$(call GETVAR,gpg4win_pkg_$(1)_version)";     \
61         pkgsdir="$(bdir)/$$$${pkg_version}";                            \
62         pkgbdir="$(bdir)/$$$${pkg_version}-build";                      \
63         pkgpdir="$(pdir)/$$$${pkg_version}";                            \
64         pkgpbdir="$(pdir)/$(1)";                                        \
65         pkgidir="$(ipdir)/$$$${pkg_version}";                           \
66         pkg_dev="$(call GETVAR,gpg4win_pkg_$(1)_dev)";                  \
67         pkg_version_dev="$(1)-dev-$(call GETVAR,gpg4win_pkg_$(1)_version)"; \
68         pkgidir_dev="$(ipdir)/$$$${pkg_version_dev}";                   \
69         pkgcfg="$(call GETVAR,gpg4win_pkg_$(1)_configure)";             \
70         pkgmkargs="$(call GETVAR,gpg4win_pkg_$(1)_make_args)";          \
71         pkgmkargs_inst="$(call GETVAR,gpg4win_pkg_$(1)_make_args_inst)";\
72         export PKG_CONFIG="$(tsdir)/src/pkg-config";                    \
73         export PKG_CONFIG_PATH="$(idir)/lib/pkgconfig";                 \
74         export PKG_CONFIG_LIBDIR="";                                    \
75         export PATH="$(idir)/bin:$${PATH}";                             \
76         export SYSROOT="$(idir)";                                       \
77         export CONFIG_SITE="$(tsdir)/src/config.site"
78 endef
79
80 # Support macro.  Unpack the archive $(1).
81 define DEFLATE_macro
82         case "$(1)" in                  \
83           */gnupg2-2.*.tar.bz2)          \
84             $(TAR) -xj --transform='s,^gnupg-,gnupg2-,' -f "$(1)" ;; \
85           *.tar.gz | *.tgz)             \
86             $(TAR) xzf "$(1)" ;;        \
87           *.tar.bz2 | *.tbz2 | *.tbz)   \
88             $(TAR) xjf "$(1)" ;;        \
89           *.zip)                        \
90             $(UNZIP) -o "$(1)" ;;               \
91         esac
92 endef
93
94 # Support macro.  Strip all exe files below $(1).
95 define STRIP_macro
96         if test -z '$(DEBUG)'; then                     \
97           (cd $(1);                                     \
98            for f in `find . -name \*.exe -o -name \*.dll`; do           \
99            echo Calling $(STRIP) "$$$${pkg_version}/$$$${f}"; \
100            $(STRIP) "$$$${f}"; done);                   \
101         fi
102 endef
103
104 define GETDEPS
105   $(addprefix stamps/stamp-final-, $(call GETVAR,gpg4win_pkg_$(1)_deps))
106 endef
107
108
109 # Template for source packages.
110
111 define SPKG_template_
112
113 pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
114
115 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories $(call GETDEPS,$(1))
116         (cd $(bdir);                                    \
117          $(call SETVARS,$(1));                          \
118          $(call DEFLATE_macro,$$$${pkg}))
119         touch stamps/stamp-$(1)-00-unpack
120
121 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
122         (shopt -s nullglob;                             \
123          $(call SETVARS,$(1));                          \
124          for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do  \
125            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
126          done)
127         touch stamps/stamp-$(1)-01-patch
128
129 stamps/stamp-$(1)-02-configure: stamps/stamp-$(1)-01-patch
130         ($(call SETVARS,$(1));                          \
131          mkdir "$$$${pkgbdir}";                         \
132           cd "$$$${pkgbdir}";                           \
133          eval "../$$$${pkg_version}/configure"          \
134                 --prefix="$$$${pkgidir}"                \
135                 --host=$(host_cpu)-$(host_os)           \
136                 --build=$(build_cpu)-$(build_os)        \
137                 $$$${pkgcfg} CFLAGS=-mms-bitfields)
138         touch stamps/stamp-$(1)-02-configure
139
140 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-02-configure
141         ($(call SETVARS,$(1));                          \
142           cd "$$$${pkgbdir}";                           \
143           $(MAKE) $(AM_MAKEFLAGS) $(GPG4WIN_PARALLEL) $$$${pkgmkargs} || \
144           $(MAKE) $(AM_MAKEFLAGS) $(GPG4WIN_PARALLEL) $$$${pkgmkargs} || \
145           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
146         touch stamps/stamp-$(1)-03-make
147
148 # Note that post_install must come last because it may be empty and
149 # "; ;" is a syntax error.
150 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
151         ($(call SETVARS,$(1));                          \
152           cd "$$$${pkgbdir}";                           \
153           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
154           $(call STRIP_macro,"$$$${pkgidir}"); \
155           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
156         touch stamps/stamp-$(1)-04-install
157
158 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
159         ($(call SETVARS,$(1));                          \
160          cd $(ipdir);                                   \
161          $(STOW) "$$$${pkg_version}")
162         touch stamps/stamp-$(1)-05-stow
163
164 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
165         touch stamps/stamp-final-$(1)
166
167 .PHONY : clean-$(1)
168 clean-$(1):
169         ($(call SETVARS,$(1));                          \
170          (cd $(ipdir) &&                                \
171           ($(STOW) -D "$$$${pkg_version}";              \
172            rm -fR "$$$${pkg_version}"));                \
173          rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}")
174         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
175
176 endef
177
178 define SPKG_template
179 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
180   $(call SPKG_template_,$1))
181 endef
182
183
184 # Template for source packages using only make and no build
185 # directory.
186
187 define MPKG_template_
188
189 pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
190
191 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories $(call GETDEPS,$(1))
192         (cd $(bdir);                                    \
193          $(call SETVARS,$(1));                          \
194          $(call DEFLATE_macro,$$$${pkg}))
195         touch stamps/stamp-$(1)-00-unpack
196
197 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
198         (shopt -s nullglob;                             \
199          $(call SETVARS,$(1));                          \
200          for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do \
201            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
202          done)
203         touch stamps/stamp-$(1)-01-patch
204
205 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-01-patch
206         ($(call SETVARS,$(1));                          \
207           cd "$$$${pkgsdir}";                           \
208           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
209         touch stamps/stamp-$(1)-03-make
210
211 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
212         ($(call SETVARS,$(1));                          \
213           cd "$$$${pkgsdir}";                           \
214           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
215           $(call STRIP_macro,"$$$${pkgidir}"))
216         touch stamps/stamp-$(1)-04-install
217
218 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
219         ($(call SETVARS,$(1));                          \
220          cd $(ipdir);                                   \
221          $(STOW) "$$$${pkg_version}")
222         touch stamps/stamp-$(1)-05-stow
223
224 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
225         touch stamps/stamp-final-$(1)
226
227 .PHONY : clean-$(1)
228 clean-$(1):
229         ($(call SETVARS,$(1));                          \
230          (cd $(ipdir) &&                                \
231           ($(STOW) -D "$$$${pkg_version}";              \
232            rm -fR "$$$${pkg_version}"));                \
233          rm -fR "$$$${pkgsdir}"
234         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
235
236 endef
237
238 define MPKG_template
239 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
240   $(call MPKG_template_,$1))
241 endef
242
243
244
245 # Template for binary packages.
246
247 define BPKG_template_
248
249 pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
250 pkg_files += $(call GETVAR,gpg4win_pkg_$(1)_dev)
251
252 stamps/stamp-$(1)-00-install: stamps/stamp-directories $(call GETDEPS,$(1))
253         ($(call SETVARS,$(1));                          \
254          $(MKDIR) "$$$${pkgidir}";                      \
255          cd $$$${pkgidir};                              \
256          $(call DEFLATE_macro,$$$${pkg}))
257         touch stamps/stamp-$(1)-00-install
258
259 # Note that post_install must come last because it may be empty and
260 # "; ;" is a syntax error.
261 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
262         ($(call SETVARS,$(1));                          \
263          $(MKDIR) "$$$${pkgidir_dev}";                  \
264          (cd $$$${pkgidir_dev};                         \
265           $(call DEFLATE_macro,$$$${pkg_dev}));         \
266          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
267         touch stamps/stamp-$(1)-01-install-dev
268
269 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
270         ($(call SETVARS,$(1));                          \
271          cd $(ipdir);                                   \
272          $(STOW) "$$$${pkg_version}")
273         touch stamps/stamp-$(1)-02-stow
274
275 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
276         ($(call SETVARS,$(1));                          \
277          cd $(ipdir);                                   \
278          $(STOW) "$$$${pkg_version_dev}")
279         touch stamps/stamp-$(1)-03-stow-dev
280
281 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
282         touch stamps/stamp-final-$(1)
283
284 .PHONY : clean-$(1)
285 clean-$(1):
286         ($(call SETVARS,$(1));                          \
287          cd $(ipdir) &&                                 \
288          ($(STOW) -D "$$$${pkg_version}";               \
289           $(STOW) -D "$$$${pkg_version_dev}";           \
290           rm -fR "$$$${pkg_version}" "$$$${pkg_version_dev}"))
291         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
292
293 endef
294
295 define BPKG_template
296 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
297   $(call BPKG_template_,$1))
298 endef
299
300
301 # Template for internal packages.
302
303 define IPKG_template
304
305 stamps/stamp-final-$(1): stamps/stamp-directories $(call GETDEPS,$(1))
306         touch stamps/stamp-final-$(1)
307 endef
308
309
310 # Insert the template for each source package.
311 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
312
313 # Insert the template for each make only source package.
314 $(foreach mpkg, $(gpg4win_mpkgs), $(eval $(call MPKG_template,$(mpkg))))
315
316 # Insert the template for each binary package.
317 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
318
319 # Insert the template for each internal package.
320 $(foreach ipkg, $(gpg4win_ipkgs), $(eval $(call IPKG_template,$(ipkg))))
321
322 stamps/stamp-final: stamps/stamp-directories
323 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
324         touch stamps/stamp-final
325
326 $(bdir)/versioninfo.txt: stamps/stamp-final
327         touch $(bdir)/versioninfo.txt
328
329
330 all-gpg4win: stamps/stamp-final
331
332 # Just to check if we catched all stamps.
333 clean-stamps:
334         $(RM) -fR $(stamps)
335
336 clean-gpg4win:
337         $(RM) -fR playground stamps
338
339 .PHONY : all-gpg4win clean-stamps clean-gpg4win