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