pkg-autotools.mk 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 informations 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. ################################################################################
  37. # inner-autotools-package -- defines how the configuration, compilation and
  38. # installation of an autotools package should be done, implements a
  39. # few hooks to tune the build process for autotools specifities and
  40. # calls the generic package infrastructure to generate the necessary
  41. # make targets
  42. #
  43. # argument 1 is the lowercase package name
  44. # argument 2 is the uppercase package name, including an HOST_ prefix
  45. # for host packages
  46. # argument 3 is the uppercase package name, without the HOST_ prefix
  47. # for host packages
  48. # argument 4 is the package directory prefix
  49. # argument 5 is the type (target or host)
  50. ################################################################################
  51. define inner-autotools-package
  52. ifndef $(2)_LIBTOOL_PATCH
  53. ifdef $(3)_LIBTOOL_PATCH
  54. $(2)_LIBTOOL_PATCH = $($(3)_LIBTOOL_PATCH)
  55. else
  56. $(2)_LIBTOOL_PATCH ?= YES
  57. endif
  58. endif
  59. ifndef $(2)_MAKE
  60. ifdef $(3)_MAKE
  61. $(2)_MAKE = $($(3)_MAKE)
  62. else
  63. $(2)_MAKE ?= $(MAKE)
  64. endif
  65. endif
  66. $(2)_CONF_ENV ?=
  67. $(2)_CONF_OPT ?=
  68. $(2)_MAKE_ENV ?=
  69. $(2)_MAKE_OPT ?=
  70. $(2)_AUTORECONF ?= NO
  71. $(2)_AUTORECONF_OPT ?=
  72. $(2)_INSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) install
  73. $(2)_INSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) install
  74. $(2)_CLEAN_OPT ?= clean
  75. $(2)_UNINSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) uninstall
  76. $(2)_UNINSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) uninstall
  77. #
  78. # Configure step. Only define it if not already defined by the package
  79. # .mk file. And take care of the differences between host and target
  80. # packages.
  81. #
  82. ifndef $(2)_CONFIGURE_CMDS
  83. ifeq ($(5),target)
  84. # Configure package for target
  85. define $(2)_CONFIGURE_CMDS
  86. (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache && \
  87. $$(TARGET_CONFIGURE_OPTS) \
  88. $$(TARGET_CONFIGURE_ARGS) \
  89. $$($$(PKG)_CONF_ENV) \
  90. ./configure \
  91. --target=$$(GNU_TARGET_NAME) \
  92. --host=$$(GNU_TARGET_NAME) \
  93. --build=$$(GNU_HOST_NAME) \
  94. --prefix=/usr \
  95. --exec-prefix=/usr \
  96. --sysconfdir=/etc \
  97. --program-prefix="" \
  98. $$(DISABLE_DOCUMENTATION) \
  99. $$(DISABLE_NLS) \
  100. $$(DISABLE_LARGEFILE) \
  101. $$(DISABLE_IPV6) \
  102. $$(SHARED_STATIC_LIBS_OPTS) \
  103. $$(QUIET) $$($$(PKG)_CONF_OPT) \
  104. )
  105. endef
  106. else
  107. # Configure package for host
  108. define $(2)_CONFIGURE_CMDS
  109. (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \
  110. $$(HOST_CONFIGURE_OPTS) \
  111. CFLAGS="$$(HOST_CFLAGS)" \
  112. LDFLAGS="$$(HOST_LDFLAGS)" \
  113. $$($$(PKG)_CONF_ENV) \
  114. ./configure \
  115. --prefix="$$(HOST_DIR)/usr" \
  116. --sysconfdir="$$(HOST_DIR)/etc" \
  117. --enable-shared --disable-static \
  118. $$($$(PKG)_CONF_OPT) \
  119. )
  120. endef
  121. endif
  122. endif
  123. #
  124. # Hook to update config.sub and config.guess if needed
  125. #
  126. define UPDATE_CONFIG_HOOK
  127. @$$(call MESSAGE, "Updating config.sub and config.guess")
  128. $$(call CONFIG_UPDATE,$$(@D))
  129. endef
  130. $(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK
  131. #
  132. # Hook to patch libtool to make it work properly for cross-compilation
  133. #
  134. define LIBTOOL_PATCH_HOOK
  135. @$$(call MESSAGE,"Patching libtool")
  136. $(Q)if test "$$($$(PKG)_LIBTOOL_PATCH)" = "YES" \
  137. -a "$$($$(PKG)_AUTORECONF)" != "YES"; then \
  138. for i in `find $$($$(PKG)_SRCDIR) -name ltmain.sh`; do \
  139. ltmain_version=`sed -n '/^[ ]*VERSION=/{s/^[ ]*VERSION=//;p;q;}' $$$$i | \
  140. sed -e 's/\([0-9].[0-9]*\).*/\1/' -e 's/\"//'`; \
  141. if test $$$${ltmain_version} = '1.5'; then \
  142. support/scripts/apply-patches.sh $$$${i%/*} support/libtool buildroot-libtool-v1.5.patch; \
  143. elif test $$$${ltmain_version} = "2.2"; then\
  144. support/scripts/apply-patches.sh $$$${i%/*} support/libtool buildroot-libtool-v2.2.patch; \
  145. elif test $$$${ltmain_version} = "2.4"; then\
  146. support/scripts/apply-patches.sh $$$${i%/*} support/libtool buildroot-libtool-v2.4.patch; \
  147. fi \
  148. done \
  149. fi
  150. endef
  151. # default values are not evaluated yet, so don't rely on this defaulting to YES
  152. ifneq ($$($(2)_LIBTOOL_PATCH),NO)
  153. $(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK
  154. endif
  155. #
  156. # Hook to autoreconf the package if needed
  157. #
  158. define AUTORECONF_HOOK
  159. @$$(call MESSAGE,"Autoreconfiguring")
  160. $(Q)cd $$($$(PKG)_SRCDIR) && $(AUTORECONF) $$($$(PKG)_AUTORECONF_OPT)
  161. $(Q)if test "$$($$(PKG)_LIBTOOL_PATCH)" = "YES"; then \
  162. for i in `find $$($$(PKG)_SRCDIR) -name ltmain.sh`; do \
  163. ltmain_version=`sed -n '/^[ ]*VERSION=/{s/^[ ]*VERSION=//;p;q;}' $$$$i | sed 's/\([0-9].[0-9]*\).*/\1/'`; \
  164. if test $$$${ltmain_version} = "1.5"; then \
  165. support/scripts/apply-patches.sh $$$${i%/*} support/libtool buildroot-libtool-v1.5.patch; \
  166. elif test $$$${ltmain_version} = "2.2"; then\
  167. support/scripts/apply-patches.sh $$$${i%/*} support/libtool buildroot-libtool-v2.2.patch; \
  168. elif test $$$${ltmain_version} = "2.4"; then\
  169. support/scripts/apply-patches.sh $$$${i%/*} support/libtool buildroot-libtool-v2.4.patch; \
  170. fi \
  171. done \
  172. fi
  173. endef
  174. # This must be repeated from inner-generic-package, otherwise we get an empty
  175. # _DEPENDENCIES if _AUTORECONF is YES. Also filter the result of _AUTORECONF
  176. # away from the non-host rule
  177. $(2)_DEPENDENCIES ?= $(filter-out host-automake host-autoconf host-libtool $(1),\
  178. $(patsubst host-host-%,host-%,$(addprefix host-,$($(3)_DEPENDENCIES))))
  179. ifeq ($$($(2)_AUTORECONF),YES)
  180. $(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
  181. $(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
  182. endif
  183. #
  184. # Build step. Only define it if not already defined by the package .mk
  185. # file.
  186. #
  187. ifndef $(2)_BUILD_CMDS
  188. ifeq ($(5),target)
  189. define $(2)_BUILD_CMDS
  190. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_SRCDIR)
  191. endef
  192. else
  193. define $(2)_BUILD_CMDS
  194. $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_SRCDIR)
  195. endef
  196. endif
  197. endif
  198. #
  199. # Host installation step. Only define it if not already defined by the
  200. # package .mk file.
  201. #
  202. ifndef $(2)_INSTALL_CMDS
  203. define $(2)_INSTALL_CMDS
  204. $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) -C $$($$(PKG)_SRCDIR) install
  205. endef
  206. endif
  207. #
  208. # Staging installation step. Only define it if not already defined by
  209. # the package .mk file.
  210. #
  211. ifndef $(2)_INSTALL_STAGING_CMDS
  212. define $(2)_INSTALL_STAGING_CMDS
  213. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPT) -C $$($$(PKG)_SRCDIR)
  214. for i in $$$$(find $(STAGING_DIR)/usr/lib* -name "*.la"); do \
  215. cp -f $$$$i $$$$i~; \
  216. $$(SED) "s:\(['= ]\)/usr:\\1$(STAGING_DIR)/usr:g" $$$$i; \
  217. done
  218. endef
  219. endif
  220. #
  221. # Target installation step. Only define it if not already defined by
  222. # the package .mk file.
  223. #
  224. ifndef $(2)_INSTALL_TARGET_CMDS
  225. define $(2)_INSTALL_TARGET_CMDS
  226. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPT) -C $$($$(PKG)_SRCDIR)
  227. endef
  228. endif
  229. #
  230. # Clean step. Only define it if not already defined by
  231. # the package .mk file.
  232. #
  233. ifndef $(2)_CLEAN_CMDS
  234. define $(2)_CLEAN_CMDS
  235. -$$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_CLEAN_OPT) -C $$($$(PKG)_SRCDIR)
  236. endef
  237. endif
  238. #
  239. # Uninstall from staging step. Only define it if not already defined by
  240. # the package .mk file.
  241. #
  242. ifndef $(2)_UNINSTALL_STAGING_CMDS
  243. define $(2)_UNINSTALL_STAGING_CMDS
  244. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_UNINSTALL_STAGING_OPT) -C $$($$(PKG)_SRCDIR)
  245. endef
  246. endif
  247. #
  248. # Uninstall from target step. Only define it if not already defined
  249. # by the package .mk file.
  250. # Autotools Makefiles do uninstall with ( cd ...; rm -f ... )
  251. # Since we remove a lot of directories in target-finalize, this is likely
  252. # to fail. Therefore add -k flag.
  253. #
  254. ifndef $(2)_UNINSTALL_TARGET_CMDS
  255. define $(2)_UNINSTALL_TARGET_CMDS
  256. $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) -k $$($$(PKG)_UNINSTALL_TARGET_OPT) -C $$($$(PKG)_SRCDIR)
  257. endef
  258. endif
  259. # Call the generic package infrastructure to generate the necessary
  260. # make targets
  261. $(call inner-generic-package,$(1),$(2),$(3),$(4),$(5))
  262. endef
  263. ################################################################################
  264. # autotools-package -- the target generator macro for autotools packages
  265. ################################################################################
  266. autotools-package = $(call inner-autotools-package,$(call pkgname),$(call UPPERCASE,$(call pkgname)),$(call UPPERCASE,$(call pkgname)),$(call pkgparentdir),target)
  267. host-autotools-package = $(call inner-autotools-package,host-$(call pkgname),$(call UPPERCASE,host-$(call pkgname)),$(call UPPERCASE,$(call pkgname)),$(call pkgparentdir),host)