Rename scripts/ to build-aux/
[gnupg.git] / build-aux / speedo.mk
1 # speedo.mk - Speedo rebuilds speedily.
2 # Copyright (C) 2008, 2014 g10 Code GmbH
3 #
4 # speedo is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # speedo is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, see <http://www.gnu.org/licenses/>.
16
17 # speedo builds gnupg-related packages from GIT and installs them in a
18 # user directory, thereby providing a non-obstrusive test environment.
19 # speedo does only work with GNU make.  The build system is similar to
20 # that of gpg4win.  The following commands are supported:
21 #
22 #   make -f speedo.mk all
23 # or
24 #   make -f speedo.mk
25 #
26 # Builds all packages and installs them under play/inst.  At the end,
27 # speedo prints commands that can be executed in the local shell to
28 # make use of the installed packages.
29 #
30 #   make -f speedo.mk clean
31 # or
32 #   make -f speedo.mk clean-PACKAGE
33 #
34 # Removes all packages or the package PACKAGE from the installation
35 # and build tree.  A subsequent make will rebuild these (and only
36 # these) packages.
37 #
38 #   make -f speedo.mk report
39 # or
40 #   make -f speedo.mk report-PACKAGE
41 #
42 # Lists packages and versions.
43 #
44
45
46
47 # --------
48
49 # The packages that should be built.  The order is also the build order.
50 speedo_spkgs = libgpg-error npth libgcrypt libassuan libksba gnupg gpgme gpa
51
52 # version numbers of the released packages
53 # Fixme: Take the version numbers from gnupg-doc/web/swdb.mac
54 libgpg_error_ver = 1.12
55 npth_ver = 0.91
56 libgcrypt_ver = 1.6.0
57 libassuan_ver = 2.1.1
58 libksba_ver = 1.3.0
59 gnupg_ver = 2.0.22
60 gpgme_ver = 1.5.0
61 gpa_ver = 0.9.5
62
63 # The GIT repository.  Using a local repo is much faster.
64 #gitrep = git://git.gnupg.org
65 gitrep = ${HOME}/s
66
67
68 # For each package, the following variables can be defined:
69 #
70 # speedo_pkg_PACKAGE_git: The GIT repository that should be built.
71 # speedo_pkg_PACKAGE_gitref: The GIT revision to checkout
72 #
73 # speedo_pkg_PACKAGE_tar: URL to the tar file that should be built.
74 #
75 # Exactly one of the above variables is required.  Note that this
76 # version of speedo does not cache repositories or tar files, and does
77 # not test the integrity of the downloaded software.  If you care
78 # about this, you can also specify filenames to locally verified files.
79 # Filenames are differentiated from URLs by starting with a slash '/'.
80 #
81 # speedo_pkg_PACKAGE_configure: Extra arguments to configure.
82 #
83 # speedo_pkg_PACKAGE_make_args: Extra arguments to make.
84 #
85 # speedo_pkg_PACKAGE_make_args_inst: Extra arguments to make install.
86 #
87 # Note that you can override the defaults in this file in a local file
88 # "config.mk"
89
90 # Set this to "git" or "release".
91 WHAT=release
92
93 # Set target to "native" or "w32"
94 TARGETOS=native
95
96 #  Number of parallel make jobs
97 MAKE_J=3
98
99 ifeq ($(WHAT),git)
100   speedo_pkg_libgpg_error_git = $(gitrep)/libgpg-error
101   speedo_pkg_libgpg_error_gitref = master
102   speedo_pkg_npth_git = $(gitrep)/npth
103   speedo_pkg_npth_gitref = master
104   speedo_pkg_libassuan_git = $(gitrep)/libassuan
105   speedo_pkg_libassuan_gitref = master
106   speedo_pkg_libgcrypt_git = $(gitrep)/libgcrypt
107   speedo_pkg_libgcrypt_gitref = master
108   speedo_pkg_libksba_git = $(gitrep)/libksba
109   speedo_pkg_libksba_gitref = master
110   speedo_pkg_gnupg_git = $(gitrep)/gnupg
111   speedo_pkg_gnupg_gitref = master
112   speedo_pkg_gpgme_git = $(gitrep)/gpgme
113   speedo_pkg_gpgme_gitref = master
114   speedo_pkg_gpa_git = $(gitrep)/gpa
115   speedo_pkg_gpa_gitref = master
116 else
117   pkgrep = ftp://ftp.gnupg.org/gcrypt
118   speedo_pkg_libgpg_error_tar = \
119         $(pkgrep)/libgpg-error/libgpg-error-$(libgpg_error_ver).tar.bz2
120   speedo_pkg_npth_tar = \
121         $(pkgrep)/npth/npth-$(npth_ver).tar.bz2
122   speedo_pkg_libassuan_tar = \
123         $(pkgrep)/libassuan/libassuan-$(libassuan_ver).tar.bz2
124   speedo_pkg_libgcrypt_tar = \
125         $(pkgrep)/libgcrypt/libgcrypt-$(libgcrypt_ver).tar.bz2
126   speedo_pkg_libksba_tar = \
127         $(pkgrep)/libksba/libksba-$(libksba_ver).tar.bz2
128   speedo_pkg_gnupg_tar = \
129         $(pkgrep)/gnupg/gnupg-$(gnupg_ver).tar.bz2
130   speedo_pkg_gpgme_tar = \
131         $(pkgrep)/gpgme/gpgme-$(gpgme_ver).tar.bz2
132   speedo_pkg_gpa_tar = \
133         $(pkgrep)/gpa/gpa-$(gpa_ver).tar.bz2
134 endif
135
136 speedo_pkg_pinentry_configure = --disable-pinentry-qt4
137
138 speedo_pkg_libgcrypt_configure = --disable-static
139
140 speedo_pkg_libksba_configure = --disable-static
141
142
143 # ---------
144
145 all: all-speedo
146         @echo export PATH=\"$(idir)/bin\":\$$PATH
147         @echo export LD_LIBRARY_PATH=\"$(idir)/lib\":\$$LD_LIBRARY_PATH
148         @echo hash -r
149
150 report: report-speedo
151
152 clean: clean-speedo
153
154
155 # Fixme: The dist target does not work anymore.
156 STRIP = i686-w64-mingw32-strip
157
158 dist: all
159         set -e; date=$$(date -u +%Y%m%d); pkgname=gpg-w32-dev-$$date; \
160         rm -rf $$pkgname $${pkgname}.zip || true; \
161         cp -rL playground/install $${pkgname}; \
162         rm -r $${pkgname}/share/info || true; \
163         mkdir -p $${pkgname}/share/doc/gpg-w32-dev ;\
164         echo "Included versions:" > $${pkgname}/README.txt ; \
165         echo ""                   >> $${pkgname}/README.txt ; \
166         $(MAKE) --no-print-directory report \
167               | awk '{print $$2}' >> $${pkgname}/README.txt ; \
168         cp GNUmakefile speedo.mk $${pkgname}/README.txt \
169                   $${pkgname}/share/doc/gpg-w32-dev/ ; \
170         $(STRIP) $${pkgname}/bin/*.dll ; \
171         zip -r9 $${pkgname}.zip $${pkgname} >/dev/null ; \
172         rm -rf $$pkgname; \
173         echo "$$pkgname.zip ready for distribution" >&2
174
175
176 -include config.mk
177
178 #
179 #  The generic speedo code
180 #
181
182 MKDIR=mkdir
183
184
185 # These paths must be absolute, as we switch directories pretty often.
186 root := $(shell pwd)/play
187 stampdir := $(root)/stamps
188 sdir := $(root)/src
189 bdir := $(root)/build
190 idir := $(root)/inst
191
192 speedo_build_list = $(speedo_spkgs)
193
194 ifeq ($(TARGETOS),w32)
195   speedo_autogen_buildopt="--build-w32"
196 else
197   speedo_autogen_buildopt=
198 endif
199
200 ifeq ($(MAKE_J),)
201   speedo_makeopt=
202 else
203   speedo_makeopt=-j$(MAKE_J)
204 endif
205
206
207 # The playground area is our scratch area, where we unpack, build and
208 # install the packages.
209 $(stampdir)/stamp-directories:
210         $(MKDIR) $(root)
211         $(MKDIR) $(stampdir)
212         $(MKDIR) $(sdir)
213         $(MKDIR) $(bdir)
214         $(MKDIR) $(idir)
215         touch $(stampdir)/stamp-directories
216
217 # Frob the name $1 by converting all '-' and '+' characters to '_'.
218 define FROB_macro
219 $(subst +,_,$(subst -,_,$(1)))
220 endef
221
222 # Get the variable $(1) (which may contain '-' and '+' characters).
223 define GETVAR
224 $($(call FROB_macro,$(1)))
225 endef
226
227 # Set a couple of common variables.
228 define SETVARS
229         pkg="$(1)";                                                     \
230         git="$(call GETVAR,speedo_pkg_$(1)_git)";                       \
231         gitref="$(call GETVAR,speedo_pkg_$(1)_gitref)";                 \
232         tar="$(call GETVAR,speedo_pkg_$(1)_tar)";                       \
233         pkgsdir="$(sdir)/$(1)";                                         \
234         pkgbdir="$(bdir)/$(1)";                                         \
235         pkgcfg="$(call GETVAR,speedo_pkg_$(1)_configure)";              \
236         pkgmkargs="$(call GETVAR,speedo_pkg_$(1)_make_args)";           \
237         pkgmkargs_inst="$(call GETVAR,speedo_pkg_$(1)_make_args_inst)"; \
238         export PATH="$(idir)/bin:$${PATH}";                             \
239         export LD_LIBRARY_PATH="$(idir)/lib:$${LD_LIBRARY_PATH}"
240 endef
241
242
243 # Template for source packages.
244
245 define SPKG_template
246
247 $(stampdir)/stamp-$(1)-00-unpack: $(stampdir)/stamp-directories
248         @echo "speedo: /*"
249         @echo "speedo:  *   $(1)"
250         @echo "speedo:  */"
251         @(cd $(sdir);                                   \
252          $(call SETVARS,$(1));                          \
253          if [ -n "$$$${git}" ]; then                    \
254            echo "speedo: unpacking $(1) from $$$${git}:$$$${gitref}"; \
255            git clone -q -b "$$$${gitref}" "$$$${git}" "$$$${pkg}"; \
256            cd "$$$${pkg}" &&                            \
257            AUTOGEN_SH_SILENT=1 ./autogen.sh;            \
258          elif [ -n "$$$${tar}" ]; then                  \
259            echo "speedo: unpacking $(1) from $$$${tar}"; \
260            case "$$$${tar}" in                          \
261              *.gz) opt=z ;;                             \
262              *.bz2) opt=j ;;                            \
263              *) opt= ;;                                 \
264            esac;                                        \
265            case "$$$${tar}" in                          \
266              /*) cmd=cat ;;                             \
267              *) cmd="wget -q -O -" ;;                   \
268            esac;                                        \
269            $$$${cmd} "$$$${tar}" | tar x$$$${opt}f - ;  \
270            base=`echo "$$$${tar}" | sed -e 's,^.*/,,'   \
271                  | sed -e 's,\.tar.*$$$$,,'`;           \
272            mv $$$${base} $(1);                          \
273          else                                           \
274            echo "speedo: unpacking $(1) from UNKNOWN";  \
275          fi)
276         @touch $(stampdir)/stamp-$(1)-00-unpack
277
278 $(stampdir)/stamp-$(1)-01-configure: $(stampdir)/stamp-$(1)-00-unpack
279         @echo "speedo: configuring $(1)"
280         @($(call SETVARS,$(1));                         \
281          mkdir "$$$${pkgbdir}";                         \
282          cd "$$$${pkgbdir}";                            \
283          if [ -n "$(speedo_autogen_buildopt)" ]; then   \
284             eval AUTOGEN_SH_SILENT=1 w32root="$(idir)"  \
285                  "$$$${pkgsdir}/autogen.sh"             \
286                  $(speedo_autogen_buildopt) --silent   \
287                  $$$${pkgcfg};                         \
288          else                                           \
289             eval "$$$${pkgsdir}/configure"              \
290                  --silent                               \
291                  --enable-maintainer-mode               \
292                  --prefix="$(idir)"                     \
293                  $$$${pkgcfg};                          \
294          fi)
295         @touch $(stampdir)/stamp-$(1)-01-configure
296
297 $(stampdir)/stamp-$(1)-02-make: $(stampdir)/stamp-$(1)-01-configure
298         @echo "speedo: making $(1)"
299         @($(call SETVARS,$(1));                         \
300           cd "$$$${pkgbdir}";                           \
301           $(MAKE) --no-print-directory $(speedo_makeopt) $$$${pkgmkargs} V=0)
302         @touch $(stampdir)/stamp-$(1)-02-make
303
304 # Note that post_install must come last because it may be empty and
305 # "; ;" is a syntax error.
306 $(stampdir)/stamp-$(1)-03-install: $(stampdir)/stamp-$(1)-02-make
307         @echo "speedo: installing $(1)"
308         @($(call SETVARS,$(1));                         \
309           cd "$$$${pkgbdir}";                           \
310           $(MAKE) --no-print-directory $$$${pkgmkargs_inst} install-strip V=0;\
311           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
312         @touch $(stampdir)/stamp-$(1)-03-install
313
314 $(stampdir)/stamp-final-$(1): $(stampdir)/stamp-$(1)-03-install
315         @touch $(stampdir)/stamp-final-$(1)
316
317 .PHONY : clean-$(1)
318 clean-$(1):
319         @echo "speedo: uninstalling $(1)"
320         @($(call SETVARS,$(1));                         \
321          (cd "$$$${pkgbdir}";                           \
322           $(MAKE) --no-print-directory $$$${pkgmkargs_inst} uninstall V=0); \
323          rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}")
324         @rm -f $(stampdir)/stamp-final-$(1) $(stampdir)/stamp-$(1)-*
325
326 .PHONY : report-$(1)
327 report-$(1):
328         @($(call SETVARS,$(1));                         \
329          echo -n $(1):\  ;                              \
330          if [ -n "$$$${git}" ]; then                    \
331            if [ -e "$$$${pkgsdir}/.git" ]; then         \
332              cd "$$$${pkgsdir}" &&                      \
333              git describe ;                             \
334            else                                         \
335              echo missing;                              \
336            fi                                           \
337          elif [ -n "$$$${tar}" ]; then                  \
338            base=`echo "$$$${tar}" | sed -e 's,^.*/,,'   \
339                  | sed -e 's,\.tar.*$$$$,,'`;           \
340            echo $$$${base} ;                            \
341          fi)
342
343 endef
344
345
346 # Insert the template for each source package.
347 $(foreach spkg, $(speedo_spkgs), $(eval $(call SPKG_template,$(spkg))))
348
349 $(stampdir)/stamp-final: $(stampdir)/stamp-directories
350 $(stampdir)/stamp-final: $(addprefix $(stampdir)/stamp-final-,$(speedo_build_list))
351         touch $(stampdir)/stamp-final
352
353 all-speedo: $(stampdir)/stamp-final
354
355 report-speedo: $(addprefix report-,$(speedo_build_list))
356
357 # Just to check if we catched all stamps.
358 clean-stamps:
359         $(RM) -fR $(stampdir)
360
361 clean-speedo:
362         $(RM) -fR play
363
364 .PHONY : all-speedo report-speedo clean-stamps clean-speedo