pkg-autotools.mk 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 autoreconf the package if needed
  85. #
  86. define AUTORECONF_HOOK
  87. @$(call MESSAGE,"Autoreconfiguring")
  88. $(Q)cd $($(PKG)_SRCDIR) && $($(PKG)_AUTORECONF_ENV) $(AUTORECONF) $($(PKG)_AUTORECONF_OPTS)
  89. endef
  90. ################################################################################
  91. # inner-autotools-package -- defines how the configuration, compilation and
  92. # installation of an autotools package should be done, implements a
  93. # few hooks to tune the build process for autotools specifities and
  94. # calls the generic package infrastructure to generate the necessary
  95. # make targets
  96. #
  97. # argument 1 is the lowercase package name
  98. # argument 2 is the uppercase package name, including a HOST_ prefix
  99. # for host packages
  100. # argument 3 is the uppercase package name, without the HOST_ prefix
  101. # for host packages
  102. # argument 4 is the type (target or host)
  103. ################################################################################
  104. define inner-autotools-package
  105. ifndef $(2)_LIBTOOL_PATCH
  106. ifdef $(3)_LIBTOOL_PATCH
  107. $(2)_LIBTOOL_PATCH = $$($(3)_LIBTOOL_PATCH)
  108. else
  109. $(2)_LIBTOOL_PATCH ?= YES
  110. endif
  111. endif
  112. ifndef $(2)_MAKE
  113. ifdef $(3)_MAKE
  114. $(2)_MAKE = $$($(3)_MAKE)
  115. else
  116. $(2)_MAKE ?= $$(MAKE)
  117. endif
  118. endif
  119. ifndef $(2)_AUTORECONF
  120. ifdef $(3)_AUTORECONF
  121. $(2)_AUTORECONF = $$($(3)_AUTORECONF)
  122. else
  123. $(2)_AUTORECONF ?= NO
  124. endif
  125. endif
  126. ifndef $(2)_AUTOPOINT
  127. ifdef $(3)_AUTOPOINT
  128. $(2)_AUTOPOINT = $$($(3)_AUTOPOINT)
  129. else
  130. $(2)_AUTOPOINT ?= NO
  131. endif
  132. endif
  133. ifeq ($(4),host)
  134. $(2)_AUTORECONF_OPTS ?= $$($(3)_AUTORECONF_OPTS)
  135. endif
  136. $(2)_INSTALL_OPTS ?= install
  137. $(2)_INSTALL_STAGING_OPTS ?= DESTDIR=$$(STAGING_DIR) install
  138. $(2)_INSTALL_TARGET_OPTS ?= DESTDIR=$$(TARGET_DIR) install
  139. #
  140. # Configure step. Only define it if not already defined by the package
  141. # .mk file. And take care of the differences between host and target
  142. # packages.
  143. #
  144. ifndef $(2)_CONFIGURE_CMDS
  145. ifeq ($(4),target)
  146. # Configure package for target
  147. define $(2)_CONFIGURE_CMDS
  148. (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache && \
  149. $$(TARGET_CONFIGURE_OPTS) \
  150. $$(TARGET_CONFIGURE_ARGS) \
  151. $$($$(PKG)_CONF_ENV) \
  152. CONFIG_SITE=/dev/null \
  153. ./configure \
  154. --target=$$(GNU_TARGET_NAME) \
  155. --host=$$(GNU_TARGET_NAME) \
  156. --build=$$(GNU_HOST_NAME) \
  157. --prefix=/usr \
  158. --exec-prefix=/usr \
  159. --sysconfdir=/etc \
  160. --localstatedir=/var \
  161. --program-prefix="" \
  162. --disable-gtk-doc \
  163. --disable-gtk-doc-html \
  164. --disable-doc \
  165. --disable-docs \
  166. --disable-documentation \
  167. --with-xmlto=no \
  168. --with-fop=no \
  169. $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
  170. --enable-ipv6 \
  171. $$(NLS_OPTS) \
  172. $$(SHARED_STATIC_LIBS_OPTS) \
  173. $$(QUIET) $$($$(PKG)_CONF_OPTS) \
  174. )
  175. endef
  176. else
  177. # Configure package for host
  178. # disable all kind of documentation generation in the process,
  179. # because it often relies on host tools which may or may not be
  180. # installed.
  181. define $(2)_CONFIGURE_CMDS
  182. (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \
  183. $$(HOST_CONFIGURE_OPTS) \
  184. CFLAGS="$$(HOST_CFLAGS)" \
  185. LDFLAGS="$$(HOST_LDFLAGS)" \
  186. $$($$(PKG)_CONF_ENV) \
  187. CONFIG_SITE=/dev/null \
  188. ./configure \
  189. --prefix="$$(HOST_DIR)" \
  190. --sysconfdir="$$(HOST_DIR)/etc" \
  191. --localstatedir="$$(HOST_DIR)/var" \
  192. --enable-shared --disable-static \
  193. --disable-gtk-doc \
  194. --disable-gtk-doc-html \
  195. --disable-doc \
  196. --disable-docs \
  197. --disable-documentation \
  198. --disable-debug \
  199. --with-xmlto=no \
  200. --with-fop=no \
  201. --disable-nls \
  202. $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \
  203. $$(QUIET) $$($$(PKG)_CONF_OPTS) \
  204. )
  205. endef
  206. endif
  207. endif
  208. $(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK
  209. ifeq ($$($(2)_AUTORECONF),YES)
  210. # autopoint is provided by gettext
  211. ifeq ($$($(2)_AUTOPOINT),YES)
  212. $(2)_DEPENDENCIES += host-gettext
  213. $(2)_AUTORECONF_ENV += AUTOPOINT=$$(HOST_DIR)/bin/autopoint
  214. else
  215. $(2)_AUTORECONF_ENV += AUTOPOINT=/bin/true
  216. endif
  217. $(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
  218. # default values are not evaluated yet, so don't rely on this defaulting to YES
  219. ifneq ($$($(2)_LIBTOOL_PATCH),NO)
  220. $(2)_PRE_CONFIGURE_HOOKS += LIBTOOL_PATCH_HOOK
  221. endif
  222. $(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
  223. else # ! AUTORECONF = YES
  224. # default values are not evaluated yet, so don't rely on this defaulting to YES
  225. ifneq ($$($(2)_LIBTOOL_PATCH),NO)
  226. $(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK
  227. endif
  228. endif
  229. # Append a configure hook if building for a powerpc64 (or powerpc64le) arch.
  230. # Must be added after other pre-configure hooks that might regenerate the
  231. # configure script and overwrite the changes made here.
  232. ifneq ($$(filter powerpc64%,$$(if $$(filter target,$(4)),$$(ARCH),$$(HOSTARCH))),)
  233. $(2)_PRE_CONFIGURE_HOOKS += CONFIGURE_FIX_POWERPC64_HOOK
  234. endif
  235. #
  236. # Build step. Only define it if not already defined by the package .mk
  237. # file.
  238. #
  239. ifndef $(2)_BUILD_CMDS
  240. ifeq ($(4),target)
  241. define $(2)_BUILD_CMDS
  242. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
  243. endef
  244. else
  245. define $(2)_BUILD_CMDS
  246. $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR)
  247. endef
  248. endif
  249. endif
  250. #
  251. # Host installation step. Only define it if not already defined by the
  252. # package .mk file.
  253. #
  254. ifndef $(2)_INSTALL_CMDS
  255. define $(2)_INSTALL_CMDS
  256. $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_SRCDIR)
  257. endef
  258. endif
  259. #
  260. # Staging installation step. Only define it if not already defined by
  261. # the package .mk file.
  262. #
  263. ifndef $(2)_INSTALL_STAGING_CMDS
  264. define $(2)_INSTALL_STAGING_CMDS
  265. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_SRCDIR)
  266. endef
  267. endif
  268. #
  269. # Target installation step. Only define it if not already defined by
  270. # the package .mk file.
  271. #
  272. ifndef $(2)_INSTALL_TARGET_CMDS
  273. define $(2)_INSTALL_TARGET_CMDS
  274. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_SRCDIR)
  275. endef
  276. endif
  277. # Call the generic package infrastructure to generate the necessary
  278. # make targets
  279. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  280. endef
  281. ################################################################################
  282. # autotools-package -- the target generator macro for autotools packages
  283. ################################################################################
  284. autotools-package = $(call inner-autotools-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  285. host-autotools-package = $(call inner-autotools-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)