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
83 # Template for source packages.
84
85 define SPKG_template
86
87 stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
88         (cd $(bdir);                                    \
89          $(call SETVARS,$(1));                          \
90          $(call DEFLATE_macro,$$$${pkg}))
91         touch stamps/stamp-$(1)-00-unpack
92
93 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
94         (shopt -s nullglob;                             \
95          $(call SETVARS,$(1));                          \
96          for pfile in "$$$${pkgpdir}"/*.patch ; do      \
97            (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
98          done)
99         touch stamps/stamp-$(1)-01-patch
100
101 stamps/stamp-$(1)-02-configure: stamps/stamp-$(1)-01-patch
102         ($(call SETVARS,$(1));                          \
103          mkdir "$$$${pkgbdir}";                         \
104           cd "$$$${pkgbdir}";                           \
105          "$$$${pkgsdir}/configure"                      \
106                 --prefix="$$$${pkgidir}"                \
107                 --host=$(host_cpu)-$(host_os)           \
108                 --build=$(build_cpu)-$(build_os) $$$${pkgcfg})
109         touch stamps/stamp-$(1)-02-configure
110
111 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-02-configure
112         ($(call SETVARS,$(1));                          \
113           cd "$$$${pkgbdir}";                           \
114           $(MAKE) $(AM_MAKEFLAGS))
115         touch stamps/stamp-$(1)-03-make
116
117 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
118         ($(call SETVARS,$(1));                          \
119           cd "$$$${pkgbdir}";                           \
120           $(MAKE) $(AM_MAKEFLAGS) install)
121         touch stamps/stamp-$(1)-04-install
122
123 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
124         ($(call SETVARS,$(1));                          \
125          cd $(ipdir);                                   \
126          $(STOW) "$$$${pkg_version}")
127         touch stamps/stamp-$(1)-05-stow
128
129 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
130         touch stamps/stamp-final-$(1)
131 endef
132
133
134 # Template for binary packages.
135
136 define BPKG_template
137
138 stamps/stamp-$(1)-00-install: stamps/stamp-directories 
139         ($(call SETVARS,$(1));                          \
140          $(MKDIR) "$$$${pkgidir}";                      \
141          cd $$$${pkgidir};                              \
142          $(call DEFLATE_macro,$$$${pkg}))
143         touch stamps/stamp-$(1)-00-install
144
145 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
146         ($(call SETVARS,$(1));                          \
147          $(MKDIR) "$$$${pkgidir_dev}";                  \
148          cd $$$${pkgidir_dev};                          \
149          $(call DEFLATE_macro,$$$${pkg_dev});           \
150          $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
151         touch stamps/stamp-$(1)-01-install-dev
152
153 stamps/stamp-$(1)-02-stow: stamps/stamp-$(1)-01-install-dev
154         ($(call SETVARS,$(1));                          \
155          cd $(ipdir);                                   \
156          $(STOW) "$$$${pkg_version}")
157         touch stamps/stamp-$(1)-02-stow
158
159 stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
160         ($(call SETVARS,$(1));                          \
161          cd $(ipdir);                                   \
162          $(STOW) "$$$${pkg_version_dev}")
163         touch stamps/stamp-$(1)-03-stow-dev
164
165 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
166         touch stamps/stamp-final-$(1)
167 endef
168
169
170 # Insert the template for each source package.
171 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
172
173 # Insert the template for each binary package.
174 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
175
176
177 .PHONY : final
178
179 final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
180
181 all-gpg4win: final
182
183
184 # Just to check if we catched all stamps.
185 clean-stamps:
186         $(RM) -fR $(stamps)
187
188 clean-gpg4win:
189         $(RM) -fR playground stamps