gtk+: Build from source.
[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         pkgextracflags="$(call GETVAR,gpg4win_pkg_$(1)_extracflags)";   \
71         pkgmkargs="$(call GETVAR,gpg4win_pkg_$(1)_make_args)";          \
72         pkgmkargs_inst="$(call GETVAR,gpg4win_pkg_$(1)_make_args_inst)";\
73         export PKG_CONFIG="$(tsdir)/src/pkg-config";                    \
74         export PKG_CONFIG_PATH="$(idir)/lib/pkgconfig";                 \
75         export PKG_CONFIG_LIBDIR="";                                    \
76         export PATH="$(idir)/bin:$${PATH}";                             \
77         export SYSROOT="$(idir)";                                       \
78         export CONFIG_SITE="$(tsdir)/src/config.site"
79 endef
80
81 # Support macro.  Unpack the archive $(1).
82 define DEFLATE_macro
83         case "$(1)" in                  \
84           */gnupg2-2.*.tar.bz2)          \
85             $(TAR) -xj --transform='s,^gnupg-,gnupg2-,' -f "$(1)" ;; \
86           *.tar.gz | *.tgz)             \
87             $(TAR) xzf "$(1)" ;;        \
88           *.tar.bz2 | *.tbz2 | *.tbz)   \
89             $(TAR) xjf "$(1)" ;;        \
90           *.tar.xz )                    \
91             $(TAR) xJf "$(1)" ;;        \
92           *.zip)                        \
93             $(UNZIP) -o "$(1)" ;;               \
94         esac
95 endef
96
97 # Support macro.  Strip all exe files below $(1).
98 define STRIP_macro
99         if test -z '$(DEBUG)'; then                     \
100           (cd $(1);                                     \
101            for f in `find . -name \*.exe -o -name \*.dll`; do           \
102            echo Calling $(STRIP) "$$$${pkg_version}/$$$${f}"; \
103            $(STRIP) "$$$${f}"; done);                   \
104         fi
105 endef
106
107 define GETDEPS
108   $(addprefix stamps/stamp-final-, $(call GETVAR,gpg4win_pkg_$(1)_deps))
109 endef
110
111
112 # Template for source packages.
113
114 define SPKG_template_
115
116 pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
117
118 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories $(call GETDEPS,$(1))
119         (cd $(bdir);                                    \
120          $(call SETVARS,$(1));                          \
121          $(call DEFLATE_macro,$$$${pkg}))
122         touch stamps/stamp-$(1)-00-unpack
123
124 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
125         (shopt -s nullglob;                             \
126          $(call SETVARS,$(1));                          \
127          for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do  \
128            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
129          done)
130         touch stamps/stamp-$(1)-01-patch
131
132 stamps/stamp-$(1)-02-configure: stamps/stamp-$(1)-01-patch
133         ($(call SETVARS,$(1));                          \
134          mkdir "$$$${pkgbdir}";                         \
135           cd "$$$${pkgbdir}";                           \
136          eval "../$$$${pkg_version}/configure"          \
137                 --prefix="$$$${pkgidir}"                \
138                 --host=$(host_cpu)-$(host_os)           \
139                 --build=$(build_cpu)-$(build_os)        \
140                 $$$${pkgcfg} CFLAGS=\"-mms-bitfields $$$${pkgextracflags}\")
141         touch stamps/stamp-$(1)-02-configure
142
143 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-02-configure
144         ($(call SETVARS,$(1));                          \
145           cd "$$$${pkgbdir}";                           \
146           $(MAKE) $(AM_MAKEFLAGS) $(GPG4WIN_PARALLEL) $$$${pkgmkargs} || \
147           $(MAKE) $(AM_MAKEFLAGS) $(GPG4WIN_PARALLEL) $$$${pkgmkargs} || \
148           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
149         touch stamps/stamp-$(1)-03-make
150
151 # Note that post_install must come last because it may be empty and
152 # "; ;" is a syntax error.
153 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
154         ($(call SETVARS,$(1));                          \
155           cd "$$$${pkgbdir}";                           \
156           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
157           $(call STRIP_macro,"$$$${pkgidir}");          \
158           rm -f "$$$${pkgidir}/share/info/dir";         \
159           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
160         touch stamps/stamp-$(1)-04-install
161
162 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
163         ($(call SETVARS,$(1));                          \
164          cd $(ipdir);                                   \
165          $(STOW) "$$$${pkg_version}")
166         touch stamps/stamp-$(1)-05-stow
167
168 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
169         touch stamps/stamp-final-$(1)
170
171 .PHONY : clean-$(1)
172 clean-$(1):
173         ($(call SETVARS,$(1));                          \
174          (cd $(ipdir) &&                                \
175           ($(STOW) -D "$$$${pkg_version}";              \
176            rm -fR "$$$${pkg_version}"));                \
177          rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}")
178         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
179
180 endef
181
182 define SPKG_template
183 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
184   $(call SPKG_template_,$1))
185 endef
186
187
188 # Template for source packages using only make and no build
189 # directory.
190
191 define MPKG_template_
192
193 pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
194
195 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories $(call GETDEPS,$(1))
196         (cd $(bdir);                                    \
197          $(call SETVARS,$(1));                          \
198          $(call DEFLATE_macro,$$$${pkg}))
199         touch stamps/stamp-$(1)-00-unpack
200
201 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
202         (shopt -s nullglob;                             \
203          $(call SETVARS,$(1));                          \
204          for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do \
205            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
206          done)
207         touch stamps/stamp-$(1)-01-patch
208
209 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-01-patch
210         ($(call SETVARS,$(1));                          \
211           cd "$$$${pkgsdir}";                           \
212           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
213         touch stamps/stamp-$(1)-03-make
214
215 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
216         ($(call SETVARS,$(1));                          \
217           cd "$$$${pkgsdir}";                           \
218           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
219           $(call STRIP_macro,"$$$${pkgidir}"); \
220           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
221         touch stamps/stamp-$(1)-04-install
222
223 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
224         ($(call SETVARS,$(1));                          \
225          cd $(ipdir);                                   \
226          $(STOW) "$$$${pkg_version}")
227         touch stamps/stamp-$(1)-05-stow
228
229 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
230         touch stamps/stamp-final-$(1)
231
232 .PHONY : clean-$(1)
233 clean-$(1):
234         ($(call SETVARS,$(1));                          \
235          (cd $(ipdir) &&                                \
236           ($(STOW) -D "$$$${pkg_version}";              \
237            rm -fR "$$$${pkg_version}"));                \
238          rm -fR "$$$${pkgsdir}")
239         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
240
241 endef
242
243 define MPKG_template
244 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
245   $(call MPKG_template_,$1))
246 endef
247
248
249
250 # Template for binary packages.
251
252 define BPKG_template_
253
254 pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
255 pkg_files += $(call GETVAR,gpg4win_pkg_$(1)_dev)
256
257 stamps/stamp-$(1)-00-install: stamps/stamp-directories $(call GETDEPS,$(1))
258         ($(call SETVARS,$(1));                          \
259          $(MKDIR) "$$$${pkgidir}";                      \
260          cd $$$${pkgidir};                              \
261          $(call DEFLATE_macro,$$$${pkg}))
262         touch stamps/stamp-$(1)-00-install
263
264 # Note that post_install must come last because it may be empty and
265 # "; ;" is a syntax error.
266 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
267         ($(call SETVARS,$(1));                          \
268          $(MKDIR) "$$$${pkgidir_dev}";                  \
269          (cd $$$${pkgidir_dev};                         \
270           $(call DEFLATE_macro,$$$${pkg_dev}));         \
271          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
272         touch stamps/stamp-$(1)-01-install-dev
273
274 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
275         ($(call SETVARS,$(1));                          \
276          cd $(ipdir);                                   \
277          $(STOW) "$$$${pkg_version}")
278         touch stamps/stamp-$(1)-02-stow
279
280 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
281         ($(call SETVARS,$(1));                          \
282          cd $(ipdir);                                   \
283          $(STOW) "$$$${pkg_version_dev}")
284         touch stamps/stamp-$(1)-03-stow-dev
285
286 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
287         touch stamps/stamp-final-$(1)
288
289 .PHONY : clean-$(1)
290 clean-$(1):
291         ($(call SETVARS,$(1));                          \
292          cd $(ipdir) &&                                 \
293          ($(STOW) -D "$$$${pkg_version}";               \
294           $(STOW) -D "$$$${pkg_version_dev}";           \
295           rm -fR "$$$${pkg_version}" "$$$${pkg_version_dev}"))
296         rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
297
298 endef
299
300 define BPKG_template
301 $(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
302   $(call BPKG_template_,$1))
303 endef
304
305
306 # Template for internal packages.
307
308 define IPKG_template
309
310 stamps/stamp-final-$(1): stamps/stamp-directories $(call GETDEPS,$(1))
311         touch stamps/stamp-final-$(1)
312 endef
313
314 # Template for README files
315 # (The final awk command converts the file endings).
316
317 define README_template
318 README.$(1).txt : versioninfo.txt NEWS.tmp $(top_srcdir)/doc/README.$(1).txt \
319                   $(top_srcdir)/doc/beta-warning.txt
320         sed -e '/^;.*/d;/!VERSIONINFO!/{r versioninfo.txt' -e 'd;}' \
321         -e '/!NEWSFILE!/{r NEWS.tmp' -e 'd;}' \
322         -e '/!NEWSFILE!/{r NEWS.tmp' -e 'd;}' \
323         -e '/!PKG-COPYRIGHT!/{r $(top_srcdir)/doc/pkg-copyright.txt' -e 'd;}' \
324         -e 's,!VERSION!,$(VERSION),g' \
325         -e 's,!BUILD_ISODATE!,$(BUILD_ISODATE),g' \
326            < $(top_srcdir)/doc/README.$(1).txt \
327            | (if echo "$(VERSION)" | egrep 'svn|rc|beta|git' >/dev/null; then \
328               sed -e '/!BETA-WARNING!/{r $(top_srcdir)/doc/beta-warning.txt' \
329                -e 'd;}'; else sed -e 's,!BETA-WARNING!,,g'; fi) \
330            | awk '{printf "%s\r\n", $$$$0}' >README.$(1).txt
331 endef
332
333 define HOWTO_template
334 HOWTO-$(1).$(2).txt : $(top_srcdir)/doc/HOWTO-$(1).$(2).txt
335         sed -e '/^;.*/d' \
336         -e 's,!VERSION!,$(VERSION),g' \
337         -e 's,!BUILD_ISODATE!,$(BUILD_ISODATE),g' \
338            < $(top_srcdir)/doc/HOWTO-$(1).$(2).txt \
339         | awk '{printf "%s\r\n", $$$$0}' > HOWTO-$(1).$(2).txt
340 endef
341
342 # Insert the template for each source package.
343 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
344
345 # Insert the template for each make only source package.
346 $(foreach mpkg, $(gpg4win_mpkgs), $(eval $(call MPKG_template,$(mpkg))))
347
348 # Insert the template for each binary package.
349 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
350
351 # Insert the template for each internal package.
352 $(foreach ipkg, $(gpg4win_ipkgs), $(eval $(call IPKG_template,$(ipkg))))
353
354 # Insert the template for the README and HOWTO files.
355 $(foreach rll, $(gpg4win_readme_ll), $(eval $(call README_template,$(rll))))
356
357 $(foreach rll, $(gpg4win_howto_smime_ll), \
358                $(eval $(call HOWTO_template,SMIME,$(rll))))
359
360 stamps/stamp-final: stamps/stamp-directories
361 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
362         touch stamps/stamp-final
363
364 $(bdir)/versioninfo.txt: stamps/stamp-final
365         touch $(bdir)/versioninfo.txt
366
367
368 all-gpg4win: stamps/stamp-final
369
370 # Just to check if we catched all stamps.
371 clean-stamps:
372         $(RM) -fR $(stamps)
373
374 clean-gpg4win:
375         $(RM) -fR playground stamps
376
377 .PHONY : all-gpg4win clean-stamps clean-gpg4win
378
379 # @emacs_local_vars_begin@
380 # @emacs_local_vars_read_only@
381 # @emacs_local_vars_end@