pkg-autotools.mk 11 KB

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