blob: 45de99356f5fd363c474109f6aa3e7edd7e6ed39 [file] [log] [blame]
Eric Andersena7e49eb2007-08-10 19:07:51 +00001################################################################################
Thomas Petazzonid8b55b92009-11-08 18:37:49 +01002# Autotools package infrastructure
Eric Andersena7e49eb2007-08-10 19:07:51 +00003#
Thomas Petazzonid8b55b92009-11-08 18:37:49 +01004# This file implements an infrastructure that eases development of
5# package .mk files for autotools packages. It should be used for all
Thomas Petazzonic0e6b522012-04-17 16:45:20 +02006# packages that use the autotools as their build system.
Eric Andersena7e49eb2007-08-10 19:07:51 +00007#
Thomas Petazzonid8b55b92009-11-08 18:37:49 +01008# See the Buildroot documentation for details on the usage of this
9# infrastructure
Eric Andersena7e49eb2007-08-10 19:07:51 +000010#
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010011# In terms of implementation, this autotools infrastructure requires
Thomas De Schampheleire60714bb2014-07-24 20:07:02 +020012# the .mk file to only specify metadata information about the
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010013# package: name, version, download URL, etc.
Bernhard Reutner-Fischer00b84562007-09-30 12:46:02 +000014#
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010015# We still allow the package .mk file to override what the different
16# steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
17# already defined, it is used as the list of commands to perform to
18# build the package, instead of the default autotools behaviour. The
19# package can also define some post operation hooks.
Bernhard Reutner-Fischer00b84562007-09-30 12:46:02 +000020#
Eric Andersena7e49eb2007-08-10 19:07:51 +000021################################################################################
22
Thomas Petazzoni102a93b2011-08-31 23:35:06 +020023
24#
25# Utility function to upgrade config.sub and config.guess files
26#
27# argument 1 : directory into which config.guess and config.sub need
28# to be updated. Note that config.sub and config.guess are searched
29# recursively in this directory.
30#
31define CONFIG_UPDATE
32 for file in config.guess config.sub; do \
33 for i in $$(find $(1) -name $$file); do \
34 cp support/gnuconfig/$$file $$i; \
35 done; \
36 done
37endef
38
Thomas Petazzonif4642ee2014-03-21 05:34:03 +010039# This function generates the ac_cv_file_<foo> value for a given
40# filename. This is needed to convince configure script doing
41# AC_CHECK_FILE() tests that the file actually exists, since such
42# tests cannot be done in a cross-compilation context. This function
43# takes as argument the path of the file. An example usage is:
44#
45# FOOBAR_CONF_ENV = \
46# $(call AUTOCONF_AC_CHECK_FILE_VAL,/dev/random)=yes
47AUTOCONF_AC_CHECK_FILE_VAL = ac_cv_file_$(subst -,_,$(subst /,_,$(subst .,_,$(1))))
48
Johan Oudinet3a82b1e2014-11-12 01:25:47 +010049#
50# Hook to update config.sub and config.guess if needed
51#
52define UPDATE_CONFIG_HOOK
53 @$(call MESSAGE,"Updating config.sub and config.guess")
54 $(call CONFIG_UPDATE,$(@D))
55endef
56
57#
58# Hook to patch libtool to make it work properly for cross-compilation
59#
60define LIBTOOL_PATCH_HOOK
Yann E. MORINb3b22222014-11-12 01:25:52 +010061 @$(call MESSAGE,"Patching libtool")
Waldemar Brodkorb7485ff42016-12-07 19:41:20 +010062 $(Q)for i in `find $($(PKG)_DIR) -name ltmain.sh`; do \
Danomi Manchego5eb23c92015-07-07 00:34:00 -040063 ltmain_version=`sed -n '/^[ \t]*VERSION=/{s/^[ \t]*VERSION=//;p;q;}' $$i | \
Danomi Manchego9917e482015-07-05 16:53:48 -040064 sed -e 's/\([0-9]*\.[0-9]*\).*/\1/' -e 's/\"//'`; \
Danomi Manchego5eb23c92015-07-07 00:34:00 -040065 ltmain_patchlevel=`sed -n '/^[ \t]*VERSION=/{s/^[ \t]*VERSION=//;p;q;}' $$i | \
Danomi Manchego9917e482015-07-05 16:53:48 -040066 sed -e 's/\([0-9]*\.[0-9]*\.*\)\([0-9]*\).*/\2/' -e 's/\"//'`; \
Yann E. MORINb3b22222014-11-12 01:25:52 +010067 if test $${ltmain_version} = '1.5'; then \
Romain Naourba4af1a2016-08-17 18:01:08 +020068 patch -i support/libtool/buildroot-libtool-v1.5.patch $${i}; \
Yann E. MORINb3b22222014-11-12 01:25:52 +010069 elif test $${ltmain_version} = "2.2"; then\
Romain Naourba4af1a2016-08-17 18:01:08 +020070 patch -i support/libtool/buildroot-libtool-v2.2.patch $${i}; \
Yann E. MORINb3b22222014-11-12 01:25:52 +010071 elif test $${ltmain_version} = "2.4"; then\
Yann E. MORIN383287c2015-01-27 00:30:24 +010072 if test $${ltmain_patchlevel:-0} -gt 2; then\
Romain Naourba4af1a2016-08-17 18:01:08 +020073 patch -i support/libtool/buildroot-libtool-v2.4.4.patch $${i}; \
Gustavo Zacarias4a28e352014-12-16 11:08:15 -030074 else \
Romain Naourba4af1a2016-08-17 18:01:08 +020075 patch -i support/libtool/buildroot-libtool-v2.4.patch $${i}; \
Gustavo Zacarias4a28e352014-12-16 11:08:15 -030076 fi \
Yann E. MORINb3b22222014-11-12 01:25:52 +010077 fi \
78 done
Johan Oudinet3a82b1e2014-11-12 01:25:47 +010079endef
80
81#
Sam bobroff41444d72016-11-28 16:11:39 +110082# Hook to patch common issue with configure on powerpc64{,le} failing
83# to detect shared library support:
84#
85define CONFIGURE_FIX_POWERPC64_HOOK
86 @$(call MESSAGE,"Checking configure (powerpc64/powerpc64le)")
87 support/scripts/fix-configure-powerpc64.sh $($(PKG)_DIR)
88endef
89
90#
Johan Oudinet3a82b1e2014-11-12 01:25:47 +010091# Hook to gettextize the package if needed
92#
93define GETTEXTIZE_HOOK
94 @$(call MESSAGE,"Gettextizing")
95 $(Q)cd $($(PKG)_SRCDIR) && $(GETTEXTIZE) $($(PKG)_GETTEXTIZE_OPTS)
96endef
97
98#
99# Hook to autoreconf the package if needed
100#
101define AUTORECONF_HOOK
102 @$(call MESSAGE,"Autoreconfiguring")
103 $(Q)cd $($(PKG)_SRCDIR) && $($(PKG)_AUTORECONF_ENV) $(AUTORECONF) $($(PKG)_AUTORECONF_OPTS)
Johan Oudinet3a82b1e2014-11-12 01:25:47 +0100104endef
105
Peter Korsgaardd58636d2009-01-16 10:27:48 +0000106################################################################################
Arnout Vandecappelle (Essensium/Mind)46fa5cb2012-07-03 00:07:08 +0200107# inner-autotools-package -- defines how the configuration, compilation and
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100108# installation of an autotools package should be done, implements a
109# few hooks to tune the build process for autotools specifities and
110# calls the generic package infrastructure to generate the necessary
111# make targets
Peter Korsgaardd58636d2009-01-16 10:27:48 +0000112#
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100113# argument 1 is the lowercase package name
Thomas De Schampheleire5bd9ed62014-07-24 20:57:41 +0200114# argument 2 is the uppercase package name, including a HOST_ prefix
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100115# for host packages
116# argument 3 is the uppercase package name, without the HOST_ prefix
117# for host packages
Thomas De Schampheleire26aef882014-02-05 10:44:03 +0100118# argument 4 is the type (target or host)
Peter Korsgaardd58636d2009-01-16 10:27:48 +0000119################################################################################
120
Arnout Vandecappelle (Essensium/Mind)46fa5cb2012-07-03 00:07:08 +0200121define inner-autotools-package
Eric Andersena7e49eb2007-08-10 19:07:51 +0000122
Thomas Petazzonid2c73f52010-04-28 23:40:45 +0200123ifndef $(2)_LIBTOOL_PATCH
124 ifdef $(3)_LIBTOOL_PATCH
Thomas De Schampheleire54456cc2014-06-11 21:12:24 +0200125 $(2)_LIBTOOL_PATCH = $$($(3)_LIBTOOL_PATCH)
Thomas Petazzonid2c73f52010-04-28 23:40:45 +0200126 else
127 $(2)_LIBTOOL_PATCH ?= YES
128 endif
129endif
130
Peter Korsgaardce1ae872011-05-17 10:00:01 +0200131ifndef $(2)_MAKE
132 ifdef $(3)_MAKE
Thomas De Schampheleire54456cc2014-06-11 21:12:24 +0200133 $(2)_MAKE = $$($(3)_MAKE)
Peter Korsgaardce1ae872011-05-17 10:00:01 +0200134 else
Thomas De Schampheleire54456cc2014-06-11 21:12:24 +0200135 $(2)_MAKE ?= $$(MAKE)
Peter Korsgaardce1ae872011-05-17 10:00:01 +0200136 endif
137endif
138
Peter Korsgaard97c68702013-10-02 23:37:58 +0200139ifndef $(2)_AUTORECONF
140 ifdef $(3)_AUTORECONF
Thomas De Schampheleire54456cc2014-06-11 21:12:24 +0200141 $(2)_AUTORECONF = $$($(3)_AUTORECONF)
Peter Korsgaard97c68702013-10-02 23:37:58 +0200142 else
143 $(2)_AUTORECONF ?= NO
144 endif
145endif
146
Yann E. MORIN89925832014-07-17 00:00:35 +0200147ifndef $(2)_GETTEXTIZE
148 ifdef $(3)_GETTEXTIZE
149 $(2)_GETTEXTIZE = $$($(3)_GETTEXTIZE)
150 else
151 $(2)_GETTEXTIZE ?= NO
152 endif
153endif
154
Yann E. MORINbea8f262014-07-18 23:02:31 +0200155ifeq ($(4),host)
Thomas De Schampheleire35886e52014-09-27 21:32:46 +0200156 $(2)_GETTEXTIZE_OPTS ?= $$($(3)_GETTEXTIZE_OPTS)
Yann E. MORIN89925832014-07-17 00:00:35 +0200157endif
158
Thomas De Schampheleire54456cc2014-06-11 21:12:24 +0200159ifeq ($(4),host)
Thomas De Schampheleire1d2574a2014-09-27 21:32:43 +0200160 $(2)_AUTORECONF_OPTS ?= $$($(3)_AUTORECONF_OPTS)
Thomas De Schampheleire54456cc2014-06-11 21:12:24 +0200161endif
162
Eric Andersena7e49eb2007-08-10 19:07:51 +0000163$(2)_CONF_ENV ?=
Thomas De Schampheleireaaffd202014-09-27 21:32:44 +0200164$(2)_CONF_OPTS ?=
Bernhard Reutner-Fischer00b84562007-09-30 12:46:02 +0000165$(2)_MAKE_ENV ?=
Thomas De Schampheleire0518a982014-09-27 21:32:38 +0200166$(2)_MAKE_OPTS ?=
Thomas De Schampheleireb1993432014-09-27 21:32:39 +0200167$(2)_INSTALL_OPTS ?= install
Thomas De Schampheleired6c32da2014-09-27 21:32:41 +0200168$(2)_INSTALL_STAGING_OPTS ?= DESTDIR=$$(STAGING_DIR) install
Maxime Hadjinlian44c48b12015-07-12 17:06:50 +0200169$(2)_INSTALL_TARGET_OPTS ?= DESTDIR=$$(TARGET_DIR) install
Eric Andersena7e49eb2007-08-10 19:07:51 +0000170
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100171#
172# Configure step. Only define it if not already defined by the package
173# .mk file. And take care of the differences between host and target
174# packages.
175#
176ifndef $(2)_CONFIGURE_CMDS
Thomas De Schampheleire26aef882014-02-05 10:44:03 +0100177ifeq ($(4),target)
Eric Andersena7e49eb2007-08-10 19:07:51 +0000178
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100179# Configure package for target
180define $(2)_CONFIGURE_CMDS
181 (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache && \
182 $$(TARGET_CONFIGURE_OPTS) \
183 $$(TARGET_CONFIGURE_ARGS) \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100184 $$($$(PKG)_CONF_ENV) \
Romain Naourf8d4fe32014-08-22 11:12:53 +0200185 CONFIG_SITE=/dev/null \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100186 ./configure \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100187 --target=$$(GNU_TARGET_NAME) \
188 --host=$$(GNU_TARGET_NAME) \
189 --build=$$(GNU_HOST_NAME) \
190 --prefix=/usr \
191 --exec-prefix=/usr \
192 --sysconfdir=/etc \
Jörg Krauseb3ed7c22014-10-18 00:36:32 +0200193 --localstatedir=/var \
Yann E. MORINa8d6e2c2011-08-10 00:12:34 +0200194 --program-prefix="" \
Thomas De Schampheleiree20df632014-02-05 14:51:00 +0100195 --disable-gtk-doc \
Bernd Kuhls356584c2014-10-19 11:59:03 +0200196 --disable-gtk-doc-html \
Thomas De Schampheleiree20df632014-02-05 14:51:00 +0100197 --disable-doc \
198 --disable-docs \
199 --disable-documentation \
200 --with-xmlto=no \
Peter Korsgaard4e0cd2e2014-02-09 01:00:22 +0100201 --with-fop=no \
Ignacy Gawędzki630c3352017-02-01 14:53:10 +0100202 $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
Gustavo Zacariascd4e4832015-04-19 09:40:01 -0300203 --enable-ipv6 \
Thomas Petazzoni8d603622017-07-04 16:47:48 +0200204 $$(NLS_OPTS) \
Thomas Petazzoni009d8fc2011-05-30 23:57:02 +0200205 $$(SHARED_STATIC_LIBS_OPTS) \
Thomas De Schampheleireaaffd202014-09-27 21:32:44 +0200206 $$(QUIET) $$($$(PKG)_CONF_OPTS) \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100207 )
208endef
Eric Andersena7e49eb2007-08-10 19:07:51 +0000209else
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100210
211# Configure package for host
Arnout Vandecappelle489970e2012-12-12 04:07:22 +0000212# disable all kind of documentation generation in the process,
213# because it often relies on host tools which may or may not be
214# installed.
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100215define $(2)_CONFIGURE_CMDS
216 (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \
Yann E. MORIN7d6858d2015-11-22 15:39:41 +0100217 $$(HOST_CONFIGURE_OPTS) \
218 CFLAGS="$$(HOST_CFLAGS)" \
219 LDFLAGS="$$(HOST_LDFLAGS)" \
220 $$($$(PKG)_CONF_ENV) \
221 CONFIG_SITE=/dev/null \
222 ./configure \
Arnout Vandecappelle8529a7d2017-07-04 16:03:59 +0200223 --prefix="$$(HOST_DIR)" \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100224 --sysconfdir="$$(HOST_DIR)/etc" \
Jörg Krauseb3ed7c22014-10-18 00:36:32 +0200225 --localstatedir="$$(HOST_DIR)/var" \
Thomas Petazzoni009d8fc2011-05-30 23:57:02 +0200226 --enable-shared --disable-static \
Arnout Vandecappelle489970e2012-12-12 04:07:22 +0000227 --disable-gtk-doc \
Bernd Kuhls356584c2014-10-19 11:59:03 +0200228 --disable-gtk-doc-html \
Arnout Vandecappelle489970e2012-12-12 04:07:22 +0000229 --disable-doc \
230 --disable-docs \
231 --disable-documentation \
Bernd Kuhls822a7572014-10-19 11:59:01 +0200232 --disable-debug \
Arnout Vandecappelle489970e2012-12-12 04:07:22 +0000233 --with-xmlto=no \
234 --with-fop=no \
Ignacy Gawędzki630c3352017-02-01 14:53:10 +0100235 $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
Thomas De Schampheleireaaffd202014-09-27 21:32:44 +0200236 $$(QUIET) $$($$(PKG)_CONF_OPTS) \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100237 )
238endef
239endif
Eric Andersena7e49eb2007-08-10 19:07:51 +0000240endif
241
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100242$(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100243
Thomas Petazzoni7dfa3b32010-04-28 23:40:42 +0200244ifeq ($$($(2)_AUTORECONF),YES)
Yann E. MORIN452c8da2014-11-12 01:25:53 +0100245
Yann E. MORIN89925832014-07-17 00:00:35 +0200246# This has to come before autoreconf
247ifeq ($$($(2)_GETTEXTIZE),YES)
248$(2)_PRE_CONFIGURE_HOOKS += GETTEXTIZE_HOOK
249$(2)_DEPENDENCIES += host-gettext
250endif
Lionel Landwerlin89d1ad92010-11-04 03:50:24 +0100251$(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
Johan Oudinetd2ae9012014-11-12 01:25:50 +0100252# default values are not evaluated yet, so don't rely on this defaulting to YES
253ifneq ($$($(2)_LIBTOOL_PATCH),NO)
254$(2)_PRE_CONFIGURE_HOOKS += LIBTOOL_PATCH_HOOK
255endif
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100256$(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
Yann E. MORIN452c8da2014-11-12 01:25:53 +0100257
258else # ! AUTORECONF = YES
259
260# default values are not evaluated yet, so don't rely on this defaulting to YES
261ifneq ($$($(2)_LIBTOOL_PATCH),NO)
262$(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK
263endif
264
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100265endif
266
Sam bobroff41444d72016-11-28 16:11:39 +1100267# Append a configure hook if building for a powerpc64 (or powerpc64le) arch.
268# Must be added after other pre-configure hooks that might regenerate the
269# configure script and overwrite the changes made here.
270ifneq ($$(filter powerpc64%,$$(if $$(filter target,$(4)),$$(ARCH),$$(HOSTARCH))),)
271$(2)_PRE_CONFIGURE_HOOKS += CONFIGURE_FIX_POWERPC64_HOOK
272endif
273
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100274#
275# Build step. Only define it if not already defined by the package .mk
276# file.
277#
278ifndef $(2)_BUILD_CMDS
Thomas De Schampheleire26aef882014-02-05 10:44:03 +0100279ifeq ($(4),target)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100280define $(2)_BUILD_CMDS
Thomas De Schampheleire0518a982014-09-27 21:32:38 +0200281 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100282endef
283else
284define $(2)_BUILD_CMDS
Thomas De Schampheleire0518a982014-09-27 21:32:38 +0200285 $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100286endef
287endif
288endif
289
290#
291# Host installation step. Only define it if not already defined by the
292# package .mk file.
293#
294ifndef $(2)_INSTALL_CMDS
295define $(2)_INSTALL_CMDS
Thomas De Schampheleireb1993432014-09-27 21:32:39 +0200296 $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_SRCDIR)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100297endef
298endif
299
300#
301# Staging installation step. Only define it if not already defined by
302# the package .mk file.
303#
304ifndef $(2)_INSTALL_STAGING_CMDS
305define $(2)_INSTALL_STAGING_CMDS
Thomas De Schampheleired6c32da2014-09-27 21:32:41 +0200306 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_SRCDIR)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100307endef
308endif
309
310#
311# Target installation step. Only define it if not already defined by
312# the package .mk file.
313#
314ifndef $(2)_INSTALL_TARGET_CMDS
315define $(2)_INSTALL_TARGET_CMDS
Thomas De Schampheleire57f2b8d2014-09-27 21:32:40 +0200316 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_SRCDIR)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100317endef
318endif
319
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100320# Call the generic package infrastructure to generate the necessary
321# make targets
Thomas De Schampheleire26aef882014-02-05 10:44:03 +0100322$(call inner-generic-package,$(1),$(2),$(3),$(4))
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100323
324endef
325
326################################################################################
Arnout Vandecappelle (Essensium/Mind)46fa5cb2012-07-03 00:07:08 +0200327# autotools-package -- the target generator macro for autotools packages
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100328################################################################################
329
Thomas De Schampheleire26aef882014-02-05 10:44:03 +0100330autotools-package = $(call inner-autotools-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
331host-autotools-package = $(call inner-autotools-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)