pkg-autotools.mk 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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)_DIR) -name ltmain.sh`; do \
  58. ltmain_version=`sed -n '/^[ \t]*VERSION=/{s/^[ \t]*VERSION=//;p;q;}' $$i | \
  59. sed -e 's/\([0-9]*\.[0-9]*\).*/\1/' -e 's/\"//'`; \
  60. ltmain_patchlevel=`sed -n '/^[ \t]*VERSION=/{s/^[ \t]*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. patch -i support/libtool/buildroot-libtool-v1.5.patch $${i}; \
  64. elif test $${ltmain_version} = "2.2"; then\
  65. patch -i support/libtool/buildroot-libtool-v2.2.patch $${i}; \
  66. elif test $${ltmain_version} = "2.4"; then\
  67. if test $${ltmain_patchlevel:-0} -gt 2; then\
  68. patch -i support/libtool/buildroot-libtool-v2.4.4.patch $${i}; \
  69. else \
  70. patch -i support/libtool/buildroot-libtool-v2.4.patch $${i}; \
  71. fi \
  72. fi \
  73. done
  74. endef
  75. #
  76. # Hook to patch common issue with configure on powerpc64{,le} failing
  77. # to detect shared library support:
  78. #
  79. define CONFIGURE_FIX_POWERPC64_HOOK
  80. @$(call MESSAGE,"Checking configure (powerpc64/powerpc64le)")
  81. support/scripts/fix-configure-powerpc64.sh $($(PKG)_DIR)
  82. endef
  83. #
  84. # Hook to gettextize the package if needed
  85. #
  86. define GETTEXTIZE_HOOK
  87. @$(call MESSAGE,"Gettextizing")
  88. $(Q)cd $($(PKG)_SRCDIR) && $(GETTEXTIZE) $($(PKG)_GETTEXTIZE_OPTS)
  89. endef
  90. #
  91. # Hook to autoreconf the package if needed
  92. #
  93. define AUTORECONF_HOOK
  94. @$(call MESSAGE,"Autoreconfiguring")
  95. $(Q)cd $($(PKG)_SRCDIR) && $($(PKG)_AUTORECONF_ENV) $(AUTORECONF) $($(PKG)_AUTORECONF_OPTS)
  96. endef
  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. define inner-autotools-package
  112. ifndef $(2)_LIBTOOL_PATCH
  113. ifdef $(3)_LIBTOOL_PATCH
  114. $(2)_LIBTOOL_PATCH = $$($(3)_LIBTOOL_PATCH)
  115. else
  116. $(2)_LIBTOOL_PATCH ?= YES
  117. endif
  118. endif
  119. ifndef $(2)_MAKE
  120. ifdef $(3)_MAKE
  121. $(2)_MAKE = $$($(3)_MAKE)
  122. else
  123. $(2)_MAKE ?= $$(MAKE)
  124. endif
  125. endif
  126. ifndef $(2)_AUTORECONF
  127. ifdef $(3)_AUTORECONF
  128. $(2)_AUTORECONF = $$($(3)_AUTORECONF)
  129. else
  130. $(2)_AUTORECONF ?= NO
  131. endif
  132. endif
  133. ifndef $(2)_GETTEXTIZE
  134. ifdef $(3)_GETTEXTIZE
  135. $(2)_GETTEXTIZE = $$($(3)_GETTEXTIZE)
  136. else
  137. $(2)_GETTEXTIZE ?= NO
  138. endif
  139. endif
  140. ifeq ($(4),host)
  141. $(2)_GETTEXTIZE_OPTS ?= $$($(3)_GETTEXTIZE_OPTS)
  142. endif
  143. ifeq ($(4),host)
  144. $(2)_AUTORECONF_OPTS ?= $$($(3)_AUTORECONF_OPTS)
  145. endif
  146. $(2)_CONF_ENV ?=
  147. $(2)_CONF_OPTS ?=
  148. $(2)_MAKE_ENV ?=
  149. $(2)_MAKE_OPTS ?=
  150. $(2)_INSTALL_OPTS ?= install
  151. $(2)_INSTALL_STAGING_OPTS ?= DESTDIR=$$(STAGING_DIR) install
  152. $(2)_INSTALL_TARGET_OPTS ?= DESTDIR=$$(TARGET_DIR) install
  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-gtk-doc-html \
  178. --disable-doc \
  179. --disable-docs \
  180. --disable-documentation \
  181. --with-xmlto=no \
  182. --with-fop=no \
  183. $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
  184. --enable-ipv6 \
  185. $$(NLS_OPTS) \
  186. $$(SHARED_STATIC_LIBS_OPTS) \
  187. $$(QUIET) $$($$(PKG)_CONF_OPTS) \
  188. )
  189. endef
  190. else
  191. # Configure package for host
  192. # disable all kind of documentation generation in the process,
  193. # because it often relies on host tools which may or may not be
  194. # installed.
  195. define $(2)_CONFIGURE_CMDS
  196. (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \
  197. $$(HOST_CONFIGURE_OPTS) \
  198. CFLAGS="$$(HOST_CFLAGS)" \
  199. LDFLAGS="$$(HOST_LDFLAGS)" \
  200. $$($$(PKG)_CONF_ENV) \
  201. CONFIG_SITE=/dev/null \
  202. ./configure \
  203. --prefix="$$(HOST_DIR)" \
  204. --sysconfdir="$$(HOST_DIR)/etc" \
  205. --localstatedir="$$(HOST_DIR)/var" \
  206. --enable-shared --disable-static \
  207. --disable-gtk-doc \
  208. --disable-gtk-doc-html \
  209. --disable-doc \
  210. --disable-docs \
  211. --disable-documentation \
  212. --disable-debug \
  213. --with-xmlto=no \
  214. --with-fop=no \
  215. --disable-nls \
  216. $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
  217. $$(QUIET) $$($$(PKG)_CONF_OPTS) \
  218. )
  219. endef
  220. endif
  221. endif
  222. $(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK
  223. ifeq ($$($(2)_AUTORECONF),YES)
  224. # This has to come before autoreconf
  225. ifeq ($$($(2)_GETTEXTIZE),YES)
  226. $(2)_PRE_CONFIGURE_HOOKS += GETTEXTIZE_HOOK
  227. $(2)_DEPENDENCIES += host-gettext
  228. endif
  229. $(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
  230. # default values are not evaluated yet, so don't rely on this defaulting to YES
  231. ifneq ($$($(2)_LIBTOOL_PATCH),NO)
  232. $(2)_PRE_CONFIGURE_HOOKS += LIBTOOL_PATCH_HOOK
  233. endif
  234. $(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
  235. else # ! AUTORECONF = YES
  236. # default values are not evaluated yet, so don't rely on this defaulting to YES
  237. ifneq ($$($(2)_LIBTOOL_PATCH),NO)
  238. $(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK
  239. endif
  240. endif
  241. # Append a configure hook if building for a powerpc64 (or powerpc64le) arch.
  242. # Must be added after other pre-configure hooks that might regenerate the
  243. # configure script and overwrite the changes made here.
  244. ifneq ($$(filter powerpc64%,$$(if $$(filter target,$(4)),$$(ARCH),$$(HOSTARCH))),)
  245. $(2)_PRE_CONFIGURE_HOOKS += CONFIGURE_FIX_POWERPC64_HOOK
  246. endif
  247. #
  248. # Build step. Only define it if not already defined by the package .mk
  249. # file.
  250. #
  251. ifndef $(2)_BUILD_CMDS
  252. ifeq ($(4),target)
  253. define $(2)_BUILD_CMDS
  254. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
  255. endef
  256. else
  257. define $(2)_BUILD_CMDS
  258. $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
  259. endef
  260. endif
  261. endif
  262. #
  263. # Host installation step. Only define it if not already defined by the
  264. # package .mk file.
  265. #
  266. ifndef $(2)_INSTALL_CMDS
  267. define $(2)_INSTALL_CMDS
  268. $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_SRCDIR)
  269. endef
  270. endif
  271. #
  272. # Staging installation step. Only define it if not already defined by
  273. # the package .mk file.
  274. #
  275. ifndef $(2)_INSTALL_STAGING_CMDS
  276. define $(2)_INSTALL_STAGING_CMDS
  277. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_SRCDIR)
  278. endef
  279. endif
  280. #
  281. # Target installation step. Only define it if not already defined by
  282. # the package .mk file.
  283. #
  284. ifndef $(2)_INSTALL_TARGET_CMDS
  285. define $(2)_INSTALL_TARGET_CMDS
  286. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_SRCDIR)
  287. endef
  288. endif
  289. # Call the generic package infrastructure to generate the necessary
  290. # make targets
  291. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  292. endef
  293. ################################################################################
  294. # autotools-package -- the target generator macro for autotools packages
  295. ################################################################################
  296. autotools-package = $(call inner-autotools-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  297. host-autotools-package = $(call inner-autotools-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)