1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7def get_autotools_dep(d):
8    if d.getVar('INHIBIT_AUTOTOOLS_DEPS'):
9        return ''
10
11    pn = d.getVar('PN')
12    deps = ''
13
14    if pn in ['autoconf-native', 'automake-native']:
15        return deps
16    deps += 'autoconf-native automake-native '
17
18    if not pn in ['libtool', 'libtool-native'] and not pn.endswith("libtool-cross"):
19        deps += 'libtool-native '
20        if not bb.data.inherits_class('native', d) \
21                        and not bb.data.inherits_class('nativesdk', d) \
22                        and not bb.data.inherits_class('cross', d) \
23                        and not d.getVar('INHIBIT_DEFAULT_DEPS'):
24            deps += 'libtool-cross '
25
26    return deps
27
28
29DEPENDS:prepend = "${@get_autotools_dep(d)} "
30
31inherit siteinfo
32
33# Space separated list of shell scripts with variables defined to supply test
34# results for autoconf tests we cannot run at build time.
35# The value of this variable is filled in in a prefunc because it depends on
36# the contents of the sysroot.
37export CONFIG_SITE
38
39acpaths ?= "default"
40EXTRA_AUTORECONF += "--exclude=autopoint"
41
42export lt_cv_sys_lib_dlsearch_path_spec = "${libdir} ${base_libdir}"
43
44# When building tools for use at build-time it's recommended for the build
45# system to use these variables when cross-compiling.
46# https://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html
47# https://stackoverflow.com/questions/24201260/autotools-cross-compilation-and-generated-sources/24208587#24208587
48export CPP_FOR_BUILD = "${BUILD_CPP}"
49export CPPFLAGS_FOR_BUILD = "${BUILD_CPPFLAGS}"
50
51export CC_FOR_BUILD = "${BUILD_CC}"
52export CFLAGS_FOR_BUILD = "${BUILD_CFLAGS}"
53
54export CXX_FOR_BUILD = "${BUILD_CXX}"
55export CXXFLAGS_FOR_BUILD="${BUILD_CXXFLAGS}"
56
57export LD_FOR_BUILD = "${BUILD_LD}"
58export LDFLAGS_FOR_BUILD = "${BUILD_LDFLAGS}"
59
60def append_libtool_sysroot(d):
61    # Only supply libtool sysroot option for non-native packages
62    if not bb.data.inherits_class('native', d):
63        return '--with-libtool-sysroot=${STAGING_DIR_HOST}'
64    return ""
65
66CONFIGUREOPTS = " --build=${BUILD_SYS} \
67		  --host=${HOST_SYS} \
68		  --target=${TARGET_SYS} \
69		  --prefix=${prefix} \
70		  --exec_prefix=${exec_prefix} \
71		  --bindir=${bindir} \
72		  --sbindir=${sbindir} \
73		  --libexecdir=${libexecdir} \
74		  --datadir=${datadir} \
75		  --sysconfdir=${sysconfdir} \
76		  --sharedstatedir=${sharedstatedir} \
77		  --localstatedir=${localstatedir} \
78		  --libdir=${libdir} \
79		  --includedir=${includedir} \
80		  --oldincludedir=${includedir} \
81		  --infodir=${infodir} \
82		  --mandir=${mandir} \
83		  --disable-silent-rules \
84		  ${CONFIGUREOPT_DEPTRACK} \
85		  ${@append_libtool_sysroot(d)}"
86CONFIGUREOPT_DEPTRACK ?= "--disable-dependency-tracking"
87
88CACHED_CONFIGUREVARS ?= ""
89
90AUTOTOOLS_SCRIPT_PATH ?= "${S}"
91CONFIGURE_SCRIPT ?= "${AUTOTOOLS_SCRIPT_PATH}/configure"
92
93AUTOTOOLS_AUXDIR ?= "${AUTOTOOLS_SCRIPT_PATH}"
94
95oe_runconf () {
96	# Use relative path to avoid buildpaths in files
97	cfgscript_name="`basename ${CONFIGURE_SCRIPT}`"
98	cfgscript=`python3 -c "import os; print(os.path.relpath(os.path.dirname('${CONFIGURE_SCRIPT}'), '.'))"`/$cfgscript_name
99	if [ -x "$cfgscript" ] ; then
100		bbnote "Running $cfgscript ${CONFIGUREOPTS} ${EXTRA_OECONF} $@"
101		if ! CONFIG_SHELL=${CONFIG_SHELL-/bin/bash} ${CACHED_CONFIGUREVARS} $cfgscript ${CONFIGUREOPTS} ${EXTRA_OECONF} "$@"; then
102			bbnote "The following config.log files may provide further information."
103			bbnote `find ${B} -ignore_readdir_race -type f -name config.log`
104			bbfatal_log "configure failed"
105		fi
106	else
107		bbfatal "no configure script found at $cfgscript"
108	fi
109}
110
111CONFIGURESTAMPFILE = "${WORKDIR}/configure.sstate"
112
113autotools_preconfigure() {
114	if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
115		if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" ]; then
116			if [ "${S}" != "${B}" ]; then
117				echo "Previously configured separate build directory detected, cleaning ${B}"
118				rm -rf ${B}
119				mkdir -p ${B}
120			else
121				# At least remove the .la files since automake won't automatically
122				# regenerate them even if CFLAGS/LDFLAGS are different
123				cd ${S}
124				if [ "${CLEANBROKEN}" != "1" -a \( -e Makefile -o -e makefile -o -e GNUmakefile \) ]; then
125					oe_runmake clean
126				fi
127				find ${S} -ignore_readdir_race -name \*.la -delete
128			fi
129		fi
130	fi
131}
132
133autotools_postconfigure(){
134	if [ -n "${CONFIGURESTAMPFILE}" ]; then
135		mkdir -p `dirname ${CONFIGURESTAMPFILE}`
136		echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
137	fi
138}
139
140EXTRACONFFUNCS ??= ""
141
142EXTRA_OECONF:append = " ${PACKAGECONFIG_CONFARGS}"
143
144do_configure[prefuncs] += "autotools_preconfigure autotools_aclocals ${EXTRACONFFUNCS}"
145do_compile[prefuncs] += "autotools_aclocals"
146do_install[prefuncs] += "autotools_aclocals"
147do_configure[postfuncs] += "autotools_postconfigure"
148
149ACLOCALDIR = "${STAGING_DATADIR}/aclocal"
150ACLOCALEXTRAPATH = ""
151ACLOCALEXTRAPATH:class-target = " -I ${STAGING_DATADIR_NATIVE}/aclocal/"
152ACLOCALEXTRAPATH:class-nativesdk = " -I ${STAGING_DATADIR_NATIVE}/aclocal/"
153
154python autotools_aclocals () {
155    sitefiles, searched = siteinfo_get_files(d, sysrootcache=True)
156    d.setVar("CONFIG_SITE", " ".join(sitefiles))
157}
158
159do_configure[file-checksums] += "${@' '.join(siteinfo_get_files(d, sysrootcache=False)[1])}"
160
161CONFIGURE_FILES = "${S}/configure.in ${S}/configure.ac ${S}/config.h.in *.m4 Makefile.am"
162
163autotools_do_configure() {
164	# WARNING: gross hack follows:
165	# An autotools built package generally needs these scripts, however only
166	# automake or libtoolize actually install the current versions of them.
167	# This is a problem in builds that do not use libtool or automake, in the case
168	# where we -need- the latest version of these scripts.  e.g. running a build
169	# for a package whose autotools are old, on an x86_64 machine, which the old
170	# config.sub does not support.  Work around this by installing them manually
171	# regardless.
172
173	PRUNE_M4=""
174
175	for ac in `find ${S} -ignore_readdir_race -name configure.in -o -name configure.ac`; do
176		rm -f `dirname $ac`/configure
177	done
178	if [ -e ${AUTOTOOLS_SCRIPT_PATH}/configure.in -o -e ${AUTOTOOLS_SCRIPT_PATH}/configure.ac ]; then
179		olddir=`pwd`
180		cd ${AUTOTOOLS_SCRIPT_PATH}
181		mkdir -p ${ACLOCALDIR}
182		ACLOCAL="aclocal --system-acdir=${ACLOCALDIR}/"
183		if [ x"${acpaths}" = xdefault ]; then
184			acpaths=
185			for i in `find ${AUTOTOOLS_SCRIPT_PATH} -ignore_readdir_race -maxdepth 2 -name \*.m4|grep -v 'aclocal.m4'| \
186				grep -v 'acinclude.m4' | sed -e 's,\(.*/\).*$,\1,'|sort -u`; do
187				acpaths="$acpaths -I $i"
188			done
189		else
190			acpaths="${acpaths}"
191		fi
192		acpaths="$acpaths ${ACLOCALEXTRAPATH}"
193		AUTOV=`automake --version | sed -e '1{s/.* //;s/\.[0-9]\+$//};q'`
194		automake --version
195		echo "AUTOV is $AUTOV"
196		if [ -d ${STAGING_DATADIR_NATIVE}/aclocal-$AUTOV ]; then
197			ACLOCAL="$ACLOCAL --automake-acdir=${STAGING_DATADIR_NATIVE}/aclocal-$AUTOV"
198		fi
199		# autoreconf is too shy to overwrite aclocal.m4 if it doesn't look
200		# like it was auto-generated.  Work around this by blowing it away
201		# by hand, unless the package specifically asked not to run aclocal.
202		if ! echo ${EXTRA_AUTORECONF} | grep -q "aclocal"; then
203			rm -f aclocal.m4
204		fi
205		if [ -e configure.in ]; then
206			CONFIGURE_AC=configure.in
207		else
208			CONFIGURE_AC=configure.ac
209		fi
210		if grep -q "^[[:space:]]*AM_GLIB_GNU_GETTEXT" $CONFIGURE_AC; then
211			if grep -q "sed.*POTFILES" $CONFIGURE_AC; then
212				: do nothing -- we still have an old unmodified configure.ac
213	    		else
214				bbnote Executing glib-gettextize --force --copy
215				echo "no" | glib-gettextize --force --copy
216			fi
217		elif [ "${BPN}" != "gettext" ] && grep -q "^[[:space:]]*AM_GNU_GETTEXT" $CONFIGURE_AC; then
218			# We'd call gettextize here if it wasn't so broken...
219			cp ${STAGING_DATADIR_NATIVE}/gettext/config.rpath ${AUTOTOOLS_AUXDIR}/
220			if [ -d ${S}/po/ ]; then
221				cp -f ${STAGING_DATADIR_NATIVE}/gettext/po/Makefile.in.in ${S}/po/
222				if [ ! -e ${S}/po/remove-potcdate.sin ]; then
223					cp ${STAGING_DATADIR_NATIVE}/gettext/po/remove-potcdate.sin ${S}/po/
224				fi
225			fi
226			PRUNE_M4="$PRUNE_M4 gettext.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 po.m4 progtest.m4"
227		fi
228		mkdir -p m4
229
230		for i in $PRUNE_M4; do
231			find ${S} -ignore_readdir_race -name $i -delete
232		done
233
234		bbnote Executing ACLOCAL=\"$ACLOCAL\" autoreconf -Wcross --verbose --install --force ${EXTRA_AUTORECONF} $acpaths
235		ACLOCAL="$ACLOCAL" autoreconf -Wcross -Wno-obsolete --verbose --install --force ${EXTRA_AUTORECONF} $acpaths || die "autoreconf execution failed."
236		cd $olddir
237	fi
238	if [ -e ${CONFIGURE_SCRIPT} ]; then
239		oe_runconf
240	else
241		bbnote "nothing to configure"
242	fi
243}
244
245autotools_do_compile() {
246	oe_runmake
247}
248
249autotools_do_install() {
250	oe_runmake 'DESTDIR=${D}' install
251	# Info dir listing isn't interesting at this point so remove it if it exists.
252	if [ -e "${D}${infodir}/dir" ]; then
253		rm -f ${D}${infodir}/dir
254	fi
255}
256
257inherit siteconfig
258
259EXPORT_FUNCTIONS do_configure do_compile do_install
260
261B = "${WORKDIR}/build"
262