Use gpg2.
[gpg4win.git] / src / gpg4win.mk.in
1 # gpg4win.m4.in - Installer for GnuPG 4 Windows Makefile.   -*- makefile -*-
2 # Copyright (C) 2005 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
33 # The playground area is our scratch area, where we unpack, build and
34 # install the packages.
35 stamps/stamp-directories:
36         $(MKDIR) stamps
37         $(MKDIR) playground
38         $(MKDIR) $(bdir)
39         $(MKDIR) $(idir)
40         $(MKDIR) $(ipdir)
41         touch $(bdir)/versioninfo.txt
42         touch stamps/stamp-directories
43
44
45 # Frob the name $1 by converting all '-' and '+' characters to '_'.
46 define FROB_macro
47 $(subst +,_,$(subst -,_,$(1)))
48 endef
49
50 # Get the variable $(1) (which may contain '-' and '+' characters).
51 define GETVAR
52 $($(call FROB_macro,$(1)))
53 endef
54
55 # Set a couple of common variables.
56 define SETVARS
57         pkg="$(call GETVAR,gpg4win_pkg_$(1))";                          \
58         pkg_version="$(1)-$(call GETVAR,gpg4win_pkg_$(1)_version)";     \
59         pkgsdir="$(bdir)/$$$${pkg_version}";                            \
60         pkgbdir="$(bdir)/$$$${pkg_version}-build";                      \
61         pkgpdir="$(pdir)/$$$${pkg_version}";                            \
62         pkgpbdir="$(pdir)/$(1)";                                        \
63         pkgidir="$(ipdir)/$$$${pkg_version}";                           \
64         pkg_dev="$(call GETVAR,gpg4win_pkg_$(1)_dev)";                  \
65         pkg_version_dev="$(1)-dev-$(call GETVAR,gpg4win_pkg_$(1)_version)"; \
66         pkgidir_dev="$(ipdir)/$$$${pkg_version_dev}";                   \
67         pkgcfg="$(call GETVAR,gpg4win_pkg_$(1)_configure)";             \
68         pkgmkargs="$(call GETVAR,gpg4win_pkg_$(1)_make_args)";          \
69         pkgmkargs_inst="$(call GETVAR,gpg4win_pkg_$(1)_make_args_inst)";\
70         export PKG_CONFIG="$(tsdir)/src/pkg-config";                    \
71         export PKG_CONFIG_PATH="$(idir)/lib/pkgconfig";                 \
72         export PATH="$(idir)/bin:$${PATH}";                             \
73         export SYSROOT="$(idir)";                                       \
74         export CONFIG_SITE="$(tsdir)/src/config.site"
75 endef
76
77 # Support macro.  Record version number of file $(1).
78 define VERSIONINFO_macro
79          $(SHA1SUM) "$(1)" >> "$(bdir)/versioninfo.txt" 
80 endef
81
82 # Support macro.  Unpack the archive $(1).
83 define DEFLATE_macro
84         case "$(1)" in                  \
85           */gnupg2-2.*.tar.bz2)          \
86             $(TAR) -xj --transform='s,^gnupg-,gnupg2-,' -f "$(1)" ;; \
87           *.tar.gz | *.tgz)             \
88             $(TAR) xzf "$(1)" ;;        \
89           *.tar.bz2 | *.tbz2 | *.tbz)   \
90             $(TAR) xjf "$(1)" ;;        \
91           *.zip)                        \
92             $(UNZIP) -o "$(1)" ;;               \
93         esac
94 endef
95
96 # Support macro.  Strip all exe files below $(1).
97 define STRIP_macro
98         if test -z '$(DEBUG)'; then                     \
99           (cd $(1);                                     \
100            for f in `find . -name \*.exe -o -name \*.dll`; do           \
101            echo Calling $(STRIP) "$$$${pkg_version}/$$$${f}"; \
102            $(STRIP) "$$$${f}"; done);                   \
103         fi
104 endef
105
106
107 # Template for source packages.
108
109 define SPKG_template
110
111 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
112         (cd $(bdir);                                    \
113          $(call SETVARS,$(1));                          \
114          $(call VERSIONINFO_macro,$$$${pkg});           \
115          $(call DEFLATE_macro,$$$${pkg}))
116         touch stamps/stamp-$(1)-00-unpack
117
118 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
119         (shopt -s nullglob;                             \
120          $(call SETVARS,$(1));                          \
121          for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do  \
122            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
123          done)
124         touch stamps/stamp-$(1)-01-patch
125
126 stamps/stamp-$(1)-02-configure: stamps/stamp-$(1)-01-patch
127         ($(call SETVARS,$(1));                          \
128          mkdir "$$$${pkgbdir}";                         \
129           cd "$$$${pkgbdir}";                           \
130          eval "../$$$${pkg_version}/configure"          \
131                 --prefix="$$$${pkgidir}"                \
132                 --host=$(host_cpu)-$(host_os)           \
133                 --build=$(build_cpu)-$(build_os)        \
134                 $$$${pkgcfg} CFLAGS=-mms-bitfields)
135         touch stamps/stamp-$(1)-02-configure
136
137 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-02-configure
138         ($(call SETVARS,$(1));                          \
139           cd "$$$${pkgbdir}";                           \
140           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
141         touch stamps/stamp-$(1)-03-make
142
143 # Note that post_install must come last because it may be empty and
144 # "; ;" is a syntax error.
145 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
146         ($(call SETVARS,$(1));                          \
147           cd "$$$${pkgbdir}";                           \
148           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
149           $(call STRIP_macro,"$$$${pkgidir}"); \
150           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
151         touch stamps/stamp-$(1)-04-install
152
153 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
154         ($(call SETVARS,$(1));                          \
155          cd $(ipdir);                                   \
156          $(STOW) "$$$${pkg_version}")
157         touch stamps/stamp-$(1)-05-stow
158
159 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
160         touch stamps/stamp-final-$(1)
161
162 .PHONY : clean-$(1)
163 clean-$(1):
164         ($(call SETVARS,$(1));                          \
165          (cd $(ipdir) &&                                \
166           ($(STOW) -D "$$$${pkg_version}";              \
167            rm -fR "$$$${pkg_version}"));                \
168          rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}")
169         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
170
171 endef
172
173
174 # Template for source packages using only make and no build
175 # directory.
176
177 define MPKG_template
178
179 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
180         (cd $(bdir);                                    \
181          $(call SETVARS,$(1));                          \
182          $(call VERSIONINFO_macro,$$$${pkg});           \
183          $(call DEFLATE_macro,$$$${pkg}))
184         touch stamps/stamp-$(1)-00-unpack
185
186 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
187         (shopt -s nullglob;                             \
188          $(call SETVARS,$(1));                          \
189          for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do \
190            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
191          done)
192         touch stamps/stamp-$(1)-01-patch
193
194 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-01-patch
195         ($(call SETVARS,$(1));                          \
196           cd "$$$${pkgsdir}";                           \
197           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
198         touch stamps/stamp-$(1)-03-make
199
200 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
201         ($(call SETVARS,$(1));                          \
202           cd "$$$${pkgsdir}";                           \
203           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
204           $(call STRIP_macro,"$$$${pkgidir}"))
205         touch stamps/stamp-$(1)-04-install
206
207 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
208         ($(call SETVARS,$(1));                          \
209          cd $(ipdir);                                   \
210          $(STOW) "$$$${pkg_version}")
211         touch stamps/stamp-$(1)-05-stow
212
213 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
214         touch stamps/stamp-final-$(1)
215
216 .PHONY : clean-$(1)
217 clean-$(1):
218         ($(call SETVARS,$(1));                          \
219          (cd $(ipdir) &&                                \
220           ($(STOW) -D "$$$${pkg_version}";              \
221            rm -fR "$$$${pkg_version}"));                \
222          rm -fR "$$$${pkgsdir}"
223         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
224
225 endef
226
227
228
229 # Template for binary packages.
230
231 define BPKG_template
232
233 stamps/stamp-$(1)-00-install: stamps/stamp-directories 
234         ($(call SETVARS,$(1));                          \
235          $(MKDIR) "$$$${pkgidir}";                      \
236          cd $$$${pkgidir};                              \
237          $(call VERSIONINFO_macro,$$$${pkg});           \
238          $(call DEFLATE_macro,$$$${pkg}))
239         touch stamps/stamp-$(1)-00-install
240
241 # Note that post_install must come last because it may be empty and
242 # "; ;" is a syntax error.
243 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
244         ($(call SETVARS,$(1));                          \
245          $(MKDIR) "$$$${pkgidir_dev}";                  \
246          (cd $$$${pkgidir_dev};                         \
247           $(call VERSIONINFO_macro,$$$${pkg_dev});      \
248           $(call DEFLATE_macro,$$$${pkg_dev}));         \
249          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
250         touch stamps/stamp-$(1)-01-install-dev
251
252 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
253         ($(call SETVARS,$(1));                          \
254          cd $(ipdir);                                   \
255          $(STOW) "$$$${pkg_version}")
256         touch stamps/stamp-$(1)-02-stow
257
258 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
259         ($(call SETVARS,$(1));                          \
260          cd $(ipdir);                                   \
261          $(STOW) "$$$${pkg_version_dev}")
262         touch stamps/stamp-$(1)-03-stow-dev
263
264 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
265         touch stamps/stamp-final-$(1)
266
267 .PHONY : clean-$(1)
268 clean-$(1):
269         ($(call SETVARS,$(1));                          \
270          cd $(ipdir) &&                                 \
271          ($(STOW) -D "$$$${pkg_version}";               \
272           $(STOW) -D "$$$${pkg_version_dev}";           \
273           rm -fR "$$$${pkg_version}" "$$$${pkg_version_dev}"))
274         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
275
276 endef
277
278
279 # Template for source packages.
280
281 define IPKG_template
282
283 stamps/stamp-final-$(1): stamps/stamp-directories 
284         touch stamps/stamp-final-$(1)
285 endef
286
287
288 # Insert the template for each source package.
289 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
290
291 # Insert the template for each make only source package.
292 $(foreach mpkg, $(gpg4win_mpkgs), $(eval $(call MPKG_template,$(mpkg))))
293
294 # Insert the template for each binary package.
295 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
296
297 # Insert the template for each internal package.
298 $(foreach ipkg, $(gpg4win_ipkgs), $(eval $(call IPKG_template,$(ipkg))))
299
300 stamps/stamp-final: stamps/stamp-directories
301 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
302         touch stamps/stamp-final
303
304 all-gpg4win: stamps/stamp-final
305
306 # Just to check if we catched all stamps.
307 clean-stamps:
308         $(RM) -fR $(stamps)
309
310 clean-gpg4win:
311         $(RM) -fR playground stamps
312
313 .PHONY : all-gpg4win clean-stamps clean-gpg4win