blob: 13947873a0c4d3a1d35518ff8134b6a99f100f0a [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
6# packages that use the autotools as their build system. Non-autotools
7# packages should use the generic infrastructure in
8# package/Makefile.package.in.
Eric Andersena7e49eb2007-08-10 19:07:51 +00009#
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010010# See the Buildroot documentation for details on the usage of this
11# infrastructure
Eric Andersena7e49eb2007-08-10 19:07:51 +000012#
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010013# In terms of implementation, this autotools infrastructure requires
14# the .mk file to only specify metadata informations about the
15# package: name, version, download URL, etc.
Bernhard Reutner-Fischer00b84562007-09-30 12:46:02 +000016#
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010017# We still allow the package .mk file to override what the different
18# steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
19# already defined, it is used as the list of commands to perform to
20# build the package, instead of the default autotools behaviour. The
21# package can also define some post operation hooks.
Bernhard Reutner-Fischer00b84562007-09-30 12:46:02 +000022#
Eric Andersena7e49eb2007-08-10 19:07:51 +000023################################################################################
24
Thomas Petazzoni102a93b2011-08-31 23:35:06 +020025
26#
27# Utility function to upgrade config.sub and config.guess files
28#
29# argument 1 : directory into which config.guess and config.sub need
30# to be updated. Note that config.sub and config.guess are searched
31# recursively in this directory.
32#
33define CONFIG_UPDATE
34 for file in config.guess config.sub; do \
35 for i in $$(find $(1) -name $$file); do \
36 cp support/gnuconfig/$$file $$i; \
37 done; \
38 done
39endef
40
Peter Korsgaardd58636d2009-01-16 10:27:48 +000041################################################################################
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010042# AUTOTARGETS_INNER -- defines how the configuration, compilation and
43# installation of an autotools package should be done, implements a
44# few hooks to tune the build process for autotools specifities and
45# calls the generic package infrastructure to generate the necessary
46# make targets
Peter Korsgaardd58636d2009-01-16 10:27:48 +000047#
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010048# argument 1 is the lowercase package name
49# argument 2 is the uppercase package name, including an HOST_ prefix
50# for host packages
51# argument 3 is the uppercase package name, without the HOST_ prefix
52# for host packages
53# argument 4 is the package directory prefix
54# argument 5 is the type (target or host)
Peter Korsgaardd58636d2009-01-16 10:27:48 +000055################################################################################
56
Eric Andersena7e49eb2007-08-10 19:07:51 +000057define AUTOTARGETS_INNER
58
59# define package-specific variables to default values
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010060ifndef $(2)_SUBDIR
61 ifdef $(3)_SUBDIR
62 $(2)_SUBDIR = $($(3)_SUBDIR)
63 else
64 $(2)_SUBDIR ?=
65 endif
66endif
67
Thomas Petazzonid2c73f52010-04-28 23:40:45 +020068ifndef $(2)_LIBTOOL_PATCH
69 ifdef $(3)_LIBTOOL_PATCH
70 $(2)_LIBTOOL_PATCH = $($(3)_LIBTOOL_PATCH)
71 else
72 $(2)_LIBTOOL_PATCH ?= YES
73 endif
74endif
75
Peter Korsgaardce1ae872011-05-17 10:00:01 +020076ifndef $(2)_MAKE
77 ifdef $(3)_MAKE
78 $(2)_MAKE = $($(3)_MAKE)
79 else
80 $(2)_MAKE ?= $(MAKE)
81 endif
82endif
83
Eric Andersena7e49eb2007-08-10 19:07:51 +000084$(2)_CONF_ENV ?=
85$(2)_CONF_OPT ?=
Bernhard Reutner-Fischer00b84562007-09-30 12:46:02 +000086$(2)_MAKE_ENV ?=
Eric Andersena7e49eb2007-08-10 19:07:51 +000087$(2)_MAKE_OPT ?=
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010088$(2)_AUTORECONF ?= NO
89$(2)_AUTORECONF_OPT ?=
Eric Andersena7e49eb2007-08-10 19:07:51 +000090$(2)_INSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) install
Paulius Zaleckas31365de2010-03-30 17:20:55 +020091$(2)_INSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) install
Eric Andersena7e49eb2007-08-10 19:07:51 +000092$(2)_CLEAN_OPT ?= clean
93$(2)_UNINSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) uninstall
94$(2)_UNINSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) uninstall
Eric Andersena7e49eb2007-08-10 19:07:51 +000095
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010096$(2)_SRCDIR = $$($(2)_DIR)/$($(2)_SUBDIR)
Eric Andersena7e49eb2007-08-10 19:07:51 +000097
Thomas Petazzonid8b55b92009-11-08 18:37:49 +010098#
99# Configure step. Only define it if not already defined by the package
100# .mk file. And take care of the differences between host and target
101# packages.
102#
103ifndef $(2)_CONFIGURE_CMDS
104ifeq ($(5),target)
Eric Andersena7e49eb2007-08-10 19:07:51 +0000105
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100106# Configure package for target
107define $(2)_CONFIGURE_CMDS
108 (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache && \
109 $$(TARGET_CONFIGURE_OPTS) \
110 $$(TARGET_CONFIGURE_ARGS) \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100111 $$($$(PKG)_CONF_ENV) \
112 ./configure \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100113 --target=$$(GNU_TARGET_NAME) \
114 --host=$$(GNU_TARGET_NAME) \
115 --build=$$(GNU_HOST_NAME) \
116 --prefix=/usr \
117 --exec-prefix=/usr \
118 --sysconfdir=/etc \
Yann E. MORINa8d6e2c2011-08-10 00:12:34 +0200119 --program-prefix="" \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100120 $$(DISABLE_DOCUMENTATION) \
121 $$(DISABLE_NLS) \
122 $$(DISABLE_LARGEFILE) \
123 $$(DISABLE_IPV6) \
Thomas Petazzoni009d8fc2011-05-30 23:57:02 +0200124 $$(SHARED_STATIC_LIBS_OPTS) \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100125 $$(QUIET) $$($$(PKG)_CONF_OPT) \
126 )
127endef
Eric Andersena7e49eb2007-08-10 19:07:51 +0000128else
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100129
130# Configure package for host
131define $(2)_CONFIGURE_CMDS
132 (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \
133 $$(HOST_CONFIGURE_OPTS) \
134 CFLAGS="$$(HOST_CFLAGS)" \
135 LDFLAGS="$$(HOST_LDFLAGS)" \
Lionel Landwerlin1b41e322010-04-30 02:24:09 +0200136 $$($$(PKG)_CONF_ENV) \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100137 ./configure \
138 --prefix="$$(HOST_DIR)/usr" \
139 --sysconfdir="$$(HOST_DIR)/etc" \
Thomas Petazzoni009d8fc2011-05-30 23:57:02 +0200140 --enable-shared --disable-static \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100141 $$($$(PKG)_CONF_OPT) \
142 )
143endef
144endif
Eric Andersena7e49eb2007-08-10 19:07:51 +0000145endif
146
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100147#
148# Hook to update config.sub and config.guess if needed
149#
150define UPDATE_CONFIG_HOOK
Thomas Petazzoni102a93b2011-08-31 23:35:06 +0200151 @$$(call MESSAGE, "Updating config.sub and config.guess")
152 $$(call CONFIG_UPDATE,$$(@D))
Eric Andersena7e49eb2007-08-10 19:07:51 +0000153endef
154
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100155$(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100156
157#
158# Hook to patch libtool to make it work properly for cross-compilation
159#
160define LIBTOOL_PATCH_HOOK
Lionel Landwerline1317732010-11-04 03:50:22 +0100161 @$$(call MESSAGE,"Patching libtool")
Martin Banky83af8222010-10-09 12:52:49 +0200162 $(Q)if test "$$($$(PKG)_LIBTOOL_PATCH)" = "YES" \
163 -a "$$($$(PKG)_AUTORECONF)" != "YES"; then \
164 for i in `find $$($$(PKG)_SRCDIR) -name ltmain.sh`; do \
165 ltmain_version=`sed -n '/^[ ]*VERSION=/{s/^[ ]*VERSION=//;p;q;}' $$$$i | \
166 sed -e 's/\([0-9].[0-9]*\).*/\1/' -e 's/\"//'`; \
167 if test $$$${ltmain_version} = '1.5'; then \
Thomas Petazzoni59a326b2011-08-31 23:35:04 +0200168 support/scripts/apply-patches.sh $$$${i%/*} support/libtool buildroot-libtool-v1.5.patch; \
Martin Banky83af8222010-10-09 12:52:49 +0200169 elif test $$$${ltmain_version} = "2.2"; then\
Thomas Petazzoni59a326b2011-08-31 23:35:04 +0200170 support/scripts/apply-patches.sh $$$${i%/*} support/libtool buildroot-libtool-v2.2.patch; \
Peter Korsgaardf055b262011-03-28 21:45:06 +0200171 elif test $$$${ltmain_version} = "2.4"; then\
Thomas Petazzoni59a326b2011-08-31 23:35:04 +0200172 support/scripts/apply-patches.sh $$$${i%/*} support/libtool buildroot-libtool-v2.4.patch; \
Martin Banky83af8222010-10-09 12:52:49 +0200173 fi \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100174 done \
175 fi
176endef
177
Peter Korsgaard073af422009-12-30 13:42:01 +0100178# default values are not evaluated yet, so don't rely on this defaulting to YES
Thomas Petazzoni87d0af92010-04-28 23:40:47 +0200179ifneq ($$($(2)_LIBTOOL_PATCH),NO)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100180$(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK
181endif
182
183#
184# Hook to autoreconf the package if needed
185#
186define AUTORECONF_HOOK
Lionel Landwerline1317732010-11-04 03:50:22 +0100187 @$$(call MESSAGE,"Autoreconfiguring")
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100188 $(Q)cd $$($$(PKG)_SRCDIR) && $(AUTORECONF) $$($$(PKG)_AUTORECONF_OPT)
Martin Banky83af8222010-10-09 12:52:49 +0200189 $(Q)if test "$$($$(PKG)_LIBTOOL_PATCH)" = "YES"; then \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100190 for i in `find $$($$(PKG)_SRCDIR) -name ltmain.sh`; do \
Martin Banky83af8222010-10-09 12:52:49 +0200191 ltmain_version=`sed -n '/^[ ]*VERSION=/{s/^[ ]*VERSION=//;p;q;}' $$$$i | sed 's/\([0-9].[0-9]*\).*/\1/'`; \
192 if test $$$${ltmain_version} = "1.5"; then \
Thomas Petazzoni59a326b2011-08-31 23:35:04 +0200193 support/scripts/apply-patches.sh $$$${i%/*} package buildroot-libtool-v1.5.patch; \
Martin Banky83af8222010-10-09 12:52:49 +0200194 elif test $$$${ltmain_version} = "2.2"; then\
Thomas Petazzoni59a326b2011-08-31 23:35:04 +0200195 support/scripts/apply-patches.sh $$$${i%/*} package buildroot-libtool-v2.2.patch; \
Peter Korsgaard3178a202011-05-03 10:01:28 +0200196 elif test $$$${ltmain_version} = "2.4"; then\
Thomas Petazzoni59a326b2011-08-31 23:35:04 +0200197 support/scripts/apply-patches.sh $$$${i%/*} package buildroot-libtool-v2.4.patch; \
Martin Banky83af8222010-10-09 12:52:49 +0200198 fi \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100199 done \
200 fi
201endef
202
Thomas Petazzoni7dfa3b32010-04-28 23:40:42 +0200203ifeq ($$($(2)_AUTORECONF),YES)
Lionel Landwerlin89d1ad92010-11-04 03:50:24 +0100204$(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100205$(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
206endif
207
208#
209# Build step. Only define it if not already defined by the package .mk
210# file.
211#
212ifndef $(2)_BUILD_CMDS
213ifeq ($(5),target)
214define $(2)_BUILD_CMDS
215 $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_SRCDIR)
216endef
217else
218define $(2)_BUILD_CMDS
219 $(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_SRCDIR)
220endef
221endif
222endif
223
224#
225# Host installation step. Only define it if not already defined by the
226# package .mk file.
227#
228ifndef $(2)_INSTALL_CMDS
229define $(2)_INSTALL_CMDS
Thomas Petazzonib06e7ac2011-01-23 17:08:53 +0100230 $(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) -C $$($$(PKG)_SRCDIR) install
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100231endef
232endif
233
234#
235# Staging installation step. Only define it if not already defined by
236# the package .mk file.
237#
238ifndef $(2)_INSTALL_STAGING_CMDS
239define $(2)_INSTALL_STAGING_CMDS
Thomas Petazzoni600d1f82010-12-13 17:27:50 +0100240 $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPT) -C $$($$(PKG)_SRCDIR)
Peter Korsgaardecf59392010-01-18 14:53:06 +0100241 for i in $$$$(find $(STAGING_DIR)/usr/lib* -name "*.la"); do \
Lionel Landwerline8b469b2010-04-30 02:24:06 +0200242 cp -f $$$$i $$$$i~; \
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100243 $$(SED) "s:\(['= ]\)/usr:\\1$(STAGING_DIR)/usr:g" $$$$i; \
244 done
245endef
246endif
247
248#
249# Target installation step. Only define it if not already defined by
250# the package .mk file.
251#
252ifndef $(2)_INSTALL_TARGET_CMDS
253define $(2)_INSTALL_TARGET_CMDS
Thomas Petazzoni600d1f82010-12-13 17:27:50 +0100254 $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPT) -C $$($$(PKG)_SRCDIR)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100255endef
256endif
257
258#
259# Clean step. Only define it if not already defined by
260# the package .mk file.
261#
262ifndef $(2)_CLEAN_CMDS
263define $(2)_CLEAN_CMDS
Thomas Petazzoni600d1f82010-12-13 17:27:50 +0100264 -$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_CLEAN_OPT) -C $$($$(PKG)_SRCDIR)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100265endef
266endif
267
268#
269# Uninstall from staging step. Only define it if not already defined by
270# the package .mk file.
271#
272ifndef $(2)_UNINSTALL_STAGING_CMDS
273define $(2)_UNINSTALL_STAGING_CMDS
Thomas Petazzoni600d1f82010-12-13 17:27:50 +0100274 $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_UNINSTALL_STAGING_OPT) -C $$($$(PKG)_SRCDIR)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100275endef
276endif
277
278#
279# Uninstall from target step. Only define it if not already defined
280# by the package .mk file.
281#
282ifndef $(2)_UNINSTALL_TARGET_CMDS
283define $(2)_UNINSTALL_TARGET_CMDS
Thomas Petazzoni600d1f82010-12-13 17:27:50 +0100284 $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_UNINSTALL_TARGET_OPT) -C $$($$(PKG)_SRCDIR)
Thomas Petazzonid8b55b92009-11-08 18:37:49 +0100285endef
286endif
287
288# Call the generic package infrastructure to generate the necessary
289# make targets
290$(call GENTARGETS_INNER,$(1),$(2),$(3),$(4),$(5))
291
292endef
293
294################################################################################
295# AUTOTARGETS -- the target generator macro for autotools packages
296#
297# Argument 1 is the package directory prefix [mandatory]
298# Argument 2 is the lowercase package name [mandatory]
299# Argument 3 is "target" or "host" [optional, default: "target"]
300################################################################################
301
302define AUTOTARGETS
303ifeq ($(3),host)
304$(call AUTOTARGETS_INNER,$(3)-$(2),$(call UPPERCASE,$(3)-$(2)),$(call UPPERCASE,$(2)),$(1),host)
305else
306$(call AUTOTARGETS_INNER,$(2),$(call UPPERCASE,$(2)),$(call UPPERCASE,$(2)),$(1),target)
307endif
308endef