autotools.mk 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. # 1: build dir
  24. # 2: remove files
  25. # 3: automake paths
  26. # 4: libtool paths
  27. # 5: extra m4 dirs
  28. define autoreconf
  29. (cd $(1); \
  30. $(patsubst %,rm -f %;,$(2)) \
  31. $(foreach p,$(3), \
  32. if [ -f $(p)/configure.ac ] || [ -f $(p)/configure.in ]; then \
  33. [ -d $(p)/autom4te.cache ] && rm -rf $(p)/autom4te.cache; \
  34. [ -e $(p)/config.rpath ] || \
  35. ln -s $(SCRIPT_DIR)/config.rpath $(p)/config.rpath; \
  36. touch NEWS AUTHORS COPYING ABOUT-NLS ChangeLog; \
  37. $(AM_TOOL_PATHS) \
  38. LIBTOOLIZE='$(STAGING_DIR_HOST)/bin/libtoolize --install' \
  39. $(STAGING_DIR_HOST)/bin/autoreconf -v -f -i -s \
  40. $(if $(word 2,$(3)),--no-recursive) \
  41. -B $(STAGING_DIR_HOST)/share/aclocal \
  42. $(patsubst %,-I %,$(5)) \
  43. $(patsubst %,-I %,$(4)) $(p) || true; \
  44. fi; \
  45. ) \
  46. );
  47. endef
  48. # 1: build dir
  49. define patch_libtool
  50. @(cd $(1); \
  51. for lt in $$$$($$(STAGING_DIR_HOST)/bin/find . -name ltmain.sh); do \
  52. lt_version="$$$$($$(STAGING_DIR_HOST)/bin/sed -ne 's,^[[:space:]]*VERSION="\?\([0-9]\.[0-9]\+\).*,\1,p' $$$$lt)"; \
  53. case "$$$$lt_version" in \
  54. 1.5|2.2|2.4) echo "autotools.mk: Found libtool v$$$$lt_version - applying patch to $$$$lt"; \
  55. (cd $$$$(dirname $$$$lt) && $$(PATCH) -N -s -p1 < $$(TOPDIR)/tools/libtool/files/libtool-v$$$$lt_version.patch || true) ;; \
  56. *) echo "autotools.mk: error: Unsupported libtool version v$$$$lt_version - cannot patch $$$$lt"; exit 1 ;; \
  57. esac; \
  58. done; \
  59. );
  60. endef
  61. define set_libtool_abiver
  62. sed -i \
  63. -e 's,^soname_spec=.*,soname_spec="\\$$$${libname}\\$$$${shared_ext}.$(PKG_ABI_VERSION)",' \
  64. -e 's,^library_names_spec=.*,library_names_spec="\\$$$${libname}\\$$$${shared_ext}.$(PKG_ABI_VERSION) \\$$$${libname}\\$$$${shared_ext}",' \
  65. $(PKG_BUILD_DIR)/libtool
  66. endef
  67. PKG_LIBTOOL_PATHS?=$(CONFIGURE_PATH)
  68. PKG_AUTOMAKE_PATHS?=$(CONFIGURE_PATH)
  69. PKG_MACRO_PATHS?=m4
  70. PKG_REMOVE_FILES?=aclocal.m4
  71. Hooks/InstallDev/Post += libtool_remove_files
  72. define autoreconf_target
  73. $(strip $(call autoreconf, \
  74. $(PKG_BUILD_DIR), $(PKG_REMOVE_FILES), \
  75. $(PKG_AUTOMAKE_PATHS), $(PKG_LIBTOOL_PATHS), \
  76. $(STAGING_DIR)/host/share/aclocal $(STAGING_DIR_HOSTPKG)/share/aclocal $(STAGING_DIR)/usr/share/aclocal $(PKG_MACRO_PATHS)))
  77. endef
  78. define patch_libtool_target
  79. $(strip $(call patch_libtool, \
  80. $(PKG_BUILD_DIR)))
  81. endef
  82. define gettext_version_target
  83. (cd $(PKG_BUILD_DIR) && \
  84. 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' ) && \
  85. $(STAGING_DIR_HOST)/bin/sed \
  86. -i $(PKG_BUILD_DIR)/configure.ac \
  87. -e "s/AM_GNU_GETTEXT_VERSION(.*)/AM_GNU_GETTEXT_VERSION(\[$$$$GETTEXT_VERSION\])/g" && \
  88. $(STAGING_DIR_HOSTPKG)/bin/autopoint --force \
  89. );
  90. endef
  91. ifneq ($(filter gettext-version,$(PKG_FIXUP)),)
  92. Hooks/Configure/Pre += gettext_version_target
  93. ifeq ($(filter no-autoreconf,$(PKG_FIXUP)),)
  94. Hooks/Configure/Pre += autoreconf_target
  95. endif
  96. endif
  97. ifneq ($(filter patch-libtool,$(PKG_FIXUP)),)
  98. Hooks/Configure/Pre += patch_libtool_target
  99. endif
  100. ifneq ($(filter libtool,$(PKG_FIXUP)),)
  101. PKG_BUILD_DEPENDS += libtool
  102. ifeq ($(filter no-autoreconf,$(PKG_FIXUP)),)
  103. Hooks/Configure/Pre += autoreconf_target
  104. endif
  105. endif
  106. ifneq ($(filter libtool-abiver,$(PKG_FIXUP)),)
  107. Hooks/Configure/Post += set_libtool_abiver
  108. endif
  109. ifneq ($(filter autoreconf,$(PKG_FIXUP)),)
  110. ifeq ($(filter autoreconf,$(Hooks/Configure/Pre)),)
  111. Hooks/Configure/Pre += autoreconf_target
  112. endif
  113. endif
  114. HOST_FIXUP?=$(PKG_FIXUP)
  115. HOST_LIBTOOL_PATHS?=$(if $(PKG_LIBTOOL_PATHS),$(PKG_LIBTOOL_PATHS),.)
  116. HOST_AUTOMAKE_PATHS?=$(if $(PKG_AUTOMAKE_PATHS),$(PKG_AUTOMAKE_PATHS),.)
  117. HOST_MACRO_PATHS?=$(if $(PKG_MACRO_PATHS),$(PKG_MACRO_PATHS),m4)
  118. HOST_REMOVE_FILES?=$(PKG_REMOVE_FILES)
  119. define autoreconf_host
  120. $(strip $(call autoreconf, \
  121. $(HOST_BUILD_DIR), $(HOST_REMOVE_FILES), \
  122. $(HOST_AUTOMAKE_PATHS), $(HOST_LIBTOOL_PATHS), \
  123. $(HOST_MACRO_PATHS)))
  124. endef
  125. define patch_libtool_host
  126. $(strip $(call patch_libtool, \
  127. $(HOST_BUILD_DIR)))
  128. endef
  129. ifneq ($(filter patch-libtool,$(HOST_FIXUP)),)
  130. Hooks/HostConfigure/Pre += patch_libtool_host
  131. endif
  132. ifneq ($(filter libtool,$(HOST_FIXUP)),)
  133. ifeq ($(filter no-autoreconf,$(HOST_FIXUP)),)
  134. Hooks/HostConfigure/Pre += autoreconf_host
  135. endif
  136. endif
  137. ifneq ($(filter autoreconf,$(HOST_FIXUP)),)
  138. ifeq ($(filter autoreconf,$(Hooks/HostConfigure/Pre)),)
  139. Hooks/HostConfigure/Pre += autoreconf_host
  140. endif
  141. endif
  142. endif #__autotools_inc