2009-02-06 Marc Mutz <marc@kdab.net>
[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) $(GPG4WIN_PARALLEL) $$$${pkgmkargs} || \
141           $(MAKE) $(AM_MAKEFLAGS) $(GPG4WIN_PARALLEL) $$$${pkgmkargs} || \
142           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
143         touch stamps/stamp-$(1)-03-make
144
145 # Note that post_install must come last because it may be empty and
146 # "; ;" is a syntax error.
147 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
148         ($(call SETVARS,$(1));                          \
149           cd "$$$${pkgbdir}";                           \
150           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
151           $(call STRIP_macro,"$$$${pkgidir}"); \
152           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
153         touch stamps/stamp-$(1)-04-install
154
155 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
156         ($(call SETVARS,$(1));                          \
157          cd $(ipdir);                                   \
158          $(STOW) "$$$${pkg_version}")
159         touch stamps/stamp-$(1)-05-stow
160
161 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
162         touch stamps/stamp-final-$(1)
163
164 .PHONY : clean-$(1)
165 clean-$(1):
166         ($(call SETVARS,$(1));                          \
167          (cd $(ipdir) &&                                \
168           ($(STOW) -D "$$$${pkg_version}";              \
169            rm -fR "$$$${pkg_version}"));                \
170          rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}")
171         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
172
173 endef
174
175
176 # Template for source packages using only make and no build
177 # directory.
178
179 define MPKG_template
180
181 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
182         (cd $(bdir);                                    \
183          $(call SETVARS,$(1));                          \
184          $(call VERSIONINFO_macro,$$$${pkg});           \
185          $(call DEFLATE_macro,$$$${pkg}))
186         touch stamps/stamp-$(1)-00-unpack
187
188 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
189         (shopt -s nullglob;                             \
190          $(call SETVARS,$(1));                          \
191          for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do \
192            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
193          done)
194         touch stamps/stamp-$(1)-01-patch
195
196 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-01-patch
197         ($(call SETVARS,$(1));                          \
198           cd "$$$${pkgsdir}";                           \
199           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
200         touch stamps/stamp-$(1)-03-make
201
202 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
203         ($(call SETVARS,$(1));                          \
204           cd "$$$${pkgsdir}";                           \
205           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
206           $(call STRIP_macro,"$$$${pkgidir}"))
207         touch stamps/stamp-$(1)-04-install
208
209 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
210         ($(call SETVARS,$(1));                          \
211          cd $(ipdir);                                   \
212          $(STOW) "$$$${pkg_version}")
213         touch stamps/stamp-$(1)-05-stow
214
215 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
216         touch stamps/stamp-final-$(1)
217
218 .PHONY : clean-$(1)
219 clean-$(1):
220         ($(call SETVARS,$(1));                          \
221          (cd $(ipdir) &&                                \
222           ($(STOW) -D "$$$${pkg_version}";              \
223            rm -fR "$$$${pkg_version}"));                \
224          rm -fR "$$$${pkgsdir}"
225         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
226
227 endef
228
229
230
231 # Template for binary packages.
232
233 define BPKG_template
234
235 stamps/stamp-$(1)-00-install: stamps/stamp-directories 
236         ($(call SETVARS,$(1));                          \
237          $(MKDIR) "$$$${pkgidir}";                      \
238          cd $$$${pkgidir};                              \
239          $(call VERSIONINFO_macro,$$$${pkg});           \
240          $(call DEFLATE_macro,$$$${pkg}))
241         touch stamps/stamp-$(1)-00-install
242
243 # Note that post_install must come last because it may be empty and
244 # "; ;" is a syntax error.
245 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
246         ($(call SETVARS,$(1));                          \
247          $(MKDIR) "$$$${pkgidir_dev}";                  \
248          (cd $$$${pkgidir_dev};                         \
249           $(call VERSIONINFO_macro,$$$${pkg_dev});      \
250           $(call DEFLATE_macro,$$$${pkg_dev}));         \
251          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
252         touch stamps/stamp-$(1)-01-install-dev
253
254 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
255         ($(call SETVARS,$(1));                          \
256          cd $(ipdir);                                   \
257          $(STOW) "$$$${pkg_version}")
258         touch stamps/stamp-$(1)-02-stow
259
260 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
261         ($(call SETVARS,$(1));                          \
262          cd $(ipdir);                                   \
263          $(STOW) "$$$${pkg_version_dev}")
264         touch stamps/stamp-$(1)-03-stow-dev
265
266 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
267         touch stamps/stamp-final-$(1)
268
269 .PHONY : clean-$(1)
270 clean-$(1):
271         ($(call SETVARS,$(1));                          \
272          cd $(ipdir) &&                                 \
273          ($(STOW) -D "$$$${pkg_version}";               \
274           $(STOW) -D "$$$${pkg_version_dev}";           \
275           rm -fR "$$$${pkg_version}" "$$$${pkg_version_dev}"))
276         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
277
278 endef
279
280
281 # Template for source packages.
282
283 define IPKG_template
284
285 stamps/stamp-final-$(1): stamps/stamp-directories 
286         touch stamps/stamp-final-$(1)
287 endef
288
289
290 # Insert the template for each source package.
291 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
292
293 # Insert the template for each make only source package.
294 $(foreach mpkg, $(gpg4win_mpkgs), $(eval $(call MPKG_template,$(mpkg))))
295
296 # Insert the template for each binary package.
297 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
298
299 # Insert the template for each internal package.
300 $(foreach ipkg, $(gpg4win_ipkgs), $(eval $(call IPKG_template,$(ipkg))))
301
302 stamps/stamp-final: stamps/stamp-directories
303 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
304         touch stamps/stamp-final
305
306 all-gpg4win: stamps/stamp-final
307
308 # Just to check if we catched all stamps.
309 clean-stamps:
310         $(RM) -fR $(stamps)
311
312 clean-gpg4win:
313         $(RM) -fR playground stamps
314
315 .PHONY : all-gpg4win clean-stamps clean-gpg4win