2005-11-04 Marcus Brinkmann <marcus@g10code.de>
[gpg4win.git] / src / gpg4win.mk.in
1 # gpg4win.m4 - Installer for GnuPG 4 Windows 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 pdir := $(shell pwd)/${top_srcdir}/patches
30
31
32 # The playground area is our scratch area, where we unpack, build and
33 # install the packages.
34 stamps/stamp-directories:
35         $(MKDIR) stamps
36         $(MKDIR) playground
37         $(MKDIR) $(bdir)
38         $(MKDIR) $(idir)
39         $(MKDIR) $(ipdir)
40         touch stamps/stamp-directories
41
42
43 # Frob the name $1 by converting all '-' and '+' characters to '_'.
44 define FROB_macro
45 $(subst +,_,$(subst -,_,$(1)))
46 endef
47
48 # Get the variable $(1) (which may contain '-' and '+' characters).
49 define GETVAR
50 $($(call FROB_macro,$(1)))
51 endef
52
53 # Set a couple of common variables.
54 define SETVARS
55         pkg="$(call GETVAR,gpg4win_pkg_$(1))";                          \
56         pkg_version="$(1)-$(call GETVAR,gpg4win_pkg_$(1)_version)";     \
57         pkgsdir="$(bdir)/$$$${pkg_version}";                            \
58         pkgbdir="$(bdir)/$$$${pkg_version}-build";                      \
59         pkgpdir="$(pdir)/$$$${pkg_version}";                            \
60         pkgidir="$(ipdir)/$$$${pkg_version}";                           \
61         pkg_dev="$(call GETVAR,gpg4win_pkg_$(1)_dev)";                  \
62         pkg_version_dev="$(1)-dev-$(call GETVAR,gpg4win_pkg_$(1)_version)"; \
63         pkgidir_dev="$(ipdir)/$$$${pkg_version_dev}";                   \
64         pkgcfg="$(call GETVAR,gpg4win_pkg_$(1)_configure)";             \
65         export PKG_CONFIG="$(shell pwd)/$(top_srcdir)/src/pkg-config";  \
66         export PKG_CONFIG_PATH="${idir}/lib/pkgconfig";                 \
67         export SYSROOT="${idir}"
68 endef
69
70 # Support macro.  Unpack the archive $(1).
71 define DEFLATE_macro
72         case "$(1)" in                  \
73           *.tar.gz | *.tgz)             \
74             $(TAR) xzf "$(1)" ;;        \
75           *.tar.bz2 | *.tbz2 | *.tbz)   \
76             $(TAR) xjf "$(1)" ;;        \
77           *.zip)                        \
78             $(UNZIP) "$(1)" ;;          \
79         esac
80 endef
81
82 # Support macro.  Strip all exe files below $(1).
83 # We can't strip dll files: Neither --strip-unneeded nor --strip-debug
84 # works correctly on this target.
85 define STRIP_macro
86         if test -z '$(DEBUG)'; then                     \
87           (cd $(1);                                     \
88            for f in `find . -name \*.exe`; do           \
89            echo Calling $(STRIP) "$$$${pkg_version}/$$$${f}"; \
90            $(STRIP) "$$$${f}"; done);                   \
91         fi
92 endef
93
94
95 # Template for source packages.
96
97 define SPKG_template
98
99 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
100         (cd $(bdir);                                    \
101          $(call SETVARS,$(1));                          \
102          $(call DEFLATE_macro,$$$${pkg}))
103         touch stamps/stamp-$(1)-00-unpack
104
105 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
106         (shopt -s nullglob;                             \
107          $(call SETVARS,$(1));                          \
108          for pfile in "$$$${pkgpdir}"/*.patch ; do      \
109            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
110          done)
111         touch stamps/stamp-$(1)-01-patch
112
113 stamps/stamp-$(1)-02-configure: stamps/stamp-$(1)-01-patch
114         ($(call SETVARS,$(1));                          \
115          mkdir "$$$${pkgbdir}";                         \
116           cd "$$$${pkgbdir}";                           \
117          "$$$${pkgsdir}/configure"                      \
118                 --prefix="$$$${pkgidir}"                \
119                 --host=$(host_cpu)-$(host_os)           \
120                 --build=$(build_cpu)-$(build_os)        \
121                 $$$${pkgcfg} CFLAGS=-mms-bitfields)
122         touch stamps/stamp-$(1)-02-configure
123
124 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-02-configure
125         ($(call SETVARS,$(1));                          \
126           cd "$$$${pkgbdir}";                           \
127           $(MAKE) $(AM_MAKEFLAGS))
128         touch stamps/stamp-$(1)-03-make
129
130 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
131         ($(call SETVARS,$(1));                          \
132           cd "$$$${pkgbdir}";                           \
133           $(MAKE) $(AM_MAKEFLAGS) install;              \
134           $(call STRIP_macro,"$$$${pkgidir}"))
135         touch stamps/stamp-$(1)-04-install
136
137 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
138         ($(call SETVARS,$(1));                          \
139          cd $(ipdir);                                   \
140          $(STOW) "$$$${pkg_version}")
141         touch stamps/stamp-$(1)-05-stow
142
143 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
144         touch stamps/stamp-final-$(1)
145 endef
146
147
148 # Template for binary packages.
149
150 define BPKG_template
151
152 stamps/stamp-$(1)-00-install: stamps/stamp-directories 
153         ($(call SETVARS,$(1));                          \
154          $(MKDIR) "$$$${pkgidir}";                      \
155          cd $$$${pkgidir};                              \
156          $(call DEFLATE_macro,$$$${pkg});               \
157          $(call STRIP_macro,"$$$${pkgidir}"))
158         touch stamps/stamp-$(1)-00-install
159
160 # Note that post_install must come last because it may be empty and
161 # "; ;" is a syntax error.
162 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
163         ($(call SETVARS,$(1));                          \
164          $(MKDIR) "$$$${pkgidir_dev}";                  \
165          (cd $$$${pkgidir_dev};                         \
166           $(call DEFLATE_macro,$$$${pkg_dev});          \
167           $(call STRIP_macro,"$$$${pkgidir_dev}"));     \
168          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
169         touch stamps/stamp-$(1)-01-install-dev
170
171 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
172         ($(call SETVARS,$(1));                          \
173          cd $(ipdir);                                   \
174          $(STOW) "$$$${pkg_version}")
175         touch stamps/stamp-$(1)-02-stow
176
177 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
178         ($(call SETVARS,$(1));                          \
179          cd $(ipdir);                                   \
180          $(STOW) "$$$${pkg_version_dev}")
181         touch stamps/stamp-$(1)-03-stow-dev
182
183 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
184         touch stamps/stamp-final-$(1)
185 endef
186
187
188 # Insert the template for each source package.
189 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
190
191 # Insert the template for each binary package.
192 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
193
194 stamps/stamp-final: stamps/stamp-directories
195 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
196         touch stamps/stamp-final
197
198 all-gpg4win: stamps/stamp-final
199
200 # Just to check if we catched all stamps.
201 clean-stamps:
202         $(RM) -fR $(stamps)
203
204 clean-gpg4win:
205         $(RM) -fR playground stamps
206
207 .PHONY : all-gpg4win clean-stamps clean-gpg4win