speedo: Minor improvements.
[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 # Set this to "git" or "release".
47 WHAT=release
48
49 # Set target to "native" or "w32"
50 TARGETOS=native
51
52 #  Number of parallel make jobs
53 MAKE_J=3
54
55 # The packages that should be built.  The order is also the build order.
56 speedo_spkgs = libgpg-error npth libgcrypt libassuan libksba gnupg gpgme gpa
57
58 # Version numbers of the released packages
59 # Fixme: Take the version numbers from gnupg-doc/web/swdb.mac
60 libgpg_error_ver = 1.12
61 npth_ver = 0.91
62 libgcrypt_ver = 1.6.0
63 libassuan_ver = 2.1.1
64 libksba_ver = 1.3.0
65 gnupg_ver = 2.0.22
66 gpgme_ver = 1.5.0
67 gpa_ver = 0.9.5
68
69 # The GIT repository.  Using a local repo is much faster.
70 #gitrep = git://git.gnupg.org
71 gitrep = ${HOME}/s
72
73 # The tarball directory
74 pkgrep = ftp://ftp.gnupg.org/gcrypt
75
76
77 # For each package, the following variables can be defined:
78 #
79 # speedo_pkg_PACKAGE_git: The GIT repository that should be built.
80 # speedo_pkg_PACKAGE_gitref: The GIT revision to checkout
81 #
82 # speedo_pkg_PACKAGE_tar: URL to the tar file that should be built.
83 #
84 # Exactly one of the above variables is required.  Note that this
85 # version of speedo does not cache repositories or tar files, and does
86 # not test the integrity of the downloaded software.  If you care
87 # about this, you can also specify filenames to locally verified files.
88 # Filenames are differentiated from URLs by starting with a slash '/'.
89 #
90 # speedo_pkg_PACKAGE_configure: Extra arguments to configure.
91 #
92 # speedo_pkg_PACKAGE_make_args: Extra arguments to make.
93 #
94 # speedo_pkg_PACKAGE_make_args_inst: Extra arguments to make install.
95 #
96 # Note that you can override the defaults in this file in a local file
97 # "config.mk"
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   speedo_pkg_libgpg_error_tar = \
118         $(pkgrep)/libgpg-error/libgpg-error-$(libgpg_error_ver).tar.bz2
119   speedo_pkg_npth_tar = \
120         $(pkgrep)/npth/npth-$(npth_ver).tar.bz2
121   speedo_pkg_libassuan_tar = \
122         $(pkgrep)/libassuan/libassuan-$(libassuan_ver).tar.bz2
123   speedo_pkg_libgcrypt_tar = \
124         $(pkgrep)/libgcrypt/libgcrypt-$(libgcrypt_ver).tar.bz2
125   speedo_pkg_libksba_tar = \
126         $(pkgrep)/libksba/libksba-$(libksba_ver).tar.bz2
127   speedo_pkg_gnupg_tar = \
128         $(pkgrep)/gnupg/gnupg-$(gnupg_ver).tar.bz2
129   speedo_pkg_gpgme_tar = \
130         $(pkgrep)/gpgme/gpgme-$(gpgme_ver).tar.bz2
131   speedo_pkg_gpa_tar = \
132         $(pkgrep)/gpa/gpa-$(gpa_ver).tar.bz2
133 endif
134
135 speedo_pkg_pinentry_configure = --disable-pinentry-qt4
136
137 speedo_pkg_libgcrypt_configure = --disable-static
138
139 speedo_pkg_libksba_configure = --disable-static
140
141
142 # ---------
143
144 all: all-speedo
145         @echo export PATH=\"$(idir)/bin\":\$$PATH
146         @echo export LD_LIBRARY_PATH=\"$(idir)/lib\":\$$LD_LIBRARY_PATH
147         @echo hash -r
148
149 report: report-speedo
150
151 clean: clean-speedo
152
153
154 # Fixme: The dist target does not work anymore.
155 STRIP = i686-w64-mingw32-strip
156
157 dist: all
158         set -e; date=$$(date -u +%Y%m%d); pkgname=gpg-w32-dev-$$date; \
159         rm -rf $$pkgname $${pkgname}.zip || true; \
160         cp -rL playground/install $${pkgname}; \
161         rm -r $${pkgname}/share/info || true; \
162         mkdir -p $${pkgname}/share/doc/gpg-w32-dev ;\
163         echo "Included versions:" > $${pkgname}/README.txt ; \
164         echo ""                   >> $${pkgname}/README.txt ; \
165         $(MAKE) --no-print-directory report \
166               | awk '{print $$2}' >> $${pkgname}/README.txt ; \
167         cp GNUmakefile speedo.mk $${pkgname}/README.txt \
168                   $${pkgname}/share/doc/gpg-w32-dev/ ; \
169         $(STRIP) $${pkgname}/bin/*.dll ; \
170         zip -r9 $${pkgname}.zip $${pkgname} >/dev/null ; \
171         rm -rf $$pkgname; \
172         echo "$$pkgname.zip ready for distribution" >&2
173
174
175 -include config.mk
176
177 #
178 #  The generic speedo code
179 #
180
181 MKDIR=mkdir
182
183
184 # These paths must be absolute, as we switch directories pretty often.
185 root := $(shell pwd)/play
186 stampdir := $(root)/stamps
187 sdir := $(root)/src
188 bdir := $(root)/build
189 idir := $(root)/inst
190
191 speedo_build_list = $(speedo_spkgs)
192
193 ifeq ($(TARGETOS),w32)
194   speedo_autogen_buildopt="--build-w32"
195 else
196   speedo_autogen_buildopt=
197 endif
198
199 ifeq ($(MAKE_J),)
200   speedo_makeopt=
201 else
202   speedo_makeopt=-j$(MAKE_J)
203 endif
204
205
206 # The playground area is our scratch area, where we unpack, build and
207 # install the packages.
208 $(stampdir)/stamp-directories:
209         $(MKDIR) $(root)
210         $(MKDIR) $(stampdir)
211         $(MKDIR) $(sdir)
212         $(MKDIR) $(bdir)
213         $(MKDIR) $(idir)
214         touch $(stampdir)/stamp-directories
215
216 # Frob the name $1 by converting all '-' and '+' characters to '_'.
217 define FROB_macro
218 $(subst +,_,$(subst -,_,$(1)))
219 endef
220
221 # Get the variable $(1) (which may contain '-' and '+' characters).
222 define GETVAR
223 $($(call FROB_macro,$(1)))
224 endef
225
226 # Set a couple of common variables.
227 define SETVARS
228         pkg="$(1)";                                                     \
229         git="$(call GETVAR,speedo_pkg_$(1)_git)";                       \
230         gitref="$(call GETVAR,speedo_pkg_$(1)_gitref)";                 \
231         tar="$(call GETVAR,speedo_pkg_$(1)_tar)";                       \
232         pkgsdir="$(sdir)/$(1)";                                         \
233         pkgbdir="$(bdir)/$(1)";                                         \
234         pkgcfg="$(call GETVAR,speedo_pkg_$(1)_configure)";              \
235         pkgmkargs="$(call GETVAR,speedo_pkg_$(1)_make_args)";           \
236         pkgmkargs_inst="$(call GETVAR,speedo_pkg_$(1)_make_args_inst)"; \
237         export PATH="$(idir)/bin:$${PATH}";                             \
238         export LD_LIBRARY_PATH="$(idir)/lib:$${LD_LIBRARY_PATH}"
239 endef
240
241
242 # Template for source packages.
243
244 define SPKG_template
245
246 $(stampdir)/stamp-$(1)-00-unpack: $(stampdir)/stamp-directories
247         @echo "speedo: /*"
248         @echo "speedo:  *   $(1)"
249         @echo "speedo:  */"
250         @(set -e; cd $(sdir);                           \
251          $(call SETVARS,$(1));                          \
252          if [ -n "$$$${git}" ]; then                    \
253            echo "speedo: unpacking $(1) from $$$${git}:$$$${gitref}"; \
254            git clone -b "$$$${gitref}" "$$$${git}" "$$$${pkg}"; \
255            cd "$$$${pkg}";                              \
256            AUTOGEN_SH_SILENT=1 ./autogen.sh;            \
257          elif [ -n "$$$${tar}" ]; then                  \
258            echo "speedo: unpacking $(1) from $$$${tar}"; \
259            case "$$$${tar}" in                          \
260              *.gz) opt=z ;;                             \
261              *.bz2) opt=j ;;                            \
262              *) opt= ;;                                 \
263            esac;                                        \
264            case "$$$${tar}" in                          \
265              /*) cmd=cat ;;                             \
266              *) cmd="wget -q -O -" ;;                   \
267            esac;                                        \
268            $$$${cmd} "$$$${tar}" | tar x$$$${opt}f - ;  \
269            base=`echo "$$$${tar}" | sed -e 's,^.*/,,'   \
270                  | sed -e 's,\.tar.*$$$$,,'`;           \
271            mv $$$${base} $(1);                          \
272          else                                           \
273            echo "speedo: unpacking $(1) from UNKNOWN";  \
274          fi)
275         @touch $(stampdir)/stamp-$(1)-00-unpack
276
277 $(stampdir)/stamp-$(1)-01-configure: $(stampdir)/stamp-$(1)-00-unpack
278         @echo "speedo: configuring $(1)"
279         @($(call SETVARS,$(1));                         \
280          mkdir "$$$${pkgbdir}";                         \
281          cd "$$$${pkgbdir}";                            \
282          if [ -n "$(speedo_autogen_buildopt)" ]; then   \
283             eval AUTOGEN_SH_SILENT=1 w32root="$(idir)"  \
284                  "$$$${pkgsdir}/autogen.sh"             \
285                  $(speedo_autogen_buildopt)             \
286                  $$$${pkgcfg};                          \
287          else                                           \
288             eval "$$$${pkgsdir}/configure"              \
289                  --silent                               \
290                  --enable-maintainer-mode               \
291                  --prefix="$(idir)"                     \
292                  $$$${pkgcfg};                          \
293          fi)
294         @touch $(stampdir)/stamp-$(1)-01-configure
295
296 $(stampdir)/stamp-$(1)-02-make: $(stampdir)/stamp-$(1)-01-configure
297         @echo "speedo: making $(1)"
298         @($(call SETVARS,$(1));                         \
299           cd "$$$${pkgbdir}";                           \
300           $(MAKE) --no-print-directory $(speedo_makeopt) $$$${pkgmkargs} V=0)
301         @touch $(stampdir)/stamp-$(1)-02-make
302
303 # Note that post_install must come last because it may be empty and
304 # "; ;" is a syntax error.
305 $(stampdir)/stamp-$(1)-03-install: $(stampdir)/stamp-$(1)-02-make
306         @echo "speedo: installing $(1)"
307         @($(call SETVARS,$(1));                         \
308           cd "$$$${pkgbdir}";                           \
309           $(MAKE) --no-print-directory $$$${pkgmkargs_inst} install-strip V=0;\
310           $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
311         @touch $(stampdir)/stamp-$(1)-03-install
312
313 $(stampdir)/stamp-final-$(1): $(stampdir)/stamp-$(1)-03-install
314         @touch $(stampdir)/stamp-final-$(1)
315
316 .PHONY : clean-$(1)
317 clean-$(1):
318         @echo "speedo: uninstalling $(1)"
319         @($(call SETVARS,$(1));                         \
320          (cd "$$$${pkgbdir}" 2>/dev/null &&             \
321           $(MAKE) --no-print-directory                  \
322            $$$${pkgmkargs_inst} uninstall V=0 ) || true;\
323          rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}" || true)
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