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