... fixed the symptom and not the cause.
[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           *.tar.gz | *.tgz)             \
84             $(TAR) xzf "$(1)" ;;        \
85           *.tar.bz2 | *.tbz2 | *.tbz)   \
86             $(TAR) xjf "$(1)" ;;        \
87           *.zip)                        \
88             $(UNZIP) -o "$(1)" ;;               \
89         esac
90 endef
91
92 # Support macro.  Strip all exe files below $(1).
93 define STRIP_macro
94         if test -z '$(DEBUG)'; then                     \
95           (cd $(1);                                     \
96            for f in `find . -name \*.exe -o -name \*.dll`; do           \
97            echo Calling $(STRIP) "$$$${pkg_version}/$$$${f}"; \
98            $(STRIP) "$$$${f}"; done);                   \
99         fi
100 endef
101
102
103 # Template for source packages.
104
105 define SPKG_template
106
107 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
108         (cd $(bdir);                                    \
109          $(call SETVARS,$(1));                          \
110          $(call VERSIONINFO_macro,$$$${pkg});           \
111          $(call DEFLATE_macro,$$$${pkg}))
112         touch stamps/stamp-$(1)-00-unpack
113
114 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
115         (shopt -s nullglob;                             \
116          $(call SETVARS,$(1));                          \
117          for pfile in "$$$${pkgpdir}"/*.patch ; do      \
118            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
119          done)
120         touch stamps/stamp-$(1)-01-patch
121
122 stamps/stamp-$(1)-02-configure: stamps/stamp-$(1)-01-patch
123         ($(call SETVARS,$(1));                          \
124          mkdir "$$$${pkgbdir}";                         \
125           cd "$$$${pkgbdir}";                           \
126          "$$$${pkgsdir}/configure"                      \
127                 --prefix="$$$${pkgidir}"                \
128                 --host=$(host_cpu)-$(host_os)           \
129                 --build=$(build_cpu)-$(build_os)        \
130                 $$$${pkgcfg} CFLAGS=-mms-bitfields)
131         touch stamps/stamp-$(1)-02-configure
132
133 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-02-configure
134         ($(call SETVARS,$(1));                          \
135           cd "$$$${pkgbdir}";                           \
136           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
137         touch stamps/stamp-$(1)-03-make
138
139 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
140         ($(call SETVARS,$(1));                          \
141           cd "$$$${pkgbdir}";                           \
142           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
143           $(call STRIP_macro,"$$$${pkgidir}"))
144         touch stamps/stamp-$(1)-04-install
145
146 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
147         ($(call SETVARS,$(1));                          \
148          cd $(ipdir);                                   \
149          $(STOW) "$$$${pkg_version}")
150         touch stamps/stamp-$(1)-05-stow
151
152 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
153         touch stamps/stamp-final-$(1)
154 endef
155
156
157 # Template for source packages using only make and no build
158 # directory.
159
160 define MPKG_template
161
162 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
163         (cd $(bdir);                                    \
164          $(call SETVARS,$(1));                          \
165          $(call VERSIONINFO_macro,$$$${pkg});           \
166          $(call DEFLATE_macro,$$$${pkg}))
167         touch stamps/stamp-$(1)-00-unpack
168
169 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
170         (shopt -s nullglob;                             \
171          $(call SETVARS,$(1));                          \
172          for pfile in "$$$${pkgpdir}"/*.patch ; do      \
173            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
174          done)
175         touch stamps/stamp-$(1)-01-patch
176
177 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-01-patch
178         ($(call SETVARS,$(1));                          \
179           cd "$$$${pkgsdir}";                           \
180           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
181         touch stamps/stamp-$(1)-03-make
182
183 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
184         ($(call SETVARS,$(1));                          \
185           cd "$$$${pkgsdir}";                           \
186           $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
187           $(call STRIP_macro,"$$$${pkgidir}"))
188         touch stamps/stamp-$(1)-04-install
189
190 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
191         ($(call SETVARS,$(1));                          \
192          cd $(ipdir);                                   \
193          $(STOW) "$$$${pkg_version}")
194         touch stamps/stamp-$(1)-05-stow
195
196 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
197         touch stamps/stamp-final-$(1)
198 endef
199
200
201
202 # Template for binary packages.
203
204 define BPKG_template
205
206 stamps/stamp-$(1)-00-install: stamps/stamp-directories 
207         ($(call SETVARS,$(1));                          \
208          $(MKDIR) "$$$${pkgidir}";                      \
209          cd $$$${pkgidir};                              \
210          $(call VERSIONINFO_macro,$$$${pkg});           \
211          $(call DEFLATE_macro,$$$${pkg}))
212         touch stamps/stamp-$(1)-00-install
213
214 # Note that post_install must come last because it may be empty and
215 # "; ;" is a syntax error.
216 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
217         ($(call SETVARS,$(1));                          \
218          $(MKDIR) "$$$${pkgidir_dev}";                  \
219          (cd $$$${pkgidir_dev};                         \
220           $(call VERSIONINFO_macro,$$$${pkg_dev});      \
221           $(call DEFLATE_macro,$$$${pkg_dev}));         \
222          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
223         touch stamps/stamp-$(1)-01-install-dev
224
225 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
226         ($(call SETVARS,$(1));                          \
227          cd $(ipdir);                                   \
228          $(STOW) "$$$${pkg_version}")
229         touch stamps/stamp-$(1)-02-stow
230
231 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
232         ($(call SETVARS,$(1));                          \
233          cd $(ipdir);                                   \
234          $(STOW) "$$$${pkg_version_dev}")
235         touch stamps/stamp-$(1)-03-stow-dev
236
237 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
238         touch stamps/stamp-final-$(1)
239 endef
240
241
242 # Insert the template for each source package.
243 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
244
245 # Insert the template for each make only source package.
246 $(foreach mpkg, $(gpg4win_mpkgs), $(eval $(call MPKG_template,$(mpkg))))
247
248 # Insert the template for each binary package.
249 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
250
251 stamps/stamp-final: stamps/stamp-directories
252 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
253         touch stamps/stamp-final
254
255 all-gpg4win: stamps/stamp-final
256
257 # Just to check if we catched all stamps.
258 clean-stamps:
259         $(RM) -fR $(stamps)
260
261 clean-gpg4win:
262         $(RM) -fR playground stamps
263
264 .PHONY : all-gpg4win clean-stamps clean-gpg4win