Automagically add a BETA warning if the version number includes
[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         touch stamps/stamp-$(1)-04-install
218
219 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
220         ($(call SETVARS,$(1));                          \
221          cd $(ipdir);                                   \
222          $(STOW) "$$$${pkg_version}")
223         touch stamps/stamp-$(1)-05-stow
224
225 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
226         touch stamps/stamp-final-$(1)
227
228 .PHONY : clean-$(1)
229 clean-$(1):
230         ($(call SETVARS,$(1));                          \
231          (cd $(ipdir) &&                                \
232           ($(STOW) -D "$$$${pkg_version}";              \
233            rm -fR "$$$${pkg_version}"));                \
234          rm -fR "$$$${pkgsdir}"
235         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
236
237 endef
238
239 define MPKG_template
240 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
241   $(call MPKG_template_,$1))
242 endef
243
244
245
246 # Template for binary packages.
247
248 define BPKG_template_
249
250 pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
251 pkg_files += $(call GETVAR,gpg4win_pkg_$(1)_dev)
252
253 stamps/stamp-$(1)-00-install: stamps/stamp-directories $(call GETDEPS,$(1))
254         ($(call SETVARS,$(1));                          \
255          $(MKDIR) "$$$${pkgidir}";                      \
256          cd $$$${pkgidir};                              \
257          $(call DEFLATE_macro,$$$${pkg}))
258         touch stamps/stamp-$(1)-00-install
259
260 # Note that post_install must come last because it may be empty and
261 # "; ;" is a syntax error.
262 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
263         ($(call SETVARS,$(1));                          \
264          $(MKDIR) "$$$${pkgidir_dev}";                  \
265          (cd $$$${pkgidir_dev};                         \
266           $(call DEFLATE_macro,$$$${pkg_dev}));         \
267          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
268         touch stamps/stamp-$(1)-01-install-dev
269
270 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
271         ($(call SETVARS,$(1));                          \
272          cd $(ipdir);                                   \
273          $(STOW) "$$$${pkg_version}")
274         touch stamps/stamp-$(1)-02-stow
275
276 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
277         ($(call SETVARS,$(1));                          \
278          cd $(ipdir);                                   \
279          $(STOW) "$$$${pkg_version_dev}")
280         touch stamps/stamp-$(1)-03-stow-dev
281
282 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
283         touch stamps/stamp-final-$(1)
284
285 .PHONY : clean-$(1)
286 clean-$(1):
287         ($(call SETVARS,$(1));                          \
288          cd $(ipdir) &&                                 \
289          ($(STOW) -D "$$$${pkg_version}";               \
290           $(STOW) -D "$$$${pkg_version_dev}";           \
291           rm -fR "$$$${pkg_version}" "$$$${pkg_version_dev}"))
292         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
293
294 endef
295
296 define BPKG_template
297 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
298   $(call BPKG_template_,$1))
299 endef
300
301
302 # Template for internal packages.
303
304 define IPKG_template
305
306 stamps/stamp-final-$(1): stamps/stamp-directories $(call GETDEPS,$(1))
307         touch stamps/stamp-final-$(1)
308 endef
309
310 # Template for README files
311
312 define README_template
313 README.$(1).txt : versioninfo.txt NEWS.tmp $(top_srcdir)/doc/README.$(1).txt \
314                   $(top_srcdir)/doc/beta-warning.txt
315         sed -e '/^;.*/d;/!VERSIONINFO!/{r versioninfo.txt' -e 'd;}' \
316         -e '/!NEWSFILE!/{r NEWS.tmp' -e 'd;}' \
317         -e '/!NEWSFILE!/{r NEWS.tmp' -e 'd;}' \
318         -e '/!PKG-COPYRIGHT!/{r $(top_srcdir)/doc/pkg-copyright.txt' -e 'd;}' \
319         -e 's,!VERSION!,$(VERSION),g' \
320            < $(top_srcdir)/doc/README.$(1).txt \
321            | (if echo "$(VERSION)" | egrep 'svn|rc|beta' >/dev/null; then \
322               sed -e '/!BETA-WARNING!/{r $(top_srcdir)/doc/beta-warning.txt' \
323                -e 'd;}'; else sed -e 's,!BETA-WARNING!,,g'; fi) \
324            | awk '{printf "%s\r\n", $$$$0}' >README.$(1).txt
325 endef
326
327 # Insert the template for each source package.
328 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
329
330 # Insert the template for each make only source package.
331 $(foreach mpkg, $(gpg4win_mpkgs), $(eval $(call MPKG_template,$(mpkg))))
332
333 # Insert the template for each binary package.
334 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
335
336 # Insert the template for each internal package.
337 $(foreach ipkg, $(gpg4win_ipkgs), $(eval $(call IPKG_template,$(ipkg))))
338
339 # Insert the template for each README file.
340 $(foreach rll, $(gpg4win_readme_ll), $(eval $(call README_template,$(rll))))
341
342 stamps/stamp-final: stamps/stamp-directories
343 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
344         touch stamps/stamp-final
345
346 $(bdir)/versioninfo.txt: stamps/stamp-final
347         touch $(bdir)/versioninfo.txt
348
349
350 all-gpg4win: stamps/stamp-final
351
352 # Just to check if we catched all stamps.
353 clean-stamps:
354         $(RM) -fR $(stamps)
355
356 clean-gpg4win:
357         $(RM) -fR playground stamps
358
359 .PHONY : all-gpg4win clean-stamps clean-gpg4win