9dea08aabfa65bffbf3721a32b0782ea7cf9ba54
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / pkg-autotools.mk
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 #
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
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
47 AUTOCONF_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 #
52 define UPDATE_CONFIG_HOOK
53         @$(call MESSAGE,"Updating config.sub and config.guess")
54         $(call CONFIG_UPDATE,$(@D))
55 endef
56
57 #
58 # Hook to patch libtool to make it work properly for cross-compilation
59 #
60 define LIBTOOL_PATCH_HOOK
61         @$(call MESSAGE,"Patching libtool")
62         $(Q)for i in `find $($(PKG)_SRCDIR) -name ltmain.sh`; do \
63                 ltmain_version=`sed -n '/^[     ]*VERSION=/{s/^[        ]*VERSION=//;p;q;}' $$i | \
64                 sed -e 's/\([0-9].[0-9]*\).*/\1/' -e 's/\"//'`; \
65                 ltmain_patchlevel=`sed -n '/^[     ]*VERSION=/{s/^[        ]*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                         $(APPLY_PATCHES) $${i%/*} support/libtool buildroot-libtool-v1.5.patch; \
69                 elif test $${ltmain_version} = "2.2"; then\
70                         $(APPLY_PATCHES) $${i%/*} support/libtool buildroot-libtool-v2.2.patch; \
71                 elif test $${ltmain_version} = "2.4"; then\
72                         if test $${ltmain_patchlevel:-0} -gt 2; then\
73                                 $(APPLY_PATCHES) $${i%/*} support/libtool buildroot-libtool-v2.4.4.patch; \
74                         else \
75                                 $(APPLY_PATCHES) $${i%/*} support/libtool buildroot-libtool-v2.4.patch; \
76                         fi \
77                 fi \
78         done
79 endef
80
81 #
82 # Hook to gettextize the package if needed
83 #
84 define GETTEXTIZE_HOOK
85         @$(call MESSAGE,"Gettextizing")
86         $(Q)cd $($(PKG)_SRCDIR) && $(GETTEXTIZE) $($(PKG)_GETTEXTIZE_OPTS)
87 endef
88
89 #
90 # Hook to autoreconf the package if needed
91 #
92 define AUTORECONF_HOOK
93         @$(call MESSAGE,"Autoreconfiguring")
94         $(Q)cd $($(PKG)_SRCDIR) && $($(PKG)_AUTORECONF_ENV) $(AUTORECONF) $($(PKG)_AUTORECONF_OPTS)
95 endef
96
97 ################################################################################
98 # inner-autotools-package -- defines how the configuration, compilation and
99 # installation of an autotools package should be done, implements a
100 # few hooks to tune the build process for autotools specifities and
101 # calls the generic package infrastructure to generate the necessary
102 # make targets
103 #
104 #  argument 1 is the lowercase package name
105 #  argument 2 is the uppercase package name, including a HOST_ prefix
106 #             for host packages
107 #  argument 3 is the uppercase package name, without the HOST_ prefix
108 #             for host packages
109 #  argument 4 is the type (target or host)
110 ################################################################################
111
112 define inner-autotools-package
113
114 ifndef $(2)_LIBTOOL_PATCH
115  ifdef $(3)_LIBTOOL_PATCH
116   $(2)_LIBTOOL_PATCH = $$($(3)_LIBTOOL_PATCH)
117  else
118   $(2)_LIBTOOL_PATCH ?= YES
119  endif
120 endif
121
122 ifndef $(2)_MAKE
123  ifdef $(3)_MAKE
124   $(2)_MAKE = $$($(3)_MAKE)
125  else
126   $(2)_MAKE ?= $$(MAKE)
127  endif
128 endif
129
130 ifndef $(2)_AUTORECONF
131  ifdef $(3)_AUTORECONF
132   $(2)_AUTORECONF = $$($(3)_AUTORECONF)
133  else
134   $(2)_AUTORECONF ?= NO
135  endif
136 endif
137
138 ifndef $(2)_GETTEXTIZE
139  ifdef $(3)_GETTEXTIZE
140   $(2)_GETTEXTIZE = $$($(3)_GETTEXTIZE)
141  else
142   $(2)_GETTEXTIZE ?= NO
143  endif
144 endif
145
146 ifeq ($(4),host)
147  $(2)_GETTEXTIZE_OPTS ?= $$($(3)_GETTEXTIZE_OPTS)
148 endif
149
150 ifeq ($(4),host)
151  $(2)_AUTORECONF_OPTS ?= $$($(3)_AUTORECONF_OPTS)
152 endif
153
154 $(2)_CONF_ENV                   ?=
155 $(2)_CONF_OPTS                  ?=
156 $(2)_MAKE_ENV                   ?=
157 $(2)_MAKE_OPTS                  ?=
158 $(2)_INSTALL_OPTS                ?= install
159 $(2)_INSTALL_STAGING_OPTS       ?= DESTDIR=$$(STAGING_DIR) install
160 $(2)_INSTALL_TARGET_OPTS                ?= DESTDIR=$$(TARGET_DIR)  install
161
162 # This must be repeated from inner-generic-package, otherwise we get an empty
163 # _DEPENDENCIES if _AUTORECONF is YES.  Also filter the result of _AUTORECONF
164 # and _GETTEXTIZE away from the non-host rule
165 ifeq ($(4),host)
166 $(2)_DEPENDENCIES ?= $$(filter-out host-automake host-autoconf host-libtool \
167                                 host-gettext host-toolchain $(1),\
168     $$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
169 endif
170
171 #
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 #
176 ifndef $(2)_CONFIGURE_CMDS
177 ifeq ($(4),target)
178
179 # Configure package for target
180 define $(2)_CONFIGURE_CMDS
181         (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache && \
182         $$(TARGET_CONFIGURE_OPTS) \
183         $$(TARGET_CONFIGURE_ARGS) \
184         $$($$(PKG)_CONF_ENV) \
185         CONFIG_SITE=/dev/null \
186         ./configure \
187                 --target=$$(GNU_TARGET_NAME) \
188                 --host=$$(GNU_TARGET_NAME) \
189                 --build=$$(GNU_HOST_NAME) \
190                 --prefix=/usr \
191                 --exec-prefix=/usr \
192                 --sysconfdir=/etc \
193                 --localstatedir=/var \
194                 --program-prefix="" \
195                 --disable-gtk-doc \
196                 --disable-gtk-doc-html \
197                 --disable-doc \
198                 --disable-docs \
199                 --disable-documentation \
200                 --with-xmlto=no \
201                 --with-fop=no \
202                 --disable-dependency-tracking \
203                 --enable-ipv6 \
204                 $$(DISABLE_NLS) \
205                 $$(ENABLE_DEBUG) \
206                 $$(SHARED_STATIC_LIBS_OPTS) \
207                 $$(QUIET) $$($$(PKG)_CONF_OPTS) \
208         )
209 endef
210 else
211
212 # Configure package for host
213 # disable all kind of documentation generation in the process,
214 # because it often relies on host tools which may or may not be
215 # installed.
216 define $(2)_CONFIGURE_CMDS
217         (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \
218                 $$(HOST_CONFIGURE_OPTS) \
219                 CFLAGS="$$(HOST_CFLAGS)" \
220                 LDFLAGS="$$(HOST_LDFLAGS)" \
221                 $$($$(PKG)_CONF_ENV) \
222                 CONFIG_SITE=/dev/null \
223                 ./configure \
224                 --prefix="$$(HOST_DIR)/usr" \
225                 --sysconfdir="$$(HOST_DIR)/etc" \
226                 --localstatedir="$$(HOST_DIR)/var" \
227                 --enable-shared --disable-static \
228                 --disable-gtk-doc \
229                 --disable-gtk-doc-html \
230                 --disable-doc \
231                 --disable-docs \
232                 --disable-documentation \
233                 --disable-debug \
234                 --with-xmlto=no \
235                 --with-fop=no \
236                 --disable-dependency-tracking \
237                 $$(QUIET) $$($$(PKG)_CONF_OPTS) \
238         )
239 endef
240 endif
241 endif
242
243 $(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK
244
245 ifeq ($$($(2)_AUTORECONF),YES)
246
247 # This has to come before autoreconf
248 ifeq ($$($(2)_GETTEXTIZE),YES)
249 $(2)_PRE_CONFIGURE_HOOKS += GETTEXTIZE_HOOK
250 $(2)_DEPENDENCIES += host-gettext
251 endif
252 $(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
253 # default values are not evaluated yet, so don't rely on this defaulting to YES
254 ifneq ($$($(2)_LIBTOOL_PATCH),NO)
255 $(2)_PRE_CONFIGURE_HOOKS += LIBTOOL_PATCH_HOOK
256 endif
257 $(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
258
259 else # ! AUTORECONF = YES
260
261 # default values are not evaluated yet, so don't rely on this defaulting to YES
262 ifneq ($$($(2)_LIBTOOL_PATCH),NO)
263 $(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK
264 endif
265
266 endif
267
268 #
269 # Build step. Only define it if not already defined by the package .mk
270 # file.
271 #
272 ifndef $(2)_BUILD_CMDS
273 ifeq ($(4),target)
274 define $(2)_BUILD_CMDS
275         $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
276 endef
277 else
278 define $(2)_BUILD_CMDS
279         $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
280 endef
281 endif
282 endif
283
284 #
285 # Host installation step. Only define it if not already defined by the
286 # package .mk file.
287 #
288 ifndef $(2)_INSTALL_CMDS
289 define $(2)_INSTALL_CMDS
290         $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_SRCDIR)
291 endef
292 endif
293
294 #
295 # Staging installation step. Only define it if not already defined by
296 # the package .mk file.
297 #
298 # Most autotools packages install libtool .la files alongside any
299 # installed libraries. These .la files sometimes refer to paths
300 # relative to the sysroot, which libtool will interpret as absolute
301 # paths to host libraries instead of the target libraries. Since this
302 # is not what we want, these paths are fixed by prefixing them with
303 # $(STAGING_DIR).  As we configure with --prefix=/usr, this fix
304 # needs to be applied to any path that starts with /usr.
305 #
306 # To protect against the case that the output or staging directories
307 # or the pre-installed external toolchain themselves are under /usr,
308 # we first substitute away any occurrences of these directories as
309 # @BASE_DIR@, @STAGING_DIR@ and @TOOLCHAIN_EXTERNAL_INSTALL_DIR@ respectively.
310 # Note that STAGING_DIR can be outside BASE_DIR when the user sets
311 # BR2_HOST_DIR to a custom value. Note that TOOLCHAIN_EXTERNAL_INSTALL_DIR
312 # can be under @BASE_DIR@ when it's a downloaded toolchain, and can be empty
313 # when we use an internal toolchain.
314 #
315 ifndef $(2)_INSTALL_STAGING_CMDS
316 define $(2)_INSTALL_STAGING_CMDS
317         $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_SRCDIR)
318         find $$(STAGING_DIR)/usr/lib* -name "*.la" | xargs --no-run-if-empty \
319                 $$(SED) "s:$$(BASE_DIR):@BASE_DIR@:g" \
320                         -e "s:$$(STAGING_DIR):@STAGING_DIR@:g" \
321                         $$(if $$(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
322                                 -e "s:$$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:g") \
323                         -e "s:\(['= ]\)/usr:\\1@STAGING_DIR@/usr:g" \
324                         $$(if $$(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
325                                 -e "s:@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:$$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):g") \
326                         -e "s:@STAGING_DIR@:$$(STAGING_DIR):g" \
327                         -e "s:@BASE_DIR@:$$(BASE_DIR):g"
328 endef
329 endif
330
331 #
332 # Target installation step. Only define it if not already defined by
333 # the package .mk file.
334 #
335 ifndef $(2)_INSTALL_TARGET_CMDS
336 define $(2)_INSTALL_TARGET_CMDS
337         $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_SRCDIR)
338 endef
339 endif
340
341 # Call the generic package infrastructure to generate the necessary
342 # make targets
343 $(call inner-generic-package,$(1),$(2),$(3),$(4))
344
345 endef
346
347 ################################################################################
348 # autotools-package -- the target generator macro for autotools packages
349 ################################################################################
350
351 autotools-package = $(call inner-autotools-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
352 host-autotools-package = $(call inner-autotools-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)