autotools.mk 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2007-2020 OpenWrt.org
  4. ifneq ($(__autotools_inc),1)
  5. __autotools_inc=1
  6. autoconf_bool = $(patsubst %,$(if $($(1)),--enable,--disable)-%,$(2))
  7. # delete *.la-files from staging_dir - we can not yet remove respective lines within all package
  8. # Makefiles, since backfire still uses libtool v1.5.x which (may) require those files
  9. define libtool_remove_files
  10. find $(1) -name '*.la' | $(XARGS) rm -f;
  11. endef
  12. AM_TOOL_PATHS:= \
  13. AUTOM4TE=$(STAGING_DIR_HOST)/bin/autom4te \
  14. AUTOCONF=$(STAGING_DIR_HOST)/bin/autoconf \
  15. AUTOMAKE=$(STAGING_DIR_HOST)/bin/automake \
  16. ACLOCAL=$(STAGING_DIR_HOST)/bin/aclocal \
  17. AUTOHEADER=$(STAGING_DIR_HOST)/bin/autoheader \
  18. LIBTOOLIZE=$(STAGING_DIR_HOST)/bin/libtoolize \
  19. LIBTOOL=$(STAGING_DIR_HOST)/bin/libtool \
  20. M4=$(STAGING_DIR_HOST)/bin/m4 \
  21. AUTOPOINT=true \
  22. GTKDOCIZE=true
  23. AM_TOOL_PATHS_FAKE:=$(subst = ,=,$(patsubst "%,"$(TRUE)",$(subst =,= ",$(AM_TOOL_PATHS))))
  24. # 1: build dir
  25. # 2: remove files
  26. # 3: automake paths
  27. # 4: libtool paths
  28. # 5: extra m4 dirs
  29. define autoreconf
  30. (cd $(1); \
  31. $(patsubst %,rm -f %;,$(2)) \
  32. $(foreach p,$(3), \
  33. if [ -f $(p)/configure.ac ] || [ -f $(p)/configure.in ]; then \
  34. [ -d $(p)/autom4te.cache ] && rm -rf $(p)/autom4te.cache; \
  35. [ -e $(p)/config.rpath ] || \
  36. ln -s $(SCRIPT_DIR)/config.rpath $(p)/config.rpath; \
  37. touch NEWS AUTHORS COPYING ABOUT-NLS ChangeLog; \
  38. $(AM_TOOL_PATHS) \
  39. LIBTOOLIZE='$(STAGING_DIR_HOST)/bin/libtoolize --install' \
  40. $(STAGING_DIR_HOST)/bin/autoreconf -v -f -i -s \
  41. $(if $(word 2,$(3)),--no-recursive) \
  42. -B $(STAGING_DIR_HOST)/share/aclocal \
  43. $(patsubst %,-I %,$(5)) \
  44. $(patsubst %,-I %,$(4)) $(p) || true; \
  45. fi; \
  46. ) \
  47. );
  48. endef
  49. # 1: build dir
  50. define patch_libtool
  51. @(cd $(1); \
  52. for lt in $$$$($$(STAGING_DIR_HOST)/bin/find . -name ltmain.sh); do \
  53. lt_version="$$$$($$(STAGING_DIR_HOST)/bin/sed -ne 's,^[[:space:]]*VERSION="\?\([0-9]\.[0-9]\+\).*,\1,p' $$$$lt)"; \
  54. case "$$$$lt_version" in \
  55. 1.5|2.2|2.4) echo "autotools.mk: Found libtool v$$$$lt_version - applying patch to $$$$lt"; \
  56. (cd $$$$(dirname $$$$lt) && $$(PATCH) -N -s -p1 < $$(TOPDIR)/tools/libtool/files/libtool-v$$$$lt_version.patch || true) ;; \
  57. *) echo "autotools.mk: error: Unsupported libtool version v$$$$lt_version - cannot patch $$$$lt"; exit 1 ;; \
  58. esac; \
  59. done; \
  60. );
  61. endef
  62. define set_libtool_abiver
  63. sed -i \
  64. -e 's,^soname_spec=.*,soname_spec="\\$$$${libname}\\$$$${shared_ext}.$(PKG_ABI_VERSION)",' \
  65. -e 's,^library_names_spec=.*,library_names_spec="\\$$$${libname}\\$$$${shared_ext}.$(PKG_ABI_VERSION) \\$$$${libname}\\$$$${shared_ext}",' \
  66. $(PKG_BUILD_DIR)/libtool
  67. endef
  68. PKG_LIBTOOL_PATHS?=$(CONFIGURE_PATH)
  69. PKG_AUTOMAKE_PATHS?=$(CONFIGURE_PATH)
  70. PKG_MACRO_PATHS?=m4
  71. PKG_REMOVE_FILES?=aclocal.m4
  72. Hooks/InstallDev/Post += libtool_remove_files
  73. define autoreconf_target
  74. $(strip $(call autoreconf, \
  75. $(PKG_BUILD_DIR), $(PKG_REMOVE_FILES), \
  76. $(PKG_AUTOMAKE_PATHS), $(PKG_LIBTOOL_PATHS), \
  77. $(STAGING_DIR)/host/share/aclocal $(STAGING_DIR_HOSTPKG)/share/aclocal $(STAGING_DIR)/usr/share/aclocal $(PKG_MACRO_PATHS)))
  78. endef
  79. define patch_libtool_target
  80. $(strip $(call patch_libtool, \
  81. $(PKG_BUILD_DIR)))
  82. endef
  83. define gettext_version_target
  84. (cd $(PKG_BUILD_DIR) && \
  85. GETTEXT_VERSION=$(shell $(STAGING_DIR_HOSTPKG)/bin/gettext -V | $(STAGING_DIR_HOST)/bin/sed -rne '1s/.*\b([0-9]\.[0-9]+(\.[0-9]+)?)\b.*/\1/p' ) && \
  86. $(STAGING_DIR_HOST)/bin/sed \
  87. -i $(PKG_BUILD_DIR)/configure.ac \
  88. -e "s/AM_GNU_GETTEXT_VERSION(.*)/AM_GNU_GETTEXT_VERSION(\[$$$$GETTEXT_VERSION\])/g" && \
  89. $(STAGING_DIR_HOSTPKG)/bin/autopoint --force \
  90. );
  91. endef
  92. ifneq ($(filter gettext-version,$(PKG_FIXUP)),)
  93. Hooks/Configure/Pre += gettext_version_target
  94. ifeq ($(filter no-autoreconf,$(PKG_FIXUP)),)
  95. Hooks/Configure/Pre += autoreconf_target
  96. endif
  97. endif
  98. ifneq ($(filter patch-libtool,$(PKG_FIXUP)),)
  99. Hooks/Configure/Pre += patch_libtool_target
  100. endif
  101. ifneq ($(filter libtool,$(PKG_FIXUP)),)
  102. PKG_BUILD_DEPENDS += libtool
  103. ifeq ($(filter no-autoreconf,$(PKG_FIXUP)),)
  104. Hooks/Configure/Pre += autoreconf_target
  105. endif
  106. endif
  107. ifneq ($(filter libtool-abiver,$(PKG_FIXUP)),)
  108. Hooks/Configure/Post += set_libtool_abiver
  109. endif
  110. ifneq ($(filter autoreconf,$(PKG_FIXUP)),)
  111. ifeq ($(filter autoreconf,$(Hooks/Configure/Pre)),)
  112. Hooks/Configure/Pre += autoreconf_target
  113. endif
  114. endif
  115. HOST_FIXUP?=$(PKG_FIXUP)
  116. HOST_LIBTOOL_PATHS?=$(if $(PKG_LIBTOOL_PATHS),$(PKG_LIBTOOL_PATHS),.)
  117. HOST_AUTOMAKE_PATHS?=$(if $(PKG_AUTOMAKE_PATHS),$(PKG_AUTOMAKE_PATHS),.)
  118. HOST_MACRO_PATHS?=$(if $(PKG_MACRO_PATHS),$(PKG_MACRO_PATHS),m4)
  119. HOST_REMOVE_FILES?=$(PKG_REMOVE_FILES)
  120. define autoreconf_host
  121. $(strip $(call autoreconf, \
  122. $(HOST_BUILD_DIR), $(HOST_REMOVE_FILES), \
  123. $(HOST_AUTOMAKE_PATHS), $(HOST_LIBTOOL_PATHS), \
  124. $(HOST_MACRO_PATHS)))
  125. endef
  126. define patch_libtool_host
  127. $(strip $(call patch_libtool, \
  128. $(HOST_BUILD_DIR)))
  129. endef
  130. ifneq ($(filter patch-libtool,$(HOST_FIXUP)),)
  131. Hooks/HostConfigure/Pre += patch_libtool_host
  132. endif
  133. ifneq ($(filter libtool,$(HOST_FIXUP)),)
  134. ifeq ($(filter no-autoreconf,$(HOST_FIXUP)),)
  135. Hooks/HostConfigure/Pre += autoreconf_host
  136. endif
  137. endif
  138. ifneq ($(filter autoreconf,$(HOST_FIXUP)),)
  139. ifeq ($(filter autoreconf,$(Hooks/HostConfigure/Pre)),)
  140. Hooks/HostConfigure/Pre += autoreconf_host
  141. endif
  142. endif
  143. endif #__autotools_inc