speedo: Improve speedo Makefile.
[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  pkg2rep=/dir/with/tarballs
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 # We need to know our own name.
46 SPEEDO_MK := $(realpath $(lastword $(MAKEFILE_LIST)))
47
48 .PHONY : help native native-gui w32-installer w32-source
49 .PHONY :      git-native git-native-gui git-w32-installer git-w32-source
50 .PHONY :      this-native this-native-gui this-w32-installer this-w32-source
51
52 help:
53         @echo 'usage: make -f speedo.mk TARGET'
54         @echo '       with TARGET being one of:'
55         @echo '  help           This help'
56         @echo '  native         Native build of the GnuPG core'
57         @echo '  native-gui     Ditto but with pinentry and GPA'
58         @echo '  w32-installer  Build a Windows installer'
59         @echo '  w32-source     Pack a source archive'
60         @echo
61         @echo 'Prepend TARGET with "git-" to build from GIT repos'
62         @echo 'Prepend TARGET with "this-" to build from the source tarball'
63
64 SPEEDOMAKE := $(MAKE) -f $(SPEEDO_MK) UPD_SWDB=1
65
66 native:
67         $(SPEEDOMAKE) TARGETOS=native WHAT=release WITH_GUI=0 all
68
69 git-native:
70         $(SPEEDOMAKE) TARGETOS=native WHAT=git     WITH_GUI=0 all
71
72 this-native:
73         $(SPEEDOMAKE) TARGETOS=native WHAT=this    WITH_GUI=0 all
74
75 native-gui:
76         $(SPEEDOMAKE) TARGETOS=native WHAT=release WITH_GUI=1 all
77
78 git-native-gui:
79         $(SPEEDOMAKE) TARGETOS=native WHAT=git     WITH_GUI=1 all
80
81 this-native-gui:
82         $(SPEEDOMAKE) TARGETOS=native WHAT=this    WITH_GUI=1 all
83
84 w32-installer:
85         $(SPEEDOMAKE) TARGETOS=w32    WHAT=release WITH_GUI=1 installer
86
87 git-w32-installer:
88         $(SPEEDOMAKE) TARGETOS=w32    WHAT=git     WITH_GUI=1 installer
89
90 this-w32-installer:
91         $(SPEEDOMAKE) TARGETOS=w32    WHAT=this    WITH_GUI=1 installer
92
93 w32-source:
94         $(SPEEDOMAKE) TARGETOS=w32    WHAT=release WITH_GUI=1 dist-source
95
96 git-w32-source:
97         $(SPEEDOMAKE) TARGETOS=w32    WHAT=git     WITH_GUI=1 dist-source
98
99 this-w32-source:
100         $(SPEEDOMAKE) TARGETOS=w32    WHAT=git     WITH_GUI=1 dist-source
101
102
103 # Set this to "git" to build from git,
104 #          to "release" from tarballs,
105 #          to "this" from the unpacked sources.
106 WHAT=git
107
108 # Set target to "native" or "w32"
109 TARGETOS=w32
110
111 # Set to 1 to build the GUI tools
112 WITH_GUI=0
113
114 # Set to 1 to really download the swdb.
115 UPD_SWDB=0
116
117 # Set to the location of the directory with tarballs of
118 # external packages.
119 TARBALLS=$(shell pwd)/../tarballs
120
121 #  Number of parallel make jobs
122 MAKE_J=3
123
124 # Name to use for the w32 installer and sources
125 INST_NAME=gnupg-w32
126
127
128 # Directory names.
129 # They must be absolute, as we switch directories pretty often.
130 root := $(shell pwd)/PLAY
131 sdir := $(root)/src
132 bdir := $(root)/build
133 bdir6:= $(root)/build-w64
134 idir := $(root)/inst
135 idir6:= $(root)/inst-w64
136 stampdir := $(root)/stamps
137 topsrc := $(shell cd $(dir $(SPEEDO_MK)).. && pwd)
138 auxsrc := $(topsrc)/build-aux/speedo
139 patdir := $(topsrc)/build-aux/speedo/patches
140 w32src := $(topsrc)/build-aux/speedo/w32
141
142 # =====BEGIN LIST OF PACKAGES=====
143 # The packages that should be built.  The order is also the build order.
144 # Fixme: Do we need to build pkg-config for cross-building?
145
146 speedo_spkgs  = \
147         libgpg-error npth libgcrypt
148
149 ifeq ($(TARGETOS),w32)
150 speedo_spkgs += \
151         zlib libiconv gettext
152 endif
153
154 speedo_spkgs += \
155         libassuan libksba gnupg
156
157 ifeq ($(TARGETOS),w32)
158 speedo_spkgs += \
159         libffi glib pkg-config
160 endif
161
162 speedo_spkgs += \
163         gpgme
164
165 ifeq ($(TARGETOS),w32)
166 speedo_spkgs += \
167         libpng \
168         gdk-pixbuf atk pixman cairo pango gtk+
169 endif
170
171
172 ifeq ($(WITH_GUI),1)
173 speedo_spkgs += \
174         pinentry gpa
175 endif
176
177 ifeq ($(TARGETOS),w32)
178 speedo_spkgs += \
179         gpgex
180 endif
181
182 # =====END LIST OF PACKAGES=====
183
184
185 # Packages which are additionally build for 64 bit Windows
186 speedo_w64_spkgs  = \
187         libgpg-error libiconv gettext libassuan gpgex
188
189 # Packages which use the gnupg autogen.sh build style
190 speedo_gnupg_style = \
191         libgpg-error npth libgcrypt  \
192         libassuan libksba gnupg gpgme \
193         pinentry gpa gpgex
194
195 # Packages which use only make and no build directory
196 speedo_make_only_style = \
197         zlib
198
199 # Get the content of the software DB.
200 ifeq ($(UPD_SWDB),1)
201 SWDB := $(shell $(topsrc)/build-aux/getswdb.sh && echo okay)
202 ifeq ($(strip $(SWDB)),)
203 $(error Error getting GnuPG software version database)
204 endif
205
206 # Version numbers of the released packages
207 gnupg_ver = $(shell cat $(topsrc)/VERSION)
208
209 libgpg_error_ver := $(shell awk '$$1=="libgpg_error_ver" {print $$2}' swdb.lst)
210 libgpg_error_sha1:= $(shell awk '$$1=="libgpg_error_sha1" {print $$2}' swdb.lst)
211
212 npth_ver  := $(shell awk '$$1=="npth_ver" {print $$2}' swdb.lst)
213 npth_sha1 := $(shell awk '$$1=="npth_sha1" {print $$2}' swdb.lst)
214
215 libgcrypt_ver  := $(shell awk '$$1=="libgcrypt_ver" {print $$2}' swdb.lst)
216 libgcrypt_sha1 := $(shell awk '$$1=="libgcrypt_sha1" {print $$2}' swdb.lst)
217
218 libassuan_ver  := $(shell awk '$$1=="libassuan_ver" {print $$2}' swdb.lst)
219 libassuan_sha1 := $(shell awk '$$1=="libassuan_sha1" {print $$2}' swdb.lst)
220
221 libksba_ver  := $(shell awk '$$1=="libksba_ver" {print $$2}' swdb.lst)
222 libksba_sha1 := $(shell awk '$$1=="libksba_sha1" {print $$2}' swdb.lst)
223
224 gpgme_ver  := $(shell awk '$$1=="gpgme_ver" {print $$2}' swdb.lst)
225 gpgme_sha1 := $(shell awk '$$1=="gpgme_sha1" {print $$2}' swdb.lst)
226
227 pinentry_ver  := $(shell awk '$$1=="pinentry_ver" {print $$2}' swdb.lst)
228 pinentry_sha1 := $(shell awk '$$1=="pinentry_sha1" {print $$2}' swdb.lst)
229
230 gpa_ver  := $(shell awk '$$1=="gpa_ver" {print $$2}' swdb.lst)
231 gpa_sha1 := $(shell awk '$$1=="gpa_sha1" {print $$2}' swdb.lst)
232
233 gpgex_ver  := $(shell awk '$$1=="gpgex_ver" {print $$2}' swdb.lst)
234 gpgex_sha1 := $(shell awk '$$1=="gpgex_sha1" {print $$2}' swdb.lst)
235
236 $(info Information from the version database)
237 $(info GnuPG ..........: $(gnupg_ver))
238 $(info Libgpg-error ...: $(libgpg_error_ver))
239 $(info Npth ...........: $(npth_ver))
240 $(info Libgcrypt ......: $(libgcrypt_ver))
241 $(info Libassuan ......: $(libassuan_ver))
242 $(info GPGME ..........: $(gpgme_ver))
243 $(info Pinentry .......: $(pinentry_ver))
244 $(info GPA ............: $(gpa_ver))
245 $(info GpgEX.... ......: $(gpgex_ver))
246 endif
247
248 # Version number for external packages
249 pkg_config_ver = 0.23
250 zlib_ver = 1.2.8
251 libiconv_ver = 1.14
252 gettext_ver = 0.18.2.1
253 libffi_ver = 3.0.13
254 glib_ver = 2.34.3
255 libpng_ver = 1.4.12
256 gdk_pixbuf_ver = 2.26.5
257 atk_ver = 1.32.0
258 pango_ver = 1.29.4
259 pixman_ver = 0.32.4
260 cairo_ver = 1.12.16
261 gtk__ver = 2.24.17
262
263
264 # The GIT repository.  Using a local repo is much faster.
265 #gitrep = git://git.gnupg.org
266 gitrep = ${HOME}/s
267
268 # The tarball directories
269 pkgrep = ftp://ftp.gnupg.org/gcrypt
270 pkg2rep = $(TARBALLS)
271
272 # For each package, the following variables can be defined:
273 #
274 # speedo_pkg_PACKAGE_git: The GIT repository that should be built.
275 # speedo_pkg_PACKAGE_gitref: The GIT revision to checkout
276 #
277 # speedo_pkg_PACKAGE_tar: URL to the tar file that should be built.
278 #
279 # Exactly one of the above variables is required.  Note that this
280 # version of speedo does not cache repositories or tar files, and does
281 # not test the integrity of the downloaded software.  If you care
282 # about this, you can also specify filenames to locally verified files.
283 # Filenames are differentiated from URLs by starting with a slash '/'.
284 #
285 # speedo_pkg_PACKAGE_configure: Extra arguments to configure.
286 #
287 # speedo_pkg_PACKAGE_make_args: Extra arguments to make.
288 #
289 # speedo_pkg_PACKAGE_make_args_inst: Extra arguments to make install.
290 #
291 # Note that you can override the defaults in this file in a local file
292 # "config.mk"
293
294 ifeq ($(WHAT),this)
295 else ifeq ($(WHAT),git)
296   speedo_pkg_libgpg_error_git = $(gitrep)/libgpg-error
297   speedo_pkg_libgpg_error_gitref = master
298   speedo_pkg_npth_git = $(gitrep)/npth
299   speedo_pkg_npth_gitref = master
300   speedo_pkg_libassuan_git = $(gitrep)/libassuan
301   speedo_pkg_libassuan_gitref = master
302   speedo_pkg_libgcrypt_git = $(gitrep)/libgcrypt
303   speedo_pkg_libgcrypt_gitref = LIBGCRYPT-1-6-BRANCH
304   speedo_pkg_libksba_git = $(gitrep)/libksba
305   speedo_pkg_libksba_gitref = master
306   speedo_pkg_gpgme_git = $(gitrep)/gpgme
307   speedo_pkg_gpgme_gitref = master
308   speedo_pkg_pinentry_git = $(gitrep)/pinentry
309   speedo_pkg_pinentry_gitref = master
310   speedo_pkg_gpa_git = $(gitrep)/gpa
311   speedo_pkg_gpa_gitref = master
312   speedo_pkg_gpgex_git = $(gitrep)/gpgex
313   speedo_pkg_gpgex_gitref = master
314 else ifeq ($(WHAT),release)
315   speedo_pkg_libgpg_error_tar = \
316         $(pkgrep)/libgpg-error/libgpg-error-$(libgpg_error_ver).tar.bz2
317   speedo_pkg_npth_tar = \
318         $(pkgrep)/npth/npth-$(npth_ver).tar.bz2
319   speedo_pkg_libassuan_tar = \
320         $(pkgrep)/libassuan/libassuan-$(libassuan_ver).tar.bz2
321   speedo_pkg_libgcrypt_tar = \
322         $(pkgrep)/libgcrypt/libgcrypt-$(libgcrypt_ver).tar.bz2
323   speedo_pkg_libksba_tar = \
324         $(pkgrep)/libksba/libksba-$(libksba_ver).tar.bz2
325   speedo_pkg_gpgme_tar = \
326         $(pkgrep)/gpgme/gpgme-$(gpgme_ver).tar.bz2
327   speedo_pkg_pinentry_tar = \
328         $(pkgrep)/pinentry/pinentry-$(pinentry_ver).tar.bz2
329   speedo_pkg_gpa_tar = \
330         $(pkgrep)/gpa/gpa-$(gpa_ver).tar.bz2
331   speedo_pkg_gpgex_tar = \
332         $(pkgrep)/gpex/gpgex-$(gpa_ver).tar.bz2
333 else
334   $(error invalid value for WHAT (use on of: git release this))
335 endif
336
337 speedo_pkg_pkg_config_tar = $(pkg2rep)/pkg-config-$(pkg_config_ver).tar.gz
338 speedo_pkg_zlib_tar       = $(pkg2rep)/zlib-$(zlib_ver).tar.gz
339 speedo_pkg_libiconv_tar   = $(pkg2rep)/libiconv-$(libiconv_ver).tar.gz
340 speedo_pkg_gettext_tar    = $(pkg2rep)/gettext-$(gettext_ver).tar.gz
341 speedo_pkg_libffi_tar     = $(pkg2rep)/libffi-$(libffi_ver).tar.gz
342 speedo_pkg_glib_tar       = $(pkg2rep)/glib-$(glib_ver).tar.xz
343 speedo_pkg_libpng_tar     = $(pkg2rep)/libpng-$(libpng_ver).tar.bz2
344 speedo_pkg_gdk_pixbuf_tar = $(pkg2rep)/gdk-pixbuf-$(gdk_pixbuf_ver).tar.xz
345 speedo_pkg_atk_tar        = $(pkg2rep)/atk-$(atk_ver).tar.bz2
346 speedo_pkg_pango_tar      = $(pkg2rep)/pango-$(pango_ver).tar.bz2
347 speedo_pkg_pixman_tar     = $(pkg2rep)/pixman-$(pixman_ver).tar.gz
348 speedo_pkg_cairo_tar      = $(pkg2rep)/cairo-$(cairo_ver).tar.xz
349 speedo_pkg_gtk__tar       = $(pkg2rep)/gtk+-$(gtk__ver).tar.xz
350
351
352 #
353 # Package build options
354 #
355
356 speedo_pkg_libgpg_error_configure = --enable-static
357 speedo_pkg_w64_libgpg_error_configure = --enable-static
358
359 speedo_pkg_libassuan_configure = --enable-static
360 speedo_pkg_w64_libassuan_configure = --enable-static
361
362 speedo_pkg_libgcrypt_configure = --disable-static
363
364 speedo_pkg_libksba_configure = --disable-static
365
366 speedo_pkg_gnupg_configure = --enable-gpg2-is-gpg --disable-g13
367 speedo_pkg_gnupg_extracflags = -g
368
369 define speedo_pkg_gnupg_post_install
370 (set -e; \
371  sed -n  's/.*PACKAGE_VERSION "\(.*\)"/\1/p' config.h >$(idir)/INST_VERSION; \
372  sed -n  's/.*W32INFO_VI_PRODUCTVERSION \(.*\)/\1/p' common/w32info-rc.h \
373     |sed 's/,/./g' >$(idir)/INST_PROD_VERSION )
374 endef
375
376
377 # The LDFLAGS is needed for -lintl for glib.
378 speedo_pkg_gpgme_configure = \
379         --enable-static --enable-w32-glib --disable-w32-qt \
380         --with-gpg-error-prefix=$(idir) \
381         LDFLAGS=-L$(idir)/lib
382
383 speedo_pkg_pinentry_configure = \
384         --disable-pinentry-qt --disable-pinentry-qt4 --disable-pinentry-gtk \
385         --enable-pinentry-gtk2 \
386         --with-glib-prefix=$(idir) --with-gtk-prefix=$(idir) \
387         CPPFLAGS=-I$(idir)/include   \
388         LDFLAGS=-L$(idir)/lib        \
389         CXXFLAGS=-static-libstdc++
390
391 speedo_pkg_gpa_configure = \
392         --with-libiconv-prefix=$(idir) --with-libintl-prefix=$(idir) \
393         --with-gpgme-prefix=$(idir) --with-zlib=$(idir) \
394         --with-libassuan-prefix=$(idir) --with-gpg-error-prefix=$(idir)
395
396 speedo_pkg_gpgex_configure = \
397         --with-gpg-error-prefix=$(idir) \
398         --with-libassuan-prefix=$(idir)
399
400 speedo_pkg_w64_gpgex_configure = \
401         --with-gpg-error-prefix=$(idir6) \
402         --with-libassuan-prefix=$(idir6)
403
404
405 #
406 # External packages
407 #
408
409 ifeq ($(TARGETOS),w32)
410 speedo_pkg_zlib_make_args = \
411         -fwin32/Makefile.gcc PREFIX=$(host)- IMPLIB=libz.dll.a
412
413 speedo_pkg_zlib_make_args_inst = \
414         -fwin32/Makefile.gcc \
415         BINARY_PATH=$(idir)/bin INCLUDE_PATH=$(idir)/include \
416         LIBRARY_PATH=$(idir)/lib SHARED_MODE=1 IMPLIB=libz.dll.a
417
418 # Zlib needs some special magic to generate a libtool file.
419 # We also install the pc file here.
420 define speedo_pkg_zlib_post_install
421 (set -e; mkdir $(idir)/lib/pkgconfig || true;           \
422 cp $(auxsrc)/zlib.pc $(idir)/lib/pkgconfig/;            \
423 cd $(idir);                                             \
424 echo "# Generated by libtool" > lib/libz.la             \
425 echo "dlname='../bin/zlib1.dll'" >> lib/libz.la;        \
426 echo "library_names='libz.dll.a'" >> lib/libz.la;       \
427 echo "old_library='libz.a'" >> lib/libz.la;             \
428 echo "dependency_libs=''" >> lib/libz.la;               \
429 echo "current=1" >> lib/libz.la;                        \
430 echo "age=2" >> lib/libz.la;                            \
431 echo "revision=5" >> lib/libz.la;                       \
432 echo "installed=yes" >> lib/libz.la;                    \
433 echo "shouldnotlink=no" >> lib/libz.la;                 \
434 echo "dlopen=''" >> lib/libz.la;                        \
435 echo "dlpreopen=''" >> lib/libz.la;                     \
436 echo "libdir=\"$(idir)/lib\"" >> lib/libz.la)
437 endef
438
439 endif
440
441
442 speedo_pkg_w64_libiconv_configure = \
443         --enable-shared=no --enable-static=yes
444
445 speedo_pkg_gettext_configure = \
446         --with-lib-prefix=$(idir) --with-libiconv-prefix=$(idir) \
447         CPPFLAGS=-I$(idir)/include LDFLAGS=-L$(idir)/lib
448 speedo_pkg_w64_gettext_configure = \
449         --with-lib-prefix=$(idir) --with-libiconv-prefix=$(idir) \
450         CPPFLAGS=-I$(idir6)/include LDFLAGS=-L$(idir6)/lib
451 speedo_pkg_gettext_extracflags = -O2
452 # We only need gettext-runtime and there is sadly no top level
453 # configure option for this
454 speedo_pkg_gettext_make_dir = gettext-runtime
455
456
457 speedo_pkg_glib_configure = \
458         --disable-modular-tests \
459         --with-libiconv=gnu \
460         CPPFLAGS=-I$(idir)/include \
461         LDFLAGS=-L$(idir)/lib \
462         CCC=$(host)-g++ \
463         LIBFFI_CFLAGS=-I$(idir)/lib/libffi-$(libffi_ver)/include \
464         LIBFFI_LIBS=\"-L$(idir)/lib -lffi\"
465 ifeq ($(TARGETOS),w32)
466 speedo_pkg_glib_extracflags = -march=i486
467 endif
468
469 ifeq ($(TARGETOS),w32)
470 speedo_pkg_libpng_configure = \
471         CPPFLAGS=\"-I$(idir)/include -DPNG_BUILD_DLL\" \
472         LDFLAGS=\"-L$(idir)/lib\" LIBPNG_DEFINES=\"-DPNG_BUILD_DLL\"
473 else
474 speedo_pkg_libpng_configure = \
475         CPPFLAGS=\"-I$(idir)/include\" \
476         LDFLAGS=\"-L$(idir)/lib\"
477 endif
478
479 ifneq ($(TARGETOS),w32)
480 speedo_pkg_gdk_pixbuf_configure = --without-libtiff --without-libjpeg
481 endif
482
483 speedo_pkg_pixman_configure = \
484         CPPFLAGS=-I$(idir)/include \
485         LDFLAGS=-L$(idir)/lib
486
487 ifeq ($(TARGETOS),w32)
488 speedo_pkg_cairo_configure = \
489         --disable-qt --disable-ft --disable-fc \
490         --enable-win32 --enable-win32-font \
491         CPPFLAGS=-I$(idir)/include \
492         LDFLAGS=-L$(idir)/lib
493 else
494 speedo_pkg_cairo_configure = \
495         --disable-qt \
496         CPPFLAGS=-I$(idir)/include \
497         LDFLAGS=-L$(idir)/lib
498 endif
499
500 speedo_pkg_pango_configure = \
501         --disable-gtk-doc  \
502         CPPFLAGS=-I$(idir)/include \
503         LDFLAGS=-L$(idir)/lib
504
505 speedo_pkg_gtk__configure = \
506         --disable-cups \
507         CPPFLAGS=-I$(idir)/include \
508         LDFLAGS=-L$(idir)/lib
509
510
511 # ---------
512
513 all: all-speedo
514
515 report: report-speedo
516
517 clean: clean-speedo
518
519 ifeq ($(TARGETOS),w32)
520 STRIP = i686-w64-mingw32-strip
521 else
522 STRIP = strip
523 endif
524 W32CC = i686-w64-mingw32-gcc
525
526 -include config.mk
527
528 #
529 #  The generic speedo code
530 #
531
532 MKDIR=mkdir
533 MAKENSIS=makensis
534 BUILD_ISODATE=$(shell date -u +%Y-%m-%d)
535
536 # The next two macros will work only after gnupg has been build.
537 INST_VERSION=$(shell head -1 $(idir)/INST_VERSION)
538 INST_PROD_VERSION=$(shell head -1 $(idir)/INST_PROD_VERSION)
539
540 # List with packages
541 speedo_build_list = $(speedo_spkgs)
542 speedo_w64_build_list = $(speedo_w64_spkgs)
543
544 # Determine build and host system
545 build := $(shell $(topsrc)/autogen.sh --silent --print-build)
546 ifeq ($(TARGETOS),w32)
547   speedo_autogen_buildopt := --build-w32
548   speedo_autogen_buildopt6 := --build-w64
549   host := $(shell $(topsrc)/autogen.sh --silent --print-host --build-w32)
550   host6:= $(shell $(topsrc)/autogen.sh --silent --print-host --build-w64)
551   speedo_host_build_option := --host=$(host) --build=$(build)
552   speedo_host_build_option6 := --host=$(host6) --build=$(build)
553   speedo_w32_cflags := -mms-bitfields
554 else
555   speedo_autogen_buildopt :=
556   host :=
557   speedo_host_build_option :=
558   speedo_w32_cflags :=
559 endif
560
561 ifeq ($(MAKE_J),)
562   speedo_makeopt=
563 else
564   speedo_makeopt=-j$(MAKE_J)
565 endif
566
567
568
569
570 # The playground area is our scratch area, where we unpack, build and
571 # install the packages.
572 $(stampdir)/stamp-directories:
573         $(MKDIR) $(root) || true
574         $(MKDIR) $(stampdir) || true
575         $(MKDIR) $(sdir)  || true
576         $(MKDIR) $(bdir)  || true
577         $(MKDIR) $(idir)   || true
578 ifeq ($(TARGETOS),w32)
579         $(MKDIR) $(bdir6)  || true
580         $(MKDIR) $(idir6)   || true
581 endif
582         touch $(stampdir)/stamp-directories
583
584 # Frob the name $1 by converting all '-' and '+' characters to '_'.
585 define FROB_macro
586 $(subst +,_,$(subst -,_,$(1)))
587 endef
588
589 # Get the variable $(1) (which may contain '-' and '+' characters).
590 define GETVAR
591 $($(call FROB_macro,$(1)))
592 endef
593
594 # Set a couple of common variables.
595 define SETVARS
596         pkg="$(1)";                                                     \
597         git="$(call GETVAR,speedo_pkg_$(1)_git)";                       \
598         gitref="$(call GETVAR,speedo_pkg_$(1)_gitref)";                 \
599         tar="$(call GETVAR,speedo_pkg_$(1)_tar)";                       \
600         sha1="$(call GETVAR,$(1)_sha1)";                                \
601         pkgsdir="$(sdir)/$(1)";                                         \
602         if [ "$(1)" = "gnupg" ]; then                                   \
603           git='';                                                       \
604           gitref='';                                                    \
605           tar='';                                                       \
606           pkgsdir="$(topsrc)";                                          \
607         fi;                                                             \
608         pkgbdir="$(bdir)/$(1)";                                         \
609         pkgcfg="$(call GETVAR,speedo_pkg_$(1)_configure)";              \
610         tmp="$(speedo_w32_cflags)                                       \
611              $(call GETVAR,speedo_pkg_$(1)_extracflags)";               \
612         if [ x$$$$(echo "$$$$tmp" | tr -d '[:space:]')x != xx ]; then   \
613           pkgextracflags="CFLAGS=\"$$$$tmp\"";                          \
614         else                                                            \
615           pkgextracflags=;                                              \
616         fi;                                                             \
617         pkgmkdir="$(call GETVAR,speedo_pkg_$(1)_make_dir)";             \
618         pkgmkargs="$(call GETVAR,speedo_pkg_$(1)_make_args)";           \
619         pkgmkargs_inst="$(call GETVAR,speedo_pkg_$(1)_make_args_inst)"; \
620         pkgmkargs_uninst="$(call GETVAR,speedo_pkg_$(1)_make_args_uninst)"; \
621         export PKG_CONFIG="/usr/bin/pkg-config";                        \
622         export PKG_CONFIG_PATH="$(idir)/lib/pkgconfig";                 \
623         [ "$(TARGETOS)" != native ] && export PKG_CONFIG_LIBDIR="";     \
624         export SYSROOT="$(idir)";                                       \
625         export PATH="$(idir)/bin:$${PATH}";                             \
626         export LD_LIBRARY_PATH="$(idir)/lib:$${LD_LIBRARY_PATH}"
627 endef
628
629 define SETVARS_W64
630         pkg="$(1)";                                                     \
631         git="$(call GETVAR,speedo_pkg_$(1)_git)";                       \
632         gitref="$(call GETVAR,speedo_pkg_$(1)_gitref)";                 \
633         tar="$(call GETVAR,speedo_pkg_$(1)_tar)";                       \
634         sha1="$(call GETVAR,$(1)_sha1)";                                \
635         pkgsdir="$(sdir)/$(1)";                                         \
636         if [ "$(1)" = "gnupg" ]; then                                   \
637           git='';                                                       \
638           gitref='';                                                    \
639           tar='';                                                       \
640           pkgsdir="$(topsrc)";                                          \
641         fi;                                                             \
642         pkgbdir="$(bdir6)/$(1)";                                        \
643         pkgcfg="$(call GETVAR,speedo_pkg_w64_$(1)_configure)";          \
644         tmp="$(speedo_w32_cflags)                                       \
645              $(call GETVAR,speedo_pkg_$(1)_extracflags)";               \
646         if [ x$$$$(echo "$$$$tmp" | tr -d '[:space:]')x != xx ]; then   \
647           pkgextracflags="CFLAGS=\"$$$$tmp\"";                          \
648         else                                                            \
649           pkgextracflags=;                                              \
650         fi;                                                             \
651         pkgmkdir="$(call GETVAR,speedo_pkg_$(1)_make_dir)";             \
652         pkgmkargs="$(call GETVAR,speedo_pkg_$(1)_make_args)";           \
653         pkgmkargs_inst="$(call GETVAR,speedo_pkg_$(1)_make_args_inst)"; \
654         pkgmkargs_uninst="$(call GETVAR,speedo_pkg_$(1)_make_args_uninst)"; \
655         export PKG_CONFIG="/usr/bin/pkg-config";                        \
656         export PKG_CONFIG_PATH="$(idir6)/lib/pkgconfig";                \
657         [ "$(TARGETOS)" != native ] && export PKG_CONFIG_LIBDIR="";     \
658         export SYSROOT="$(idir6)";                                      \
659         export PATH="$(idir6)/bin:$${PATH}";                            \
660         export LD_LIBRARY_PATH="$(idir6)/lib:$${LD_LIBRARY_PATH}"
661 endef
662
663
664 # Template for source packages.
665
666 # Note that the gnupg package is special: The package source dir is
667 # the same as the topsrc dir and thus we need to detect the gnupg
668 # package and cd to that directory.  We also test that no in-source build
669 # has been done.  autogen.sh is not run for gnupg.
670 #
671 define SPKG_template
672
673 $(stampdir)/stamp-$(1)-00-unpack: $(stampdir)/stamp-directories
674         @echo "speedo: /*"
675         @echo "speedo:  *   $(1)"
676         @echo "speedo:  */"
677         @(set -e; cd $(sdir);                           \
678          $(call SETVARS,$(1));                          \
679          if [ "$(WHAT)" = "this" ]; then                \
680            echo "speedo: using included source";        \
681          elif [ "$(1)" = "gnupg" ]; then                \
682            cd $$$${pkgsdir};                            \
683            if [ -f config.log ]; then                   \
684              echo "GnuPG has already been build in-source" >&2  ;\
685              echo "Please run \"make distclean\" and retry" >&2 ;\
686              exit 1 ;                                   \
687            fi;                                          \
688            echo "speedo: unpacking gnupg not needed";   \
689          elif [ -n "$$$${git}" ]; then                  \
690            echo "speedo: unpacking $(1) from $$$${git}:$$$${gitref}"; \
691            git clone -b "$$$${gitref}" "$$$${git}" "$$$${pkg}"; \
692            cd "$$$${pkg}";                              \
693            AUTOGEN_SH_SILENT=1 ./autogen.sh;            \
694          elif [ -n "$$$${tar}" ]; then                  \
695            echo "speedo: unpacking $(1) from $$$${tar}"; \
696            case "$$$${tar}" in                          \
697              *.gz) opt=z ;;                             \
698              *.bz2) opt=j ;;                            \
699              *.xz) opt=J ;;                             \
700              *) opt= ;;                                 \
701            esac;                                        \
702            [ -f tmp.tgz ] && rm tmp.tgz;                \
703            case "$$$${tar}" in                          \
704              /*) tar x$$$${opt}f - < $$$${tar} ;;       \
705              *)  wget -q -O - $$$${tar} | tee tmp.tgz | tar x$$$${opt}f - ;; \
706            esac;                                        \
707            if [ -f tmp.tgz ]; then                      \
708              if [ -n "$$$${sha1}" ]; then               \
709                tmp=$$$$(sha1sum <tmp.tgz|cut -d' ' -f1);\
710                if [ "$$$${tmp}" != "$$$${sha1}" ]; then \
711                  echo "speedo:";                        \
712                  echo "speedo: ERROR: checksum mismatch for $(1)";\
713                  echo "speedo:";                        \
714                  exit 1;                                \
715                fi;                                      \
716              else                                       \
717                echo "speedo:";                          \
718                echo "speedo: Warning: No checksum known for $(1)";\
719                echo "speedo:";                          \
720              fi;                                        \
721              rm tmp.tgz;                                \
722            fi;                                          \
723            base=`echo "$$$${tar}" | sed -e 's,^.*/,,'   \
724                  | sed -e 's,\.tar.*$$$$,,'`;           \
725            mv $$$${base} $(1);                          \
726            patch="$(patdir)/$(1)-$$$${base#$(1)-}.patch";\
727            if [ -x "$$$${patch}" ]; then                \
728              echo "speedo: applying patch $$$${patch}"; \
729              cd $(1); "$$$${patch}";                    \
730            elif [ -f "$$$${patch}" ]; then              \
731              echo "speedo: warning: $$$${patch} is not executable"; \
732            fi;                                          \
733          else                                           \
734            echo "speedo: unpacking $(1) from UNKNOWN";  \
735          fi)
736         @touch $(stampdir)/stamp-$(1)-00-unpack
737
738 $(stampdir)/stamp-$(1)-01-configure: $(stampdir)/stamp-$(1)-00-unpack
739         @echo "speedo: configuring $(1)"
740 ifneq ($(findstring $(1),$(speedo_make_only_style)),)
741         @echo "speedo: configure run not required"
742 else ifneq ($(findstring $(1),$(speedo_gnupg_style)),)
743         @($(call SETVARS,$(1));                         \
744          mkdir "$$$${pkgbdir}";                         \
745          cd "$$$${pkgbdir}";                            \
746          if [ -n "$(speedo_autogen_buildopt)" ]; then   \
747             eval AUTOGEN_SH_SILENT=1 w32root="$(idir)"  \
748                "$$$${pkgsdir}/autogen.sh"               \
749                $(speedo_autogen_buildopt)               \
750                $$$${pkgcfg} $$$${pkgextracflags};       \
751          else                                           \
752             eval "$$$${pkgsdir}/configure"              \
753                --silent                                 \
754                --enable-maintainer-mode                 \
755                --prefix="$(idir)"                       \
756                $$$${pkgcfg} $$$${pkgextracflags};       \
757          fi)
758 else
759         @($(call SETVARS,$(1));                         \
760          mkdir "$$$${pkgbdir}";                         \
761          cd "$$$${pkgbdir}";                            \
762          eval "$$$${pkgsdir}/configure"                 \
763              --silent $(speedo_host_build_option)       \
764              --prefix="$(idir)"                         \
765              $$$${pkgcfg}  $$$${pkgextracflags};        \
766          )
767 endif
768         @touch $(stampdir)/stamp-$(1)-01-configure
769
770 # Note that unpack has no 64 bit version becuase it is just the source.
771 # Fixme: We should use templates to create the standard and w64
772 # version of these rules.
773 $(stampdir)/stamp-w64-$(1)-01-configure: $(stampdir)/stamp-$(1)-00-unpack
774         @echo "speedo: configuring $(1) (64 bit)"
775 ifneq ($(findstring $(1),$(speedo_make_only_style)),)
776         @echo "speedo: configure run not required"
777 else ifneq ($(findstring $(1),$(speedo_gnupg_style)),)
778         @($(call SETVARS_W64,$(1));                     \
779          mkdir "$$$${pkgbdir}";                         \
780          cd "$$$${pkgbdir}";                            \
781          if [ -n "$(speedo_autogen_buildopt)" ]; then   \
782             eval AUTOGEN_SH_SILENT=1 w64root="$(idir6)" \
783                "$$$${pkgsdir}/autogen.sh"               \
784                $(speedo_autogen_buildopt6)              \
785                $$$${pkgcfg} $$$${pkgextracflags};       \
786          else                                           \
787             eval "$$$${pkgsdir}/configure"              \
788                --silent                                 \
789                --enable-maintainer-mode                 \
790                --prefix="$(idir6)"                      \
791                $$$${pkgcfg} $$$${pkgextracflags};       \
792          fi)
793 else
794         @($(call SETVARS_W64,$(1));                     \
795          mkdir "$$$${pkgbdir}";                         \
796          cd "$$$${pkgbdir}";                            \
797          eval "$$$${pkgsdir}/configure"                 \
798              --silent $(speedo_host_build_option6)      \
799              --prefix="$(idir6)"                        \
800              $$$${pkgcfg} $$$${pkgextracflags};         \
801          )
802 endif
803         @touch $(stampdir)/stamp-w64-$(1)-01-configure
804
805
806 $(stampdir)/stamp-$(1)-02-make: $(stampdir)/stamp-$(1)-01-configure
807         @echo "speedo: making $(1)"
808 ifneq ($(findstring $(1),$(speedo_make_only_style)),)
809         @($(call SETVARS,$(1));                         \
810           cd "$$$${pkgsdir}";                           \
811           test -n "$$$${pkgmkdir}" && cd "$$$${pkgmkdir}"; \
812           if test "$$$${pkg}" = zlib -a "$(TARGETOS)" != w32 ; then \
813             ./configure --prefix="$(idir)" ; \
814           fi ;\
815           $(MAKE) --no-print-directory $(speedo_makeopt) $$$${pkgmkargs} V=0)
816 else
817         @($(call SETVARS,$(1));                         \
818           cd "$$$${pkgbdir}";                           \
819           test -n "$$$${pkgmkdir}" && cd "$$$${pkgmkdir}"; \
820           $(MAKE) --no-print-directory $(speedo_makeopt) $$$${pkgmkargs} V=1)
821 endif
822         @touch $(stampdir)/stamp-$(1)-02-make
823
824 $(stampdir)/stamp-w64-$(1)-02-make: $(stampdir)/stamp-w64-$(1)-01-configure
825         @echo "speedo: making $(1) (64 bit)"
826 ifneq ($(findstring $(1),$(speedo_make_only_style)),)
827         @($(call SETVARS_W64,$(1));                             \
828           cd "$$$${pkgsdir}";                           \
829           test -n "$$$${pkgmkdir}" && cd "$$$${pkgmkdir}"; \
830           $(MAKE) --no-print-directory $(speedo_makeopt) $$$${pkgmkargs} V=0)
831 else
832         @($(call SETVARS_W64,$(1));                             \
833           cd "$$$${pkgbdir}";                           \
834           test -n "$$$${pkgmkdir}" && cd "$$$${pkgmkdir}"; \
835           $(MAKE) --no-print-directory $(speedo_makeopt) $$$${pkgmkargs} V=1)
836 endif
837         @touch $(stampdir)/stamp-w64-$(1)-02-make
838
839 # Note that post_install must come last because it may be empty and
840 # "; ;" is a syntax error.
841 $(stampdir)/stamp-$(1)-03-install: $(stampdir)/stamp-$(1)-02-make
842         @echo "speedo: installing $(1)"
843 ifneq ($(findstring $(1),$(speedo_make_only_style)),)
844         @($(call SETVARS,$(1));                         \
845           cd "$$$${pkgsdir}";                           \
846           test -n "$$$${pkgmkdir}" && cd "$$$${pkgmkdir}"; \
847           $(MAKE) --no-print-directory $$$${pkgmkargs_inst} install V=1;\
848           $(call speedo_pkg_$(call FROB_macro,$(1))_post_install))
849 else
850         @($(call SETVARS,$(1));                         \
851           cd "$$$${pkgbdir}";                           \
852           test -n "$$$${pkgmkdir}" && cd "$$$${pkgmkdir}"; \
853           $(MAKE) --no-print-directory $$$${pkgmkargs_inst} install-strip V=0;\
854           $(call speedo_pkg_$(call FROB_macro,$(1))_post_install))
855 endif
856         touch $(stampdir)/stamp-$(1)-03-install
857
858 $(stampdir)/stamp-w64-$(1)-03-install: $(stampdir)/stamp-w64-$(1)-02-make
859         @echo "speedo: installing $(1) (64 bit)"
860 ifneq ($(findstring $(1),$(speedo_make_only_style)),)
861         @($(call SETVARS_W64,$(1));                             \
862           cd "$$$${pkgsdir}";                           \
863           test -n "$$$${pkgmkdir}" && cd "$$$${pkgmkdir}"; \
864           $(MAKE) --no-print-directory $$$${pkgmkargs_inst} install V=1;\
865           $(call speedo_pkg_$(call FROB_macro,$(1))_post_install))
866 else
867         @($(call SETVARS_W64,$(1));                             \
868           cd "$$$${pkgbdir}";                           \
869           test -n "$$$${pkgmkdir}" && cd "$$$${pkgmkdir}"; \
870           $(MAKE) --no-print-directory $$$${pkgmkargs_inst} install-strip V=0;\
871           $(call speedo_pkg_$(call FROB_macro,$(1))_post_install))
872 endif
873         touch $(stampdir)/stamp-w64-$(1)-03-install
874
875 $(stampdir)/stamp-final-$(1): $(stampdir)/stamp-$(1)-03-install
876         @echo "speedo: $(1) done"
877         @touch $(stampdir)/stamp-final-$(1)
878
879 $(stampdir)/stamp-w64-final-$(1): $(stampdir)/stamp-w64-$(1)-03-install
880         @echo "speedo: $(1) (64 bit) done"
881         @touch $(stampdir)/stamp-w64-final-$(1)
882
883 .PHONY : clean-$(1)
884 clean-$(1):
885         @echo "speedo: uninstalling $(1)"
886         @($(call SETVARS,$(1));                           \
887          (cd "$$$${pkgbdir}" 2>/dev/null &&               \
888           $(MAKE) --no-print-directory                    \
889            $$$${pkgmkargs_uninst} uninstall V=0 ) || true;\
890          if [ "$(1)" = "gnupg" ]; then                    \
891            rm -fR "$$$${pkgbdir}" || true                ;\
892          else                                             \
893            rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}" || true;\
894          fi)
895         -rm -f $(stampdir)/stamp-final-$(1) $(stampdir)/stamp-$(1)-*
896
897
898 .PHONY : build-$(1)
899 build-$(1): $(stampdir)/stamp-final-$(1)
900
901
902 .PHONY : report-$(1)
903 report-$(1):
904         @($(call SETVARS,$(1));                         \
905          echo -n $(1):\  ;                              \
906          if [ -n "$$$${git}" ]; then                    \
907            if [ -e "$$$${pkgsdir}/.git" ]; then         \
908              cd "$$$${pkgsdir}" &&                      \
909              git describe ;                             \
910            else                                         \
911              echo missing;                              \
912            fi                                           \
913          elif [ -n "$$$${tar}" ]; then                  \
914            base=`echo "$$$${tar}" | sed -e 's,^.*/,,'   \
915                  | sed -e 's,\.tar.*$$$$,,'`;           \
916            echo $$$${base} ;                            \
917          fi)
918
919 endef
920
921
922 # Insert the template for each source package.
923 $(foreach spkg, $(speedo_spkgs), $(eval $(call SPKG_template,$(spkg))))
924
925 $(stampdir)/stamp-final: $(stampdir)/stamp-directories
926 ifeq ($(TARGETOS),w32)
927 $(stampdir)/stamp-final: $(addprefix $(stampdir)/stamp-w64-final-,$(speedo_w64_build_list))
928 endif
929 $(stampdir)/stamp-final: $(addprefix $(stampdir)/stamp-final-,$(speedo_build_list))
930         touch $(stampdir)/stamp-final
931
932 all-speedo: $(stampdir)/stamp-final
933
934 report-speedo: $(addprefix report-,$(speedo_build_list))
935
936 # Just to check if we catched all stamps.
937 clean-stamps:
938         $(RM) -fR $(stampdir)
939
940 clean-speedo:
941         $(RM) -fR PLAY
942
943
944 #
945 # Windows installer
946 #
947
948 dist-source: all
949         for i in 00 01 02 03; do sleep 1;touch PLAY/stamps/stamp-*-${i}-*;done
950         (set -e;\
951          tarname="$(INST_NAME)-$(INST_VERSION)_$(BUILD_ISODATE).tar" ;\
952          [ -f "$$tarname" ] && rm "$$tarname" ;\
953          tar -C $(topsrc) -cf "$$tarname" --exclude-backups --exclude-vc \
954              --transform='s,^\./,$(INST_NAME)-$(INST_VERSION)/,' \
955              --anchored --exclude './PLAY' . ;\
956          tar --totals -rf "$$tarname" --exclude-backups --exclude-vc \
957               --transform='s,^,$(INST_NAME)-$(INST_VERSION)/,' \
958              PLAY/stamps/stamp-*-00-unpack PLAY/src ;\
959          xz "$$tarname" ;\
960         )
961
962
963 $(bdir)/NEWS.tmp: $(topsrc)/NEWS
964         sed -e '/^#/d' <$(topsrc)/NEWS >$(bdir)/NEWS.tmp
965
966 $(bdir)/README.txt: $(bdir)/NEWS.tmp $(w32src)/README.txt \
967                     $(w32src)/pkg-copyright.txt
968         sed -e '/^;.*/d;' \
969         -e '/!NEWSFILE!/{r NEWS.tmp' -e 'd;}' \
970         -e '/!PKG-COPYRIGHT!/{r $(w32src)/pkg-copyright.txt' -e 'd;}' \
971         -e 's,!VERSION!,$(INST_VERSION),g' \
972            < $(w32src)/README.txt \
973            | awk '{printf "%s\r\n", $$0}' >$(bdir)/README.txt
974
975 $(bdir)/g4wihelp.dll: $(w32src)/g4wihelp.c $(w32src)/exdll.h
976         (set -e; cd $(bdir); \
977          $(W32CC) -I. -shared -O2 -o g4wihelp.dll $(w32src)/g4wihelp.c \
978                   -lwinmm -lgdi32; \
979          $(STRIP) g4wihelp.dll)
980
981 w32_insthelpers: $(bdir)/g4wihelp.dll
982
983 $(bdir)/inst-options.ini: $(w32src)/inst-options.ini
984         cat $(w32src)/inst-options.ini >$(bdir)/inst-options.ini
985
986 installer: all w32_insthelpers $(w32dir)/inst-options.ini $(bdir)/README.txt
987         $(MAKENSIS) -V2 \
988                     -DINST_DIR=$(idir) \
989                     -DINST6_DIR=$(idir6) \
990                     -DBUILD_DIR=$(bdir) \
991                     -DTOP_SRCDIR=$(topsrc) \
992                     -DW32_SRCDIR=$(w32src) \
993                     -DBUILD_ISODATE=$(BUILD_ISODATE) \
994                     -DNAME=$(INST_NAME) \
995                     -DVERSION=$(INST_VERSION) \
996                     -DPROD_VERSION=$(INST_PROD_VERSION) \
997                     $(w32src)/inst.nsi
998         @echo "Ready: $(idir)/$(INST_NAME)-$(INST_VERSION)"
999
1000 #
1001 # Mark phony targets
1002 #
1003 .PHONY: all all-speedo report-speedo clean-stamps clean-speedo installer \
1004         w32_insthelpers