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