autotools.mk 5.6 KB

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