pkg-autotools.mk 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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)_INSTALL_OPTS ?= install
  147. $(2)_INSTALL_STAGING_OPTS ?= DESTDIR=$$(STAGING_DIR) install
  148. $(2)_INSTALL_TARGET_OPTS ?= DESTDIR=$$(TARGET_DIR) install
  149. #
  150. # Configure step. Only define it if not already defined by the package
  151. # .mk file. And take care of the differences between host and target
  152. # packages.
  153. #
  154. ifndef $(2)_CONFIGURE_CMDS
  155. ifeq ($(4),target)
  156. # Configure package for target
  157. define $(2)_CONFIGURE_CMDS
  158. (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache && \
  159. $$(TARGET_CONFIGURE_OPTS) \
  160. $$(TARGET_CONFIGURE_ARGS) \
  161. $$($$(PKG)_CONF_ENV) \
  162. CONFIG_SITE=/dev/null \
  163. ./configure \
  164. --target=$$(GNU_TARGET_NAME) \
  165. --host=$$(GNU_TARGET_NAME) \
  166. --build=$$(GNU_HOST_NAME) \
  167. --prefix=/usr \
  168. --exec-prefix=/usr \
  169. --sysconfdir=/etc \
  170. --localstatedir=/var \
  171. --program-prefix="" \
  172. --disable-gtk-doc \
  173. --disable-gtk-doc-html \
  174. --disable-doc \
  175. --disable-docs \
  176. --disable-documentation \
  177. --with-xmlto=no \
  178. --with-fop=no \
  179. $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
  180. --enable-ipv6 \
  181. $$(NLS_OPTS) \
  182. $$(SHARED_STATIC_LIBS_OPTS) \
  183. $$(QUIET) $$($$(PKG)_CONF_OPTS) \
  184. )
  185. endef
  186. else
  187. # Configure package for host
  188. # disable all kind of documentation generation in the process,
  189. # because it often relies on host tools which may or may not be
  190. # installed.
  191. define $(2)_CONFIGURE_CMDS
  192. (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \
  193. $$(HOST_CONFIGURE_OPTS) \
  194. CFLAGS="$$(HOST_CFLAGS)" \
  195. LDFLAGS="$$(HOST_LDFLAGS)" \
  196. $$($$(PKG)_CONF_ENV) \
  197. CONFIG_SITE=/dev/null \
  198. ./configure \
  199. --prefix="$$(HOST_DIR)" \
  200. --sysconfdir="$$(HOST_DIR)/etc" \
  201. --localstatedir="$$(HOST_DIR)/var" \
  202. --enable-shared --disable-static \
  203. --disable-gtk-doc \
  204. --disable-gtk-doc-html \
  205. --disable-doc \
  206. --disable-docs \
  207. --disable-documentation \
  208. --disable-debug \
  209. --with-xmlto=no \
  210. --with-fop=no \
  211. --disable-nls \
  212. $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
  213. $$(QUIET) $$($$(PKG)_CONF_OPTS) \
  214. )
  215. endef
  216. endif
  217. endif
  218. $(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK
  219. ifeq ($$($(2)_AUTORECONF),YES)
  220. # This has to come before autoreconf
  221. ifeq ($$($(2)_GETTEXTIZE),YES)
  222. $(2)_PRE_CONFIGURE_HOOKS += GETTEXTIZE_HOOK
  223. $(2)_DEPENDENCIES += host-gettext
  224. endif
  225. $(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
  226. # default values are not evaluated yet, so don't rely on this defaulting to YES
  227. ifneq ($$($(2)_LIBTOOL_PATCH),NO)
  228. $(2)_PRE_CONFIGURE_HOOKS += LIBTOOL_PATCH_HOOK
  229. endif
  230. $(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
  231. else # ! AUTORECONF = YES
  232. # default values are not evaluated yet, so don't rely on this defaulting to YES
  233. ifneq ($$($(2)_LIBTOOL_PATCH),NO)
  234. $(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK
  235. endif
  236. endif
  237. # Append a configure hook if building for a powerpc64 (or powerpc64le) arch.
  238. # Must be added after other pre-configure hooks that might regenerate the
  239. # configure script and overwrite the changes made here.
  240. ifneq ($$(filter powerpc64%,$$(if $$(filter target,$(4)),$$(ARCH),$$(HOSTARCH))),)
  241. $(2)_PRE_CONFIGURE_HOOKS += CONFIGURE_FIX_POWERPC64_HOOK
  242. endif
  243. #
  244. # Build step. Only define it if not already defined by the package .mk
  245. # file.
  246. #
  247. ifndef $(2)_BUILD_CMDS
  248. ifeq ($(4),target)
  249. define $(2)_BUILD_CMDS
  250. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
  251. endef
  252. else
  253. define $(2)_BUILD_CMDS
  254. $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
  255. endef
  256. endif
  257. endif
  258. #
  259. # Host installation step. Only define it if not already defined by the
  260. # package .mk file.
  261. #
  262. ifndef $(2)_INSTALL_CMDS
  263. define $(2)_INSTALL_CMDS
  264. $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_SRCDIR)
  265. endef
  266. endif
  267. #
  268. # Staging installation step. Only define it if not already defined by
  269. # the package .mk file.
  270. #
  271. ifndef $(2)_INSTALL_STAGING_CMDS
  272. define $(2)_INSTALL_STAGING_CMDS
  273. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_SRCDIR)
  274. endef
  275. endif
  276. #
  277. # Target installation step. Only define it if not already defined by
  278. # the package .mk file.
  279. #
  280. ifndef $(2)_INSTALL_TARGET_CMDS
  281. define $(2)_INSTALL_TARGET_CMDS
  282. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_SRCDIR)
  283. endef
  284. endif
  285. # Call the generic package infrastructure to generate the necessary
  286. # make targets
  287. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  288. endef
  289. ################################################################################
  290. # autotools-package -- the target generator macro for autotools packages
  291. ################################################################################
  292. autotools-package = $(call inner-autotools-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  293. host-autotools-package = $(call inner-autotools-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)