blob: e33eae7d4860e93e7065ae0067923bd34664bf6e [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
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"
Patrick Williams705982a2024-01-12 09:51:57 -060040EXTRA_AUTORECONF += "--exclude=autopoint"
Patrick Williams92b42cb2022-09-03 06:53:57 -050041
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.
Patrick Williams03514f12024-04-05 07:04:11 -050046# 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
Patrick Williams92b42cb2022-09-03 06:53:57 -050048export 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}"
Patrick Williams96e4b4e2025-02-03 15:49:15 -050055export CXXFLAGS_FOR_BUILD = "${BUILD_CXXFLAGS}"
Patrick Williams92b42cb2022-09-03 06:53:57 -050056
57export LD_FOR_BUILD = "${BUILD_LD}"
58export LDFLAGS_FOR_BUILD = "${BUILD_LDFLAGS}"
59
Patrick Williams92b42cb2022-09-03 06:53:57 -050060CONFIGUREOPTS = " --build=${BUILD_SYS} \
61 --host=${HOST_SYS} \
62 --target=${TARGET_SYS} \
63 --prefix=${prefix} \
64 --exec_prefix=${exec_prefix} \
65 --bindir=${bindir} \
66 --sbindir=${sbindir} \
67 --libexecdir=${libexecdir} \
68 --datadir=${datadir} \
69 --sysconfdir=${sysconfdir} \
70 --sharedstatedir=${sharedstatedir} \
71 --localstatedir=${localstatedir} \
72 --libdir=${libdir} \
73 --includedir=${includedir} \
Patrick Williamsac13d5f2023-11-24 18:59:46 -060074 --oldincludedir=${includedir} \
Patrick Williams92b42cb2022-09-03 06:53:57 -050075 --infodir=${infodir} \
76 --mandir=${mandir} \
77 --disable-silent-rules \
Andrew Geissleredff4922024-06-19 14:12:16 -040078 ${CONFIGUREOPT_DEPTRACK}"
Patrick Williams92b42cb2022-09-03 06:53:57 -050079CONFIGUREOPT_DEPTRACK ?= "--disable-dependency-tracking"
80
81CACHED_CONFIGUREVARS ?= ""
82
83AUTOTOOLS_SCRIPT_PATH ?= "${S}"
84CONFIGURE_SCRIPT ?= "${AUTOTOOLS_SCRIPT_PATH}/configure"
85
86AUTOTOOLS_AUXDIR ?= "${AUTOTOOLS_SCRIPT_PATH}"
87
88oe_runconf () {
89 # Use relative path to avoid buildpaths in files
90 cfgscript_name="`basename ${CONFIGURE_SCRIPT}`"
91 cfgscript=`python3 -c "import os; print(os.path.relpath(os.path.dirname('${CONFIGURE_SCRIPT}'), '.'))"`/$cfgscript_name
92 if [ -x "$cfgscript" ] ; then
93 bbnote "Running $cfgscript ${CONFIGUREOPTS} ${EXTRA_OECONF} $@"
94 if ! CONFIG_SHELL=${CONFIG_SHELL-/bin/bash} ${CACHED_CONFIGUREVARS} $cfgscript ${CONFIGUREOPTS} ${EXTRA_OECONF} "$@"; then
95 bbnote "The following config.log files may provide further information."
96 bbnote `find ${B} -ignore_readdir_race -type f -name config.log`
97 bbfatal_log "configure failed"
98 fi
99 else
100 bbfatal "no configure script found at $cfgscript"
101 fi
102}
103
104CONFIGURESTAMPFILE = "${WORKDIR}/configure.sstate"
105
106autotools_preconfigure() {
107 if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
108 if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" ]; then
109 if [ "${S}" != "${B}" ]; then
110 echo "Previously configured separate build directory detected, cleaning ${B}"
111 rm -rf ${B}
112 mkdir -p ${B}
113 else
114 # At least remove the .la files since automake won't automatically
115 # regenerate them even if CFLAGS/LDFLAGS are different
116 cd ${S}
117 if [ "${CLEANBROKEN}" != "1" -a \( -e Makefile -o -e makefile -o -e GNUmakefile \) ]; then
118 oe_runmake clean
119 fi
120 find ${S} -ignore_readdir_race -name \*.la -delete
121 fi
122 fi
123 fi
124}
125
126autotools_postconfigure(){
127 if [ -n "${CONFIGURESTAMPFILE}" ]; then
128 mkdir -p `dirname ${CONFIGURESTAMPFILE}`
129 echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
130 fi
131}
132
133EXTRACONFFUNCS ??= ""
134
135EXTRA_OECONF:append = " ${PACKAGECONFIG_CONFARGS}"
136
Patrick Williams96e4b4e2025-02-03 15:49:15 -0500137do_configure[prefuncs] += "autotools_preconfigure autotools_sitefiles ${EXTRACONFFUNCS}"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500138do_configure[postfuncs] += "autotools_postconfigure"
139
Patrick Williams96e4b4e2025-02-03 15:49:15 -0500140# Tell autoconf to load the site defaults from siteinfo
141python autotools_sitefiles () {
Patrick Williams92b42cb2022-09-03 06:53:57 -0500142 sitefiles, searched = siteinfo_get_files(d, sysrootcache=True)
143 d.setVar("CONFIG_SITE", " ".join(sitefiles))
144}
145
146do_configure[file-checksums] += "${@' '.join(siteinfo_get_files(d, sysrootcache=False)[1])}"
147
Andrew Geissler20137392023-10-12 04:59:14 -0600148CONFIGURE_FILES = "${S}/configure.in ${S}/configure.ac ${S}/config.h.in *.m4 Makefile.am"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500149
150autotools_do_configure() {
151 # WARNING: gross hack follows:
152 # An autotools built package generally needs these scripts, however only
153 # automake or libtoolize actually install the current versions of them.
154 # This is a problem in builds that do not use libtool or automake, in the case
155 # where we -need- the latest version of these scripts. e.g. running a build
156 # for a package whose autotools are old, on an x86_64 machine, which the old
157 # config.sub does not support. Work around this by installing them manually
158 # regardless.
159
160 PRUNE_M4=""
161
162 for ac in `find ${S} -ignore_readdir_race -name configure.in -o -name configure.ac`; do
163 rm -f `dirname $ac`/configure
164 done
165 if [ -e ${AUTOTOOLS_SCRIPT_PATH}/configure.in -o -e ${AUTOTOOLS_SCRIPT_PATH}/configure.ac ]; then
166 olddir=`pwd`
167 cd ${AUTOTOOLS_SCRIPT_PATH}
Patrick Williams96e4b4e2025-02-03 15:49:15 -0500168 # aclocal looks in the native sysroot by default, so tell it to also look in the target sysroot.
169 ACLOCAL="aclocal --aclocal-path=${STAGING_DATADIR}/aclocal/"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500170 if [ x"${acpaths}" = xdefault ]; then
171 acpaths=
172 for i in `find ${AUTOTOOLS_SCRIPT_PATH} -ignore_readdir_race -maxdepth 2 -name \*.m4|grep -v 'aclocal.m4'| \
173 grep -v 'acinclude.m4' | sed -e 's,\(.*/\).*$,\1,'|sort -u`; do
174 acpaths="$acpaths -I $i"
175 done
176 else
177 acpaths="${acpaths}"
178 fi
Patrick Williams92b42cb2022-09-03 06:53:57 -0500179 # autoreconf is too shy to overwrite aclocal.m4 if it doesn't look
180 # like it was auto-generated. Work around this by blowing it away
181 # by hand, unless the package specifically asked not to run aclocal.
182 if ! echo ${EXTRA_AUTORECONF} | grep -q "aclocal"; then
Patrick Williams96e4b4e2025-02-03 15:49:15 -0500183 bbnote Removing existing aclocal.m4
Patrick Williams92b42cb2022-09-03 06:53:57 -0500184 rm -f aclocal.m4
185 fi
186 if [ -e configure.in ]; then
187 CONFIGURE_AC=configure.in
188 else
189 CONFIGURE_AC=configure.ac
190 fi
191 if grep -q "^[[:space:]]*AM_GLIB_GNU_GETTEXT" $CONFIGURE_AC; then
192 if grep -q "sed.*POTFILES" $CONFIGURE_AC; then
193 : do nothing -- we still have an old unmodified configure.ac
194 else
195 bbnote Executing glib-gettextize --force --copy
196 echo "no" | glib-gettextize --force --copy
197 fi
198 elif [ "${BPN}" != "gettext" ] && grep -q "^[[:space:]]*AM_GNU_GETTEXT" $CONFIGURE_AC; then
199 # We'd call gettextize here if it wasn't so broken...
200 cp ${STAGING_DATADIR_NATIVE}/gettext/config.rpath ${AUTOTOOLS_AUXDIR}/
201 if [ -d ${S}/po/ ]; then
202 cp -f ${STAGING_DATADIR_NATIVE}/gettext/po/Makefile.in.in ${S}/po/
Patrick Williams96e4b4e2025-02-03 15:49:15 -0500203 if [ ! -e ${S}/po/remove-potcdate.sed ]; then
204 cp ${STAGING_DATADIR_NATIVE}/gettext/po/remove-potcdate.sed ${S}/po/
Patrick Williams92b42cb2022-09-03 06:53:57 -0500205 fi
206 fi
207 PRUNE_M4="$PRUNE_M4 gettext.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 po.m4 progtest.m4"
208 fi
209 mkdir -p m4
210
211 for i in $PRUNE_M4; do
212 find ${S} -ignore_readdir_race -name $i -delete
213 done
214
215 bbnote Executing ACLOCAL=\"$ACLOCAL\" autoreconf -Wcross --verbose --install --force ${EXTRA_AUTORECONF} $acpaths
216 ACLOCAL="$ACLOCAL" autoreconf -Wcross -Wno-obsolete --verbose --install --force ${EXTRA_AUTORECONF} $acpaths || die "autoreconf execution failed."
217 cd $olddir
218 fi
219 if [ -e ${CONFIGURE_SCRIPT} ]; then
220 oe_runconf
221 else
222 bbnote "nothing to configure"
223 fi
224}
225
226autotools_do_compile() {
227 oe_runmake
228}
229
230autotools_do_install() {
231 oe_runmake 'DESTDIR=${D}' install
232 # Info dir listing isn't interesting at this point so remove it if it exists.
233 if [ -e "${D}${infodir}/dir" ]; then
234 rm -f ${D}${infodir}/dir
235 fi
236}
237
Patrick Williams92b42cb2022-09-03 06:53:57 -0500238EXPORT_FUNCTIONS do_configure do_compile do_install
239
240B = "${WORKDIR}/build"