1################################################################################
2# Autotools package infrastructure
3#
4# 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.
7#
8# See the Buildroot documentation for details on the usage of this
9# infrastructure
10#
11# In terms of implementation, this autotools infrastructure requires
12# the .mk file to only specify metadata information about the
13# package: name, version, download URL, etc.
14#
15# 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.
20#
21################################################################################
22
23
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
39# 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
49#
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
61	@$(call MESSAGE,"Patching libtool")
62	$(Q)for i in `find $($(PKG)_DIR) -name ltmain.sh`; do \
63		ltmain_version=`sed -n '/^[ \t]*VERSION=/{s/^[ \t]*VERSION=//;p;q;}' $$i | \
64		sed -e 's/\([0-9]*\.[0-9]*\).*/\1/' -e 's/\"//'`; \
65		ltmain_patchlevel=`sed -n '/^[ \t]*VERSION=/{s/^[ \t]*VERSION=//;p;q;}' $$i | \
66		sed -e 's/\([0-9]*\.[0-9]*\.*\)\([0-9]*\).*/\2/' -e 's/\"//'`; \
67		if test $${ltmain_version} = '1.5'; then \
68			patch -i support/libtool/buildroot-libtool-v1.5.patch $${i}; \
69		elif test $${ltmain_version} = "2.2"; then\
70			patch -i support/libtool/buildroot-libtool-v2.2.patch $${i}; \
71		elif test $${ltmain_version} = "2.4"; then\
72			if test $${ltmain_patchlevel:-0} -gt 2; then\
73				patch -i support/libtool/buildroot-libtool-v2.4.4.patch $${i}; \
74			else \
75				patch -i support/libtool/buildroot-libtool-v2.4.patch $${i}; \
76			fi \
77		fi \
78	done
79endef
80
81#
82# 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#
91# Hook to autoreconf the package if needed
92#
93define AUTORECONF_HOOK
94	@$(call MESSAGE,"Autoreconfiguring")
95	$(Q)cd $($(PKG)_SRCDIR) && $($(PKG)_AUTORECONF_ENV) $(AUTORECONF) $($(PKG)_AUTORECONF_OPTS)
96endef
97
98################################################################################
99# inner-autotools-package -- defines how the configuration, compilation and
100# installation of an autotools package should be done, implements a
101# few hooks to tune the build process for autotools specifities and
102# calls the generic package infrastructure to generate the necessary
103# make targets
104#
105#  argument 1 is the lowercase package name
106#  argument 2 is the uppercase package name, including a HOST_ prefix
107#             for host packages
108#  argument 3 is the uppercase package name, without the HOST_ prefix
109#             for host packages
110#  argument 4 is the type (target or host)
111################################################################################
112
113define inner-autotools-package
114
115ifndef $(2)_LIBTOOL_PATCH
116 ifdef $(3)_LIBTOOL_PATCH
117  $(2)_LIBTOOL_PATCH = $$($(3)_LIBTOOL_PATCH)
118 else
119  $(2)_LIBTOOL_PATCH ?= YES
120 endif
121endif
122
123ifndef $(2)_MAKE
124 ifdef $(3)_MAKE
125  $(2)_MAKE = $$($(3)_MAKE)
126 else
127  $(2)_MAKE ?= $$(MAKE)
128 endif
129endif
130
131ifndef $(2)_AUTORECONF
132 ifdef $(3)_AUTORECONF
133  $(2)_AUTORECONF = $$($(3)_AUTORECONF)
134 else
135  $(2)_AUTORECONF ?= NO
136 endif
137endif
138
139ifndef $(2)_AUTOPOINT
140 ifdef $(3)_AUTOPOINT
141  $(2)_AUTOPOINT = $$($(3)_AUTOPOINT)
142 else
143  $(2)_AUTOPOINT ?= NO
144 endif
145endif
146
147
148ifeq ($(4),host)
149 $(2)_AUTORECONF_OPTS ?= $$($(3)_AUTORECONF_OPTS)
150endif
151
152$(2)_INSTALL_OPTS                ?= install
153$(2)_INSTALL_STAGING_OPTS	?= DESTDIR=$$(STAGING_DIR) install
154$(2)_INSTALL_TARGET_OPTS		?= DESTDIR=$$(TARGET_DIR) install
155
156#
157# Configure step. Only define it if not already defined by the package
158# .mk file. And take care of the differences between host and target
159# packages.
160#
161ifndef $(2)_CONFIGURE_CMDS
162ifeq ($(4),target)
163
164# Configure package for target
165define $(2)_CONFIGURE_CMDS
166	(cd $$($$(PKG)_SRCDIR) && rm -rf config.cache && \
167	$$(TARGET_CONFIGURE_OPTS) \
168	$$(TARGET_CONFIGURE_ARGS) \
169	$$($$(PKG)_CONF_ENV) \
170	CONFIG_SITE=/dev/null \
171	./configure \
172		--target=$$(GNU_TARGET_NAME) \
173		--host=$$(GNU_TARGET_NAME) \
174		--build=$$(GNU_HOST_NAME) \
175		--prefix=/usr \
176		--exec-prefix=/usr \
177		--sysconfdir=/etc \
178		--localstatedir=/var \
179		--program-prefix="" \
180		--disable-gtk-doc \
181		--disable-gtk-doc-html \
182		--disable-doc \
183		--disable-docs \
184		--disable-documentation \
185		--with-xmlto=no \
186		--with-fop=no \
187		$$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
188		--enable-ipv6 \
189		$$(NLS_OPTS) \
190		$$(SHARED_STATIC_LIBS_OPTS) \
191		$$(QUIET) $$($$(PKG)_CONF_OPTS) \
192	)
193endef
194else
195
196# Configure package for host
197# disable all kind of documentation generation in the process,
198# because it often relies on host tools which may or may not be
199# installed.
200define $(2)_CONFIGURE_CMDS
201	(cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \
202	$$(HOST_CONFIGURE_OPTS) \
203	CFLAGS="$$(HOST_CFLAGS)" \
204	LDFLAGS="$$(HOST_LDFLAGS)" \
205	$$($$(PKG)_CONF_ENV) \
206	CONFIG_SITE=/dev/null \
207	./configure \
208		--prefix="$$(HOST_DIR)" \
209		--sysconfdir="$$(HOST_DIR)/etc" \
210		--localstatedir="$$(HOST_DIR)/var" \
211		--enable-shared --disable-static \
212		--disable-gtk-doc \
213		--disable-gtk-doc-html \
214		--disable-doc \
215		--disable-docs \
216		--disable-documentation \
217		--disable-debug \
218		--with-xmlto=no \
219		--with-fop=no \
220		--disable-nls \
221		$$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
222		$$(QUIET) $$($$(PKG)_CONF_OPTS) \
223	)
224endef
225endif
226endif
227
228$(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK
229
230ifeq ($$($(2)_AUTORECONF),YES)
231
232# autopoint is provided by gettext
233ifeq ($$($(2)_AUTOPOINT),YES)
234$(2)_DEPENDENCIES += host-gettext
235$(2)_AUTORECONF_ENV += AUTOPOINT=$$(HOST_DIR)/bin/autopoint
236else
237$(2)_AUTORECONF_ENV += AUTOPOINT=/bin/true
238endif
239$(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
240# default values are not evaluated yet, so don't rely on this defaulting to YES
241ifneq ($$($(2)_LIBTOOL_PATCH),NO)
242$(2)_PRE_CONFIGURE_HOOKS += LIBTOOL_PATCH_HOOK
243endif
244$(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
245
246else # ! AUTORECONF = YES
247
248# default values are not evaluated yet, so don't rely on this defaulting to YES
249ifneq ($$($(2)_LIBTOOL_PATCH),NO)
250$(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK
251endif
252
253endif
254
255# Append a configure hook if building for a powerpc64 (or powerpc64le) arch.
256# Must be added after other pre-configure hooks that might regenerate the
257# configure script and overwrite the changes made here.
258ifneq ($$(filter powerpc64%,$$(if $$(filter target,$(4)),$$(ARCH),$$(HOSTARCH))),)
259$(2)_PRE_CONFIGURE_HOOKS += CONFIGURE_FIX_POWERPC64_HOOK
260endif
261
262#
263# Build step. Only define it if not already defined by the package .mk
264# file.
265#
266ifndef $(2)_BUILD_CMDS
267ifeq ($(4),target)
268define $(2)_BUILD_CMDS
269	$$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
270endef
271else
272define $(2)_BUILD_CMDS
273	$$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
274endef
275endif
276endif
277
278#
279# Host installation step. Only define it if not already defined by the
280# package .mk file.
281#
282ifndef $(2)_INSTALL_CMDS
283define $(2)_INSTALL_CMDS
284	$$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_SRCDIR)
285endef
286endif
287
288#
289# Staging installation step. Only define it if not already defined by
290# the package .mk file.
291#
292ifndef $(2)_INSTALL_STAGING_CMDS
293define $(2)_INSTALL_STAGING_CMDS
294	$$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_SRCDIR)
295endef
296endif
297
298#
299# Target installation step. Only define it if not already defined by
300# the package .mk file.
301#
302ifndef $(2)_INSTALL_TARGET_CMDS
303define $(2)_INSTALL_TARGET_CMDS
304	$$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_SRCDIR)
305endef
306endif
307
308# Call the generic package infrastructure to generate the necessary
309# make targets
310$(call inner-generic-package,$(1),$(2),$(3),$(4))
311
312endef
313
314################################################################################
315# autotools-package -- the target generator macro for autotools packages
316################################################################################
317
318autotools-package = $(call inner-autotools-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
319host-autotools-package = $(call inner-autotools-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
320