pkg-autotools.mk 11 KB

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