2005-10-20 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 dll and exe files below $(1).
83 define STRIP_macro
84         if test -z '$(DEBUG)'; then                     \
85           (cd $(1);                                     \
86            for f in `find . -name \*.dll                \
87                   -o -name \*.exe`; do                  \
88            echo Calling $(STRIP) "$$$${pkg_version}/$$$${f}"; \
89            $(STRIP) "$$$${f}"; done);                   \
90         fi
91 endef
92
93
94 # Template for source packages.
95
96 define SPKG_template
97
98 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
99         (cd $(bdir);                                    \
100          $(call SETVARS,$(1));                          \
101          $(call DEFLATE_macro,$$$${pkg}))
102         touch stamps/stamp-$(1)-00-unpack
103
104 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
105         (shopt -s nullglob;                             \
106          $(call SETVARS,$(1));                          \
107          for pfile in "$$$${pkgpdir}"/*.patch ; do      \
108            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
109          done)
110         touch stamps/stamp-$(1)-01-patch
111
112 stamps/stamp-$(1)-02-configure: stamps/stamp-$(1)-01-patch
113         ($(call SETVARS,$(1));                          \
114          mkdir "$$$${pkgbdir}";                         \
115           cd "$$$${pkgbdir}";                           \
116          "$$$${pkgsdir}/configure"                      \
117                 --prefix="$$$${pkgidir}"                \
118                 --host=$(host_cpu)-$(host_os)           \
119                 --build=$(build_cpu)-$(build_os)        \
120                 $$$${pkgcfg} CFLAGS=-mms-bitfields)
121         touch stamps/stamp-$(1)-02-configure
122
123 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-02-configure
124         ($(call SETVARS,$(1));                          \
125           cd "$$$${pkgbdir}";                           \
126           $(MAKE) $(AM_MAKEFLAGS))
127         touch stamps/stamp-$(1)-03-make
128
129 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
130         ($(call SETVARS,$(1));                          \
131           cd "$$$${pkgbdir}";                           \
132           $(MAKE) $(AM_MAKEFLAGS) install;              \
133           $(call STRIP_macro,"$$$${pkgidir}"))
134         touch stamps/stamp-$(1)-04-install
135
136 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
137         ($(call SETVARS,$(1));                          \
138          cd $(ipdir);                                   \
139          $(STOW) "$$$${pkg_version}")
140         touch stamps/stamp-$(1)-05-stow
141
142 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
143         touch stamps/stamp-final-$(1)
144 endef
145
146
147 # Template for binary packages.
148
149 define BPKG_template
150
151 stamps/stamp-$(1)-00-install: stamps/stamp-directories 
152         ($(call SETVARS,$(1));                          \
153          $(MKDIR) "$$$${pkgidir}";                      \
154          cd $$$${pkgidir};                              \
155          $(call DEFLATE_macro,$$$${pkg});               \
156          $(call STRIP_macro,"$$$${pkgidir}"))
157         touch stamps/stamp-$(1)-00-install
158
159 # Note that post_install must come last because it may be empty and
160 # "; ;" is a syntax error.
161 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
162         ($(call SETVARS,$(1));                          \
163          $(MKDIR) "$$$${pkgidir_dev}";                  \
164          cd $$$${pkgidir_dev};                          \
165          $(call DEFLATE_macro,$$$${pkg_dev});           \
166          $(call STRIP_macro,"$$$${pkgidir_dev}");       \
167          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
168         touch stamps/stamp-$(1)-01-install-dev
169
170 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
171         ($(call SETVARS,$(1));                          \
172          cd $(ipdir);                                   \
173          $(STOW) "$$$${pkg_version}")
174         touch stamps/stamp-$(1)-02-stow
175
176 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
177         ($(call SETVARS,$(1));                          \
178          cd $(ipdir);                                   \
179          $(STOW) "$$$${pkg_version_dev}")
180         touch stamps/stamp-$(1)-03-stow-dev
181
182 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
183         touch stamps/stamp-final-$(1)
184 endef
185
186
187 # Insert the template for each source package.
188 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
189
190 # Insert the template for each binary package.
191 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
192
193 stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
194         touch stamps/stamp-final
195
196 all-gpg4win: stamps/stamp-final
197
198 # Just to check if we catched all stamps.
199 clean-stamps:
200         $(RM) -fR $(stamps)
201
202 clean-gpg4win:
203         $(RM) -fR playground stamps
204
205 .PHONY : all-gpg4win clean-stamps clean-gpg4win