735d8ed89ae7bacccc9936d4a6140e43f426dd92
[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           rm -f "$$$${pkgidir}/share/info/dir";         \
156           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
157         touch stamps/stamp-$(1)-04-install
158
159 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
160         ($(call SETVARS,$(1));                          \
161          cd $(ipdir);                                   \
162          $(STOW) "$$$${pkg_version}")
163         touch stamps/stamp-$(1)-05-stow
164
165 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
166         touch stamps/stamp-final-$(1)
167
168 .PHONY : clean-$(1)
169 clean-$(1):
170         ($(call SETVARS,$(1));                          \
171          (cd $(ipdir) &&                                \
172           ($(STOW) -D "$$$${pkg_version}";              \
173            rm -fR "$$$${pkg_version}"));                \
174          rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}")
175         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
176
177 endef
178
179 define SPKG_template
180 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
181   $(call SPKG_template_,$1))
182 endef
183
184
185 # Template for source packages using only make and no build
186 # directory.
187
188 define MPKG_template_
189
190 pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
191
192 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories $(call GETDEPS,$(1))
193         (cd $(bdir);                                    \
194          $(call SETVARS,$(1));                          \
195          $(call DEFLATE_macro,$$$${pkg}))
196         touch stamps/stamp-$(1)-00-unpack
197
198 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
199         (shopt -s nullglob;                             \
200          $(call SETVARS,$(1));                          \
201          for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do \
202            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
203          done)
204         touch stamps/stamp-$(1)-01-patch
205
206 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-01-patch
207         ($(call SETVARS,$(1));                          \
208           cd "$$$${pkgsdir}";                           \
209           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
210         touch stamps/stamp-$(1)-03-make
211
212 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
213         ($(call SETVARS,$(1));                          \
214           cd "$$$${pkgsdir}";                           \
215           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
216           $(call STRIP_macro,"$$$${pkgidir}"); \
217           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
218         touch stamps/stamp-$(1)-04-install
219
220 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
221         ($(call SETVARS,$(1));                          \
222          cd $(ipdir);                                   \
223          $(STOW) "$$$${pkg_version}")
224         touch stamps/stamp-$(1)-05-stow
225
226 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
227         touch stamps/stamp-final-$(1)
228
229 .PHONY : clean-$(1)
230 clean-$(1):
231         ($(call SETVARS,$(1));                          \
232          (cd $(ipdir) &&                                \
233           ($(STOW) -D "$$$${pkg_version}";              \
234            rm -fR "$$$${pkg_version}"));                \
235          rm -fR "$$$${pkgsdir}")
236         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
237
238 endef
239
240 define MPKG_template
241 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
242   $(call MPKG_template_,$1))
243 endef
244
245
246
247 # Template for binary packages.
248
249 define BPKG_template_
250
251 pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
252 pkg_files += $(call GETVAR,gpg4win_pkg_$(1)_dev)
253
254 stamps/stamp-$(1)-00-install: stamps/stamp-directories $(call GETDEPS,$(1))
255         ($(call SETVARS,$(1));                          \
256          $(MKDIR) "$$$${pkgidir}";                      \
257          cd $$$${pkgidir};                              \
258          $(call DEFLATE_macro,$$$${pkg}))
259         touch stamps/stamp-$(1)-00-install
260
261 # Note that post_install must come last because it may be empty and
262 # "; ;" is a syntax error.
263 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
264         ($(call SETVARS,$(1));                          \
265          $(MKDIR) "$$$${pkgidir_dev}";                  \
266          (cd $$$${pkgidir_dev};                         \
267           $(call DEFLATE_macro,$$$${pkg_dev}));         \
268          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
269         touch stamps/stamp-$(1)-01-install-dev
270
271 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
272         ($(call SETVARS,$(1));                          \
273          cd $(ipdir);                                   \
274          $(STOW) "$$$${pkg_version}")
275         touch stamps/stamp-$(1)-02-stow
276
277 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
278         ($(call SETVARS,$(1));                          \
279          cd $(ipdir);                                   \
280          $(STOW) "$$$${pkg_version_dev}")
281         touch stamps/stamp-$(1)-03-stow-dev
282
283 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
284         touch stamps/stamp-final-$(1)
285
286 .PHONY : clean-$(1)
287 clean-$(1):
288         ($(call SETVARS,$(1));                          \
289          cd $(ipdir) &&                                 \
290          ($(STOW) -D "$$$${pkg_version}";               \
291           $(STOW) -D "$$$${pkg_version_dev}";           \
292           rm -fR "$$$${pkg_version}" "$$$${pkg_version_dev}"))
293         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
294
295 endef
296
297 define BPKG_template
298 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
299   $(call BPKG_template_,$1))
300 endef
301
302
303 # Template for internal packages.
304
305 define IPKG_template
306
307 stamps/stamp-final-$(1): stamps/stamp-directories $(call GETDEPS,$(1))
308         touch stamps/stamp-final-$(1)
309 endef
310
311 # Template for README files
312 # (The final awk command converts the file endings).
313
314 define README_template
315 README.$(1).txt : versioninfo.txt NEWS.tmp $(top_srcdir)/doc/README.$(1).txt \
316                   $(top_srcdir)/doc/beta-warning.txt
317         sed -e '/^;.*/d;/!VERSIONINFO!/{r versioninfo.txt' -e 'd;}' \
318         -e '/!NEWSFILE!/{r NEWS.tmp' -e 'd;}' \
319         -e '/!NEWSFILE!/{r NEWS.tmp' -e 'd;}' \
320         -e '/!PKG-COPYRIGHT!/{r $(top_srcdir)/doc/pkg-copyright.txt' -e 'd;}' \
321         -e 's,!VERSION!,$(VERSION),g' \
322         -e 's,!BUILD_ISODATE!,$(BUILD_ISODATE),g' \
323            < $(top_srcdir)/doc/README.$(1).txt \
324            | (if echo "$(VERSION)" | egrep 'svn|rc|beta|git' >/dev/null; then \
325               sed -e '/!BETA-WARNING!/{r $(top_srcdir)/doc/beta-warning.txt' \
326                -e 'd;}'; else sed -e 's,!BETA-WARNING!,,g'; fi) \
327            | awk '{printf "%s\r\n", $$$$0}' >README.$(1).txt
328 endef
329
330 define HOWTO_template
331 HOWTO-$(1).$(2).txt : $(top_srcdir)/doc/HOWTO-$(1).$(2).txt
332         sed -e '/^;.*/d' \
333         -e 's,!VERSION!,$(VERSION),g' \
334         -e 's,!BUILD_ISODATE!,$(BUILD_ISODATE),g' \
335            < $(top_srcdir)/doc/HOWTO-$(1).$(2).txt \
336         | awk '{printf "%s\r\n", $$$$0}' > HOWTO-$(1).$(2).txt
337 endef
338
339 # Insert the template for each source package.
340 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
341
342 # Insert the template for each make only source package.
343 $(foreach mpkg, $(gpg4win_mpkgs), $(eval $(call MPKG_template,$(mpkg))))
344
345 # Insert the template for each binary package.
346 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
347
348 # Insert the template for each internal package.
349 $(foreach ipkg, $(gpg4win_ipkgs), $(eval $(call IPKG_template,$(ipkg))))
350
351 # Insert the template for the README and HOWTO files.
352 $(foreach rll, $(gpg4win_readme_ll), $(eval $(call README_template,$(rll))))
353
354 $(foreach rll, $(gpg4win_howto_smime_ll), \
355                $(eval $(call HOWTO_template,SMIME,$(rll))))
356
357 stamps/stamp-final: stamps/stamp-directories
358 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
359         touch stamps/stamp-final
360
361 $(bdir)/versioninfo.txt: stamps/stamp-final
362         touch $(bdir)/versioninfo.txt
363
364
365 all-gpg4win: stamps/stamp-final
366
367 # Just to check if we catched all stamps.
368 clean-stamps:
369         $(RM) -fR $(stamps)
370
371 clean-gpg4win:
372         $(RM) -fR playground stamps
373
374 .PHONY : all-gpg4win clean-stamps clean-gpg4win
375
376 # @emacs_local_vars_begin@
377 # @emacs_local_vars_read_only@
378 # @emacs_local_vars_end@