xref: /OK3568_Linux_fs/yocto/poky/meta/classes/autotools.bbclass (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1def get_autotools_dep(d):
2    if d.getVar('INHIBIT_AUTOTOOLS_DEPS'):
3        return ''
4
5    pn = d.getVar('PN')
6    deps = ''
7
8    if pn in ['autoconf-native', 'automake-native']:
9        return deps
10    deps += 'autoconf-native automake-native '
11
12    if not pn in ['libtool', 'libtool-native'] and not pn.endswith("libtool-cross"):
13        deps += 'libtool-native '
14        if not bb.data.inherits_class('native', d) \
15                        and not bb.data.inherits_class('nativesdk', d) \
16                        and not bb.data.inherits_class('cross', d) \
17                        and not d.getVar('INHIBIT_DEFAULT_DEPS'):
18            deps += 'libtool-cross '
19
20    return deps
21
22
23DEPENDS:prepend = "${@get_autotools_dep(d)} "
24
25inherit siteinfo
26
27# Space separated list of shell scripts with variables defined to supply test
28# results for autoconf tests we cannot run at build time.
29# The value of this variable is filled in in a prefunc because it depends on
30# the contents of the sysroot.
31export CONFIG_SITE
32
33acpaths ?= "default"
34EXTRA_AUTORECONF = "--exclude=autopoint --exclude=gtkdocize"
35
36export lt_cv_sys_lib_dlsearch_path_spec = "${libdir} ${base_libdir}"
37
38# When building tools for use at build-time it's recommended for the build
39# system to use these variables when cross-compiling.
40# (http://sources.redhat.com/autobook/autobook/autobook_270.html)
41export CPP_FOR_BUILD = "${BUILD_CPP}"
42export CPPFLAGS_FOR_BUILD = "${BUILD_CPPFLAGS}"
43
44export CC_FOR_BUILD = "${BUILD_CC}"
45export CFLAGS_FOR_BUILD = "${BUILD_CFLAGS}"
46
47export CXX_FOR_BUILD = "${BUILD_CXX}"
48export CXXFLAGS_FOR_BUILD="${BUILD_CXXFLAGS}"
49
50export LD_FOR_BUILD = "${BUILD_LD}"
51export LDFLAGS_FOR_BUILD = "${BUILD_LDFLAGS}"
52
53def append_libtool_sysroot(d):
54    # Only supply libtool sysroot option for non-native packages
55    if not bb.data.inherits_class('native', d):
56        return '--with-libtool-sysroot=${STAGING_DIR_HOST}'
57    return ""
58
59CONFIGUREOPTS = " --build=${BUILD_SYS} \
60		  --host=${HOST_SYS} \
61		  --target=${TARGET_SYS} \
62		  --prefix=${prefix} \
63		  --exec_prefix=${exec_prefix} \
64		  --bindir=${bindir} \
65		  --sbindir=${sbindir} \
66		  --libexecdir=${libexecdir} \
67		  --datadir=${datadir} \
68		  --sysconfdir=${sysconfdir} \
69		  --sharedstatedir=${sharedstatedir} \
70		  --localstatedir=${localstatedir} \
71		  --libdir=${libdir} \
72		  --includedir=${includedir} \
73		  --oldincludedir=${oldincludedir} \
74		  --infodir=${infodir} \
75		  --mandir=${mandir} \
76		  --disable-silent-rules \
77		  ${CONFIGUREOPT_DEPTRACK} \
78		  ${@append_libtool_sysroot(d)}"
79CONFIGUREOPT_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
137do_configure[prefuncs] += "autotools_preconfigure autotools_aclocals ${EXTRACONFFUNCS}"
138do_compile[prefuncs] += "autotools_aclocals"
139do_install[prefuncs] += "autotools_aclocals"
140do_configure[postfuncs] += "autotools_postconfigure"
141
142ACLOCALDIR = "${STAGING_DATADIR}/aclocal"
143ACLOCALEXTRAPATH = ""
144ACLOCALEXTRAPATH:class-target = " -I ${STAGING_DATADIR_NATIVE}/aclocal/"
145ACLOCALEXTRAPATH:class-nativesdk = " -I ${STAGING_DATADIR_NATIVE}/aclocal/"
146
147python autotools_aclocals () {
148    sitefiles, searched = siteinfo_get_files(d, sysrootcache=True)
149    d.setVar("CONFIG_SITE", " ".join(sitefiles))
150}
151
152do_configure[file-checksums] += "${@' '.join(siteinfo_get_files(d, sysrootcache=False)[1])}"
153
154CONFIGURE_FILES = "${S}/configure.in ${S}/configure.ac ${S}/config.h.in ${S}/acinclude.m4 Makefile.am"
155
156autotools_do_configure() {
157	# WARNING: gross hack follows:
158	# An autotools built package generally needs these scripts, however only
159	# automake or libtoolize actually install the current versions of them.
160	# This is a problem in builds that do not use libtool or automake, in the case
161	# where we -need- the latest version of these scripts.  e.g. running a build
162	# for a package whose autotools are old, on an x86_64 machine, which the old
163	# config.sub does not support.  Work around this by installing them manually
164	# regardless.
165
166	PRUNE_M4=""
167
168	for ac in `find ${S} -ignore_readdir_race -name configure.in -o -name configure.ac`; do
169		rm -f `dirname $ac`/configure
170	done
171	if [ -e ${AUTOTOOLS_SCRIPT_PATH}/configure.in -o -e ${AUTOTOOLS_SCRIPT_PATH}/configure.ac ]; then
172		olddir=`pwd`
173		cd ${AUTOTOOLS_SCRIPT_PATH}
174		mkdir -p ${ACLOCALDIR}
175		ACLOCAL="aclocal --system-acdir=${ACLOCALDIR}/"
176		if [ x"${acpaths}" = xdefault ]; then
177			acpaths=
178			for i in `find ${AUTOTOOLS_SCRIPT_PATH} -ignore_readdir_race -maxdepth 2 -name \*.m4|grep -v 'aclocal.m4'| \
179				grep -v 'acinclude.m4' | sed -e 's,\(.*/\).*$,\1,'|sort -u`; do
180				acpaths="$acpaths -I $i"
181			done
182		else
183			acpaths="${acpaths}"
184		fi
185		acpaths="$acpaths ${ACLOCALEXTRAPATH}"
186		AUTOV=`automake --version | sed -e '1{s/.* //;s/\.[0-9]\+$//};q'`
187		automake --version
188		echo "AUTOV is $AUTOV"
189		if [ -d ${STAGING_DATADIR_NATIVE}/aclocal-$AUTOV ]; then
190			ACLOCAL="$ACLOCAL --automake-acdir=${STAGING_DATADIR_NATIVE}/aclocal-$AUTOV"
191		fi
192		# autoreconf is too shy to overwrite aclocal.m4 if it doesn't look
193		# like it was auto-generated.  Work around this by blowing it away
194		# by hand, unless the package specifically asked not to run aclocal.
195		if ! echo ${EXTRA_AUTORECONF} | grep -q "aclocal"; then
196			rm -f aclocal.m4
197		fi
198		if [ -e configure.in ]; then
199			CONFIGURE_AC=configure.in
200		else
201			CONFIGURE_AC=configure.ac
202		fi
203		if grep -q "^[[:space:]]*AM_GLIB_GNU_GETTEXT" $CONFIGURE_AC; then
204			if grep -q "sed.*POTFILES" $CONFIGURE_AC; then
205				: do nothing -- we still have an old unmodified configure.ac
206	    		else
207				bbnote Executing glib-gettextize --force --copy
208				echo "no" | glib-gettextize --force --copy
209			fi
210		elif [ "${BPN}" != "gettext" ] && grep -q "^[[:space:]]*AM_GNU_GETTEXT" $CONFIGURE_AC; then
211			# We'd call gettextize here if it wasn't so broken...
212			cp ${STAGING_DATADIR_NATIVE}/gettext/config.rpath ${AUTOTOOLS_AUXDIR}/
213			if [ -d ${S}/po/ ]; then
214				cp -f ${STAGING_DATADIR_NATIVE}/gettext/po/Makefile.in.in ${S}/po/
215				if [ ! -e ${S}/po/remove-potcdate.sin ]; then
216					cp ${STAGING_DATADIR_NATIVE}/gettext/po/remove-potcdate.sin ${S}/po/
217				fi
218			fi
219			PRUNE_M4="$PRUNE_M4 gettext.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 po.m4 progtest.m4"
220		fi
221		mkdir -p m4
222
223		for i in $PRUNE_M4; do
224			find ${S} -ignore_readdir_race -name $i -delete
225		done
226
227		bbnote Executing ACLOCAL=\"$ACLOCAL\" autoreconf -Wcross --verbose --install --force ${EXTRA_AUTORECONF} $acpaths
228		ACLOCAL="$ACLOCAL" autoreconf -Wcross -Wno-obsolete --verbose --install --force ${EXTRA_AUTORECONF} $acpaths || die "autoreconf execution failed."
229		cd $olddir
230	fi
231	if [ -e ${CONFIGURE_SCRIPT} ]; then
232		oe_runconf
233	else
234		bbnote "nothing to configure"
235	fi
236}
237
238autotools_do_compile() {
239	oe_runmake
240}
241
242autotools_do_install() {
243	oe_runmake 'DESTDIR=${D}' install
244	# Info dir listing isn't interesting at this point so remove it if it exists.
245	if [ -e "${D}${infodir}/dir" ]; then
246		rm -f ${D}${infodir}/dir
247	fi
248}
249
250inherit siteconfig
251
252EXPORT_FUNCTIONS do_configure do_compile do_install
253
254B = "${WORKDIR}/build"
255