2007-09-25 Marcus Brinkmann <marcus@g10code.de>
[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         pkgidir="$(ipdir)/$$$${pkg_version}";                           \
63         pkg_dev="$(call GETVAR,gpg4win_pkg_$(1)_dev)";                  \
64         pkg_version_dev="$(1)-dev-$(call GETVAR,gpg4win_pkg_$(1)_version)"; \
65         pkgidir_dev="$(ipdir)/$$$${pkg_version_dev}";                   \
66         pkgcfg="$(call GETVAR,gpg4win_pkg_$(1)_configure)";             \
67         pkgmkargs="$(call GETVAR,gpg4win_pkg_$(1)_make_args)";          \
68         pkgmkargs_inst="$(call GETVAR,gpg4win_pkg_$(1)_make_args_inst)";\
69         export PKG_CONFIG="$(tsdir)/src/pkg-config";                    \
70         export PKG_CONFIG_PATH="$(idir)/lib/pkgconfig";                 \
71         export SYSROOT="$(idir)";                                       \
72         export CONFIG_SITE="$(tsdir)/src/config.site"
73 endef
74
75 # Support macro.  Record version number of file $(1).
76 define VERSIONINFO_macro
77          $(SHA1SUM) "$(1)" >> "$(bdir)/versioninfo.txt" 
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
105 # Template for source packages.
106
107 define SPKG_template
108
109 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
110         (cd $(bdir);                                    \
111          $(call SETVARS,$(1));                          \
112          $(call VERSIONINFO_macro,$$$${pkg});           \
113          $(call DEFLATE_macro,$$$${pkg}))
114         touch stamps/stamp-$(1)-00-unpack
115
116 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
117         (shopt -s nullglob;                             \
118          $(call SETVARS,$(1));                          \
119          for pfile in "$$$${pkgpdir}"/*.patch ; do      \
120            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
121          done)
122         touch stamps/stamp-$(1)-01-patch
123
124 stamps/stamp-$(1)-02-configure: stamps/stamp-$(1)-01-patch
125         ($(call SETVARS,$(1));                          \
126          mkdir "$$$${pkgbdir}";                         \
127           cd "$$$${pkgbdir}";                           \
128          eval "$$$${pkgsdir}/configure"                 \
129                 --prefix="$$$${pkgidir}"                \
130                 --host=$(host_cpu)-$(host_os)           \
131                 --build=$(build_cpu)-$(build_os)        \
132                 $$$${pkgcfg} CFLAGS=-mms-bitfields)
133         touch stamps/stamp-$(1)-02-configure
134
135 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-02-configure
136         ($(call SETVARS,$(1));                          \
137           cd "$$$${pkgbdir}";                           \
138           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
139         touch stamps/stamp-$(1)-03-make
140
141 # Note that post_install must come last because it may be empty and
142 # "; ;" is a syntax error.
143 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
144         ($(call SETVARS,$(1));                          \
145           cd "$$$${pkgbdir}";                           \
146           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
147           $(call STRIP_macro,"$$$${pkgidir}"); \
148           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
149         touch stamps/stamp-$(1)-04-install
150
151 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
152         ($(call SETVARS,$(1));                          \
153          cd $(ipdir);                                   \
154          $(STOW) "$$$${pkg_version}")
155         touch stamps/stamp-$(1)-05-stow
156
157 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
158         touch stamps/stamp-final-$(1)
159
160 .PHONY : clean-$(1)
161 clean-$(1):
162         ($(call SETVARS,$(1));                          \
163          (cd $(ipdir) &&                                \
164           ($(STOW) -D "$$$${pkg_version}";              \
165            rm -fR "$$$${pkg_version}"));                \
166          rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}")
167         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
168
169 endef
170
171
172 # Template for source packages using only make and no build
173 # directory.
174
175 define MPKG_template
176
177 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
178         (cd $(bdir);                                    \
179          $(call SETVARS,$(1));                          \
180          $(call VERSIONINFO_macro,$$$${pkg});           \
181          $(call DEFLATE_macro,$$$${pkg}))
182         touch stamps/stamp-$(1)-00-unpack
183
184 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
185         (shopt -s nullglob;                             \
186          $(call SETVARS,$(1));                          \
187          for pfile in "$$$${pkgpdir}"/*.patch ; do      \
188            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
189          done)
190         touch stamps/stamp-$(1)-01-patch
191
192 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-01-patch
193         ($(call SETVARS,$(1));                          \
194           cd "$$$${pkgsdir}";                           \
195           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
196         touch stamps/stamp-$(1)-03-make
197
198 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
199         ($(call SETVARS,$(1));                          \
200           cd "$$$${pkgsdir}";                           \
201           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
202           $(call STRIP_macro,"$$$${pkgidir}"))
203         touch stamps/stamp-$(1)-04-install
204
205 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
206         ($(call SETVARS,$(1));                          \
207          cd $(ipdir);                                   \
208          $(STOW) "$$$${pkg_version}")
209         touch stamps/stamp-$(1)-05-stow
210
211 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
212         touch stamps/stamp-final-$(1)
213
214 .PHONY : clean-$(1)
215 clean-$(1):
216         ($(call SETVARS,$(1));                          \
217          (cd $(ipdir) &&                                \
218           ($(STOW) -D "$$$${pkg_version}";              \
219            rm -fR "$$$${pkg_version}"));                \
220          rm -fR "$$$${pkgsdir}"
221         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
222
223 endef
224
225
226
227 # Template for binary packages.
228
229 define BPKG_template
230
231 stamps/stamp-$(1)-00-install: stamps/stamp-directories 
232         ($(call SETVARS,$(1));                          \
233          $(MKDIR) "$$$${pkgidir}";                      \
234          cd $$$${pkgidir};                              \
235          $(call VERSIONINFO_macro,$$$${pkg});           \
236          $(call DEFLATE_macro,$$$${pkg}))
237         touch stamps/stamp-$(1)-00-install
238
239 # Note that post_install must come last because it may be empty and
240 # "; ;" is a syntax error.
241 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
242         ($(call SETVARS,$(1));                          \
243          $(MKDIR) "$$$${pkgidir_dev}";                  \
244          (cd $$$${pkgidir_dev};                         \
245           $(call VERSIONINFO_macro,$$$${pkg_dev});      \
246           $(call DEFLATE_macro,$$$${pkg_dev}));         \
247          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
248         touch stamps/stamp-$(1)-01-install-dev
249
250 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
251         ($(call SETVARS,$(1));                          \
252          cd $(ipdir);                                   \
253          $(STOW) "$$$${pkg_version}")
254         touch stamps/stamp-$(1)-02-stow
255
256 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
257         ($(call SETVARS,$(1));                          \
258          cd $(ipdir);                                   \
259          $(STOW) "$$$${pkg_version_dev}")
260         touch stamps/stamp-$(1)-03-stow-dev
261
262 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
263         touch stamps/stamp-final-$(1)
264
265 .PHONY : clean-$(1)
266 clean-$(1):
267         ($(call SETVARS,$(1));                          \
268          cd $(ipdir) &&                                 \
269          ($(STOW) -D "$$$${pkg_version}";               \
270           $(STOW) -D "$$$${pkg_version_dev}";           \
271           rm -fR "$$$${pkg_version}" "$$$${pkg_version_dev}"))
272         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
273
274 endef
275
276
277 # Template for source packages.
278
279 define IPKG_template
280
281 stamps/stamp-final-$(1): stamps/stamp-directories 
282         touch stamps/stamp-final-$(1)
283 endef
284
285
286 # Insert the template for each source package.
287 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
288
289 # Insert the template for each make only source package.
290 $(foreach mpkg, $(gpg4win_mpkgs), $(eval $(call MPKG_template,$(mpkg))))
291
292 # Insert the template for each binary package.
293 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
294
295 # Insert the template for each internal package.
296 $(foreach ipkg, $(gpg4win_ipkgs), $(eval $(call IPKG_template,$(ipkg))))
297
298 stamps/stamp-final: stamps/stamp-directories
299 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
300         touch stamps/stamp-final
301
302 all-gpg4win: stamps/stamp-final
303
304 # Just to check if we catched all stamps.
305 clean-stamps:
306         $(RM) -fR $(stamps)
307
308 clean-gpg4win:
309         $(RM) -fR playground stamps
310
311 .PHONY : all-gpg4win clean-stamps clean-gpg4win