pkg-autotools: move the libtool patching call out of the autoreconf hook
[buildroot-gz.git] / package / pkg-autotools.mk
blob45947b00886a09dc34ea78d513265deb480664a3
1 ################################################################################
2 # Autotools package infrastructure
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.
8 # See the Buildroot documentation for details on the usage of this
9 # infrastructure
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.
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.
21 ################################################################################
25 # Utility function to upgrade config.sub and config.guess files
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.
31 define 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
37 endef
40 # Utility function to patch the libtool files
42 # argument 1 : directory into which to search for libtool scripts to patch.
43 # Note that libtool scripts are searched for recursively in this directory
45 define PATCH_LIBTOOL
46 @$(call MESSAGE,"Patching libtool")
47 $(Q)if test "$($(PKG)_LIBTOOL_PATCH)" = "YES" ]; then \
48 for i in `find $(1) -name ltmain.sh`; do \
49 ltmain_version=`sed -n '/^[ ]*VERSION=/{s/^[ ]*VERSION=//;p;q;}' $$i | \
50 sed -e 's/\([0-9].[0-9]*\).*/\1/' -e 's/\"//'`; \
51 if test $${ltmain_version} = '1.5'; then \
52 $(APPLY_PATCHES) $${i%/*} support/libtool buildroot-libtool-v1.5.patch; \
53 elif test $${ltmain_version} = "2.2"; then\
54 $(APPLY_PATCHES) $${i%/*} support/libtool buildroot-libtool-v2.2.patch; \
55 elif test $${ltmain_version} = "2.4"; then\
56 $(APPLY_PATCHES) $${i%/*} support/libtool buildroot-libtool-v2.4.patch; \
57 fi \
58 done \
60 endef
62 # This function generates the ac_cv_file_<foo> value for a given
63 # filename. This is needed to convince configure script doing
64 # AC_CHECK_FILE() tests that the file actually exists, since such
65 # tests cannot be done in a cross-compilation context. This function
66 # takes as argument the path of the file. An example usage is:
68 # FOOBAR_CONF_ENV = \
69 # $(call AUTOCONF_AC_CHECK_FILE_VAL,/dev/random)=yes
70 AUTOCONF_AC_CHECK_FILE_VAL = ac_cv_file_$(subst -,_,$(subst /,_,$(subst .,_,$(1))))
73 # Hook to update config.sub and config.guess if needed
75 define UPDATE_CONFIG_HOOK
76 @$(call MESSAGE,"Updating config.sub and config.guess")
77 $(call CONFIG_UPDATE,$(@D))
78 endef
81 # Hook to patch libtool to make it work properly for cross-compilation
83 define LIBTOOL_PATCH_HOOK
84 $(call PATCH_LIBTOOL,$($(PKG)_SRCDIR))
85 endef
88 # Hook to gettextize the package if needed
90 define GETTEXTIZE_HOOK
91 @$(call MESSAGE,"Gettextizing")
92 $(Q)cd $($(PKG)_SRCDIR) && $(GETTEXTIZE) $($(PKG)_GETTEXTIZE_OPTS)
93 endef
96 # Hook to autoreconf the package if needed
98 define AUTORECONF_HOOK
99 @$(call MESSAGE,"Autoreconfiguring")
100 $(Q)cd $($(PKG)_SRCDIR) && $($(PKG)_AUTORECONF_ENV) $(AUTORECONF) $($(PKG)_AUTORECONF_OPTS)
101 endef
103 ################################################################################
104 # inner-autotools-package -- defines how the configuration, compilation and
105 # installation of an autotools package should be done, implements a
106 # few hooks to tune the build process for autotools specifities and
107 # calls the generic package infrastructure to generate the necessary
108 # make targets
110 # argument 1 is the lowercase package name
111 # argument 2 is the uppercase package name, including a HOST_ prefix
112 # for host packages
113 # argument 3 is the uppercase package name, without the HOST_ prefix
114 # for host packages
115 # argument 4 is the type (target or host)
116 ################################################################################
118 define inner-autotools-package
120 ifndef $(2)_LIBTOOL_PATCH
121 ifdef $(3)_LIBTOOL_PATCH
122 $(2)_LIBTOOL_PATCH = $$($(3)_LIBTOOL_PATCH)
123 else
124 $(2)_LIBTOOL_PATCH ?= YES
125 endif
126 endif
128 ifndef $(2)_MAKE
129 ifdef $(3)_MAKE
130 $(2)_MAKE = $$($(3)_MAKE)
131 else
132 $(2)_MAKE ?= $$(MAKE)
133 endif
134 endif
136 ifndef $(2)_AUTORECONF
137 ifdef $(3)_AUTORECONF
138 $(2)_AUTORECONF = $$($(3)_AUTORECONF)
139 else
140 $(2)_AUTORECONF ?= NO
141 endif
142 endif
144 ifndef $(2)_GETTEXTIZE
145 ifdef $(3)_GETTEXTIZE
146 $(2)_GETTEXTIZE = $$($(3)_GETTEXTIZE)
147 else
148 $(2)_GETTEXTIZE ?= NO
149 endif
150 endif
152 ifeq ($(4),host)
153 $(2)_GETTEXTIZE_OPTS ?= $$($(3)_GETTEXTIZE_OPTS)
154 endif
156 ifeq ($(4),host)
157 $(2)_AUTORECONF_OPTS ?= $$($(3)_AUTORECONF_OPTS)
158 endif
160 $(2)_CONF_ENV ?=
161 $(2)_CONF_OPTS ?=
162 $(2)_MAKE_ENV ?=
163 $(2)_MAKE_OPTS ?=
164 $(2)_INSTALL_OPTS ?= install
165 $(2)_INSTALL_STAGING_OPTS ?= DESTDIR=$$(STAGING_DIR) install
166 $(2)_INSTALL_TARGET_OPTS ?= DESTDIR=$$(TARGET_DIR) install
168 # This must be repeated from inner-generic-package, otherwise we get an empty
169 # _DEPENDENCIES if _AUTORECONF is YES. Also filter the result of _AUTORECONF
170 # and _GETTEXTIZE away from the non-host rule
171 ifeq ($(4),host)
172 $(2)_DEPENDENCIES ?= $$(filter-out host-automake host-autoconf host-libtool \
173 host-gettext host-toolchain $(1),\
174 $$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
175 endif
178 # Configure step. Only define it if not already defined by the package
179 # .mk file. And take care of the differences between host and target
180 # packages.
182 ifndef $(2)_CONFIGURE_CMDS
183 ifeq ($(4),target)
185 # Configure package for target
186 define $(2)_CONFIGURE_CMDS
187 (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache && \
188 $$(TARGET_CONFIGURE_OPTS) \
189 $$(TARGET_CONFIGURE_ARGS) \
190 $$($$(PKG)_CONF_ENV) \
191 CONFIG_SITE=/dev/null \
192 ./configure \
193 --target=$$(GNU_TARGET_NAME) \
194 --host=$$(GNU_TARGET_NAME) \
195 --build=$$(GNU_HOST_NAME) \
196 --prefix=/usr \
197 --exec-prefix=/usr \
198 --sysconfdir=/etc \
199 --localstatedir=/var \
200 --program-prefix="" \
201 --disable-gtk-doc \
202 --disable-doc \
203 --disable-docs \
204 --disable-documentation \
205 --with-xmlto=no \
206 --with-fop=no \
207 --disable-dependency-tracking \
208 $$(DISABLE_NLS) \
209 $$(DISABLE_LARGEFILE) \
210 $$(DISABLE_IPV6) \
211 $$(ENABLE_DEBUG) \
212 $$(SHARED_STATIC_LIBS_OPTS) \
213 $$(QUIET) $$($$(PKG)_CONF_OPTS) \
215 endef
216 else
218 # Configure package for host
219 # disable all kind of documentation generation in the process,
220 # because it often relies on host tools which may or may not be
221 # installed.
222 define $(2)_CONFIGURE_CMDS
223 (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \
224 $$(HOST_CONFIGURE_OPTS) \
225 CFLAGS="$$(HOST_CFLAGS)" \
226 LDFLAGS="$$(HOST_LDFLAGS)" \
227 $$($$(PKG)_CONF_ENV) \
228 CONFIG_SITE=/dev/null \
229 ./configure \
230 --prefix="$$(HOST_DIR)/usr" \
231 --sysconfdir="$$(HOST_DIR)/etc" \
232 --localstatedir="$$(HOST_DIR)/var" \
233 --enable-shared --disable-static \
234 --disable-gtk-doc \
235 --disable-doc \
236 --disable-docs \
237 --disable-documentation \
238 --disable-debug \
239 --with-xmlto=no \
240 --with-fop=no \
241 --disable-dependency-tracking \
242 $$(QUIET) $$($$(PKG)_CONF_OPTS) \
244 endef
245 endif
246 endif
248 $(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK
250 # default values are not evaluated yet, so don't rely on this defaulting to YES
251 ifneq ($$($(2)_LIBTOOL_PATCH),NO)
252 $(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK
253 endif
255 ifeq ($$($(2)_AUTORECONF),YES)
256 # This has to come before autoreconf
257 ifeq ($$($(2)_GETTEXTIZE),YES)
258 $(2)_PRE_CONFIGURE_HOOKS += GETTEXTIZE_HOOK
259 $(2)_DEPENDENCIES += host-gettext
260 endif
261 $(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
262 # default values are not evaluated yet, so don't rely on this defaulting to YES
263 ifneq ($$($(2)_LIBTOOL_PATCH),NO)
264 $(2)_PRE_CONFIGURE_HOOKS += LIBTOOL_PATCH_HOOK
265 endif
266 $(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
267 endif
270 # Build step. Only define it if not already defined by the package .mk
271 # file.
273 ifndef $(2)_BUILD_CMDS
274 ifeq ($(4),target)
275 define $(2)_BUILD_CMDS
276 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
277 endef
278 else
279 define $(2)_BUILD_CMDS
280 $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
281 endef
282 endif
283 endif
286 # Host installation step. Only define it if not already defined by the
287 # package .mk file.
289 ifndef $(2)_INSTALL_CMDS
290 define $(2)_INSTALL_CMDS
291 $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_SRCDIR)
292 endef
293 endif
296 # Staging installation step. Only define it if not already defined by
297 # the package .mk file.
299 # Most autotools packages install libtool .la files alongside any
300 # installed libraries. These .la files sometimes refer to paths
301 # relative to the sysroot, which libtool will interpret as absolute
302 # paths to host libraries instead of the target libraries. Since this
303 # is not what we want, these paths are fixed by prefixing them with
304 # $(STAGING_DIR). As we configure with --prefix=/usr, this fix
305 # needs to be applied to any path that starts with /usr.
307 # To protect against the case that the output or staging directories
308 # themselves are under /usr, we first substitute away any occurrences
309 # of these directories as @BASE_DIR@ and @STAGING_DIR@. Note that
310 # STAGING_DIR can be outside BASE_DIR when the user sets BR2_HOST_DIR
311 # to a custom value.
313 ifndef $(2)_INSTALL_STAGING_CMDS
314 define $(2)_INSTALL_STAGING_CMDS
315 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_SRCDIR)
316 find $$(STAGING_DIR)/usr/lib* -name "*.la" | xargs --no-run-if-empty \
317 $$(SED) "s:$$(BASE_DIR):@BASE_DIR@:g" \
318 -e "s:$$(STAGING_DIR):@STAGING_DIR@:g" \
319 -e "s:\(['= ]\)/usr:\\1@STAGING_DIR@/usr:g" \
320 -e "s:@STAGING_DIR@:$$(STAGING_DIR):g" \
321 -e "s:@BASE_DIR@:$$(BASE_DIR):g"
322 endef
323 endif
326 # Target installation step. Only define it if not already defined by
327 # the package .mk file.
329 ifndef $(2)_INSTALL_TARGET_CMDS
330 define $(2)_INSTALL_TARGET_CMDS
331 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_SRCDIR)
332 endef
333 endif
335 # Call the generic package infrastructure to generate the necessary
336 # make targets
337 $(call inner-generic-package,$(1),$(2),$(3),$(4))
339 endef
341 ################################################################################
342 # autotools-package -- the target generator macro for autotools packages
343 ################################################################################
345 autotools-package = $(call inner-autotools-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
346 host-autotools-package = $(call inner-autotools-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)