media-plugins/gst-plugins-taglib-1.14.4: ppc stable, bug 674854
[gentoo.git] / eclass / autotools.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: autotools.eclass
5 # @MAINTAINER:
6 # base-system@gentoo.org
7 # @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
8 # @BLURB: Regenerates auto* build scripts
9 # @DESCRIPTION:
10 # This eclass is for safely handling autotooled software packages that need to
11 # regenerate their build scripts.  All functions will abort in case of errors.
12
13 # Note: We require GNU m4, as does autoconf.  So feel free to use any features
14 # from the GNU version of m4 without worrying about other variants (i.e. BSD).
15
16 if [[ ${__AUTOTOOLS_AUTO_DEPEND+set} == "set" ]] ; then
17         # See if we were included already, but someone changed the value
18         # of AUTOTOOLS_AUTO_DEPEND on us.  We could reload the entire
19         # eclass at that point, but that adds overhead, and it's trivial
20         # to re-order inherit in eclasses/ebuilds instead.  #409611
21         if [[ ${__AUTOTOOLS_AUTO_DEPEND} != ${AUTOTOOLS_AUTO_DEPEND} ]] ; then
22                 die "AUTOTOOLS_AUTO_DEPEND changed value between inherits; please inherit autotools.eclass first! ${__AUTOTOOLS_AUTO_DEPEND} -> ${AUTOTOOLS_AUTO_DEPEND}"
23         fi
24 fi
25
26 if [[ -z ${_AUTOTOOLS_ECLASS} ]]; then
27 _AUTOTOOLS_ECLASS=1
28
29 case ${EAPI:-0} in
30         0|1|2|3|4|5|6|7) ;;
31         *) die "${ECLASS}: EAPI ${EAPI} not supported" ;;
32 esac
33
34 inherit libtool
35
36 # @ECLASS-VARIABLE: WANT_AUTOCONF
37 # @DESCRIPTION:
38 # The major version of autoconf your package needs
39 : ${WANT_AUTOCONF:=latest}
40
41 # @ECLASS-VARIABLE: WANT_AUTOMAKE
42 # @DESCRIPTION:
43 # The major version of automake your package needs
44 : ${WANT_AUTOMAKE:=latest}
45
46 # @ECLASS-VARIABLE: WANT_LIBTOOL
47 # @DESCRIPTION:
48 # Do you want libtool?  Valid values here are "latest" and "none".
49 : ${WANT_LIBTOOL:=latest}
50
51 # @ECLASS-VARIABLE: _LATEST_AUTOMAKE
52 # @INTERNAL
53 # @DESCRIPTION:
54 # CONSTANT!
55 # The latest major unstable and stable version/slot of automake available
56 # on each arch.
57 # List latest unstable version first to boost testing adoption rate because
58 # most package manager dependency resolver will pick the first suitable
59 # version.
60 # If a newer slot is stable on any arch, and is NOT reflected in this list,
61 # then circular dependencies may arise during emerge @system bootstraps.
62
63 # See bug 312315 and 465732 for further information and context.
64
65 # Do NOT change this variable in your ebuilds!
66 # If you want to force a newer minor version, you can specify the correct
67 # WANT value by using a colon:  <PV>:<WANT_AUTOMAKE>
68 _LATEST_AUTOMAKE=( 1.16.1:1.16 1.15.1:1.15 )
69
70 _automake_atom="sys-devel/automake"
71 _autoconf_atom="sys-devel/autoconf"
72 if [[ -n ${WANT_AUTOMAKE} ]]; then
73         case ${WANT_AUTOMAKE} in
74                 # Even if the package doesn't use automake, we still need to depend
75                 # on it because we run aclocal to process m4 macros.  This matches
76                 # the autoreconf tool, so this requirement is correct.  #401605
77                 none) ;;
78                 latest)
79                         # Use SLOT deps if we can.  For EAPI=0, we get pretty close.
80                         if [[ ${EAPI:-0} != 0 ]] ; then
81                                 _automake_atom="|| ( `printf '>=sys-devel/automake-%s:%s ' ${_LATEST_AUTOMAKE[@]/:/ }` )"
82                         else
83                                 _automake_atom="|| ( `printf '>=sys-devel/automake-%s ' ${_LATEST_AUTOMAKE[@]/%:*}` )"
84                         fi
85                         ;;
86                 *)      _automake_atom="=sys-devel/automake-${WANT_AUTOMAKE}*" ;;
87         esac
88         export WANT_AUTOMAKE
89 fi
90
91 if [[ -n ${WANT_AUTOCONF} ]] ; then
92         case ${WANT_AUTOCONF} in
93                 none)       _autoconf_atom="" ;; # some packages don't require autoconf at all
94                 2.1)        _autoconf_atom="~sys-devel/autoconf-2.13" ;;
95                 # if you change the "latest" version here, change also autotools_env_setup
96                 latest|2.5) _autoconf_atom=">=sys-devel/autoconf-2.69" ;;
97                 *)          die "Invalid WANT_AUTOCONF value '${WANT_AUTOCONF}'" ;;
98         esac
99         export WANT_AUTOCONF
100 fi
101
102 _libtool_atom=">=sys-devel/libtool-2.4"
103 if [[ -n ${WANT_LIBTOOL} ]] ; then
104         case ${WANT_LIBTOOL} in
105                 none)   _libtool_atom="" ;;
106                 latest) ;;
107                 *)      die "Invalid WANT_LIBTOOL value '${WANT_LIBTOOL}'" ;;
108         esac
109         export WANT_LIBTOOL
110 fi
111
112 # Force people (nicely) to upgrade to a newer version of gettext as
113 # older ones are known to be crappy.  #496454
114 AUTOTOOLS_DEPEND="!<sys-devel/gettext-0.18.1.1-r3
115         ${_automake_atom}
116         ${_autoconf_atom}
117         ${_libtool_atom}"
118 RDEPEND=""
119
120 # @ECLASS-VARIABLE: AUTOTOOLS_AUTO_DEPEND
121 # @DESCRIPTION:
122 # Set to 'no' to disable automatically adding to DEPEND.  This lets
123 # ebuilds form conditional depends by using ${AUTOTOOLS_DEPEND} in
124 # their own DEPEND string.
125 : ${AUTOTOOLS_AUTO_DEPEND:=yes}
126 if [[ ${AUTOTOOLS_AUTO_DEPEND} != "no" ]] ; then
127         case ${EAPI:-0} in
128                 0|1|2|3|4|5|6) DEPEND=${AUTOTOOLS_DEPEND} ;;
129                 7) BDEPEND=${AUTOTOOLS_DEPEND} ;;
130         esac
131 fi
132 __AUTOTOOLS_AUTO_DEPEND=${AUTOTOOLS_AUTO_DEPEND} # See top of eclass
133
134 unset _automake_atom _autoconf_atom
135
136 # @ECLASS-VARIABLE: AM_OPTS
137 # @DEFAULT_UNSET
138 # @DESCRIPTION:
139 # Additional options to pass to automake during
140 # eautoreconf call.
141
142 # @ECLASS-VARIABLE: AT_NOEAUTOMAKE
143 # @DEFAULT_UNSET
144 # @DESCRIPTION:
145 # Don't run eautomake command if set to 'yes'; only used to workaround
146 # broken packages.  Generally you should, instead, fix the package to
147 # not call AM_INIT_AUTOMAKE if it doesn't actually use automake.
148
149 # @ECLASS-VARIABLE: AT_NOELIBTOOLIZE
150 # @DEFAULT_UNSET
151 # @DESCRIPTION:
152 # Don't run elibtoolize command if set to 'yes',
153 # useful when elibtoolize needs to be ran with
154 # particular options
155
156 # @ECLASS-VARIABLE: AT_M4DIR
157 # @DESCRIPTION:
158 # Additional director(y|ies) aclocal should search
159 : ${AT_M4DIR:=}
160
161 # @ECLASS-VARIABLE: AT_SYS_M4DIR
162 # @INTERNAL
163 # @DESCRIPTION:
164 # For system integrators, a list of additional aclocal search paths.
165 # This variable gets eval-ed, so you can use variables in the definition
166 # that may not be valid until eautoreconf & friends are run.
167 : ${AT_SYS_M4DIR:=}
168
169 # @FUNCTION: eautoreconf
170 # @DESCRIPTION:
171 # This function mimes the behavior of autoreconf, but uses the different
172 # eauto* functions to run the tools. It doesn't accept parameters, but
173 # the directory with include files can be specified with AT_M4DIR variable.
174 #
175 # Should do a full autoreconf - normally what most people will be interested in.
176 # Also should handle additional directories specified by AC_CONFIG_SUBDIRS.
177 eautoreconf() {
178         local x g
179
180         # Subdirs often share a common build dir #529404.  If so, we can't safely
181         # run in parallel because many tools clobber the content in there.  Libtool
182         # and automake both `rm && cp` while aclocal reads the output.  We might be
183         # able to handle this if we split the steps and grab locks on the dirs the
184         # tools actually write to.  Then we'd run all the common tools that use
185         # those inputs.  Doing this in bash does not scale easily.
186         # If we do re-enable parallel support, make sure #426512 is handled.
187         if [[ -z ${AT_NO_RECURSIVE} ]] ; then
188                 # Take care of subdirs
189                 for x in $(autotools_check_macro_val AC_CONFIG_SUBDIRS) ; do
190                         if [[ -d ${x} ]] ; then
191                                 pushd "${x}" >/dev/null
192                                 # Avoid unsafe nested multijob_finish_one for bug #426512.
193                                 AT_NOELIBTOOLIZE="yes" eautoreconf || die
194                                 popd >/dev/null
195                         fi
196                 done
197         fi
198
199         einfo "Running eautoreconf in '${PWD}' ..."
200
201         local m4dirs=$(autotools_check_macro_val AC_CONFIG_{AUX,MACRO}_DIR)
202         [[ -n ${m4dirs} ]] && mkdir -p ${m4dirs}
203
204         # Run all the tools before aclocal so we can gather the .m4 files.
205         local i tools=(
206                 # <tool> <was run> <command>
207                 glibgettext false "autotools_run_tool glib-gettextize --copy --force"
208                 gettext     false "autotools_run_tool --at-missing autopoint --force"
209                 # intltool must come after autopoint.
210                 intltool    false "autotools_run_tool intltoolize --automake --copy --force"
211                 gtkdoc      false "autotools_run_tool --at-missing gtkdocize --copy"
212                 gnomedoc    false "autotools_run_tool --at-missing gnome-doc-prepare --copy --force"
213                 libtool     false "_elibtoolize --auto-ltdl --install --copy --force"
214         )
215         for (( i = 0; i < ${#tools[@]}; i += 3 )) ; do
216                 if _at_uses_${tools[i]} ; then
217                         tools[i+1]=true
218                         ${tools[i+2]}
219                 fi
220         done
221
222         # Generate aclocal.m4 with our up-to-date m4 files.
223         local rerun_aclocal=false
224         eaclocal
225
226         # Check to see if we had macros expanded by other macros or in other
227         # m4 files that we couldn't detect early.  This is uncommon, but some
228         # packages do this, so we have to handle it correctly.
229         for (( i = 0; i < ${#tools[@]}; i += 3 )) ; do
230                 if ! ${tools[i+1]} && _at_uses_${tools[i]} ; then
231                         ${tools[i+2]}
232                         rerun_aclocal=true
233                 fi
234         done
235         ${rerun_aclocal} && eaclocal
236
237         if [[ ${WANT_AUTOCONF} = 2.1 ]] ; then
238                 eautoconf
239         else
240                 eautoconf --force
241         fi
242         eautoheader
243         [[ ${AT_NOEAUTOMAKE} != "yes" ]] && FROM_EAUTORECONF="yes" eautomake ${AM_OPTS}
244
245         if [[ ${AT_NOELIBTOOLIZE} != "yes" ]] ; then
246                 # Call it here to prevent failures due to elibtoolize called _before_
247                 # eautoreconf.
248                 elibtoolize --force "${PWD}"
249         fi
250
251         return 0
252 }
253
254 # @FUNCTION: _at_uses_pkg
255 # @USAGE: <macros>
256 # @INTERNAL
257 # See if the specified macros are enabled.
258 _at_uses_pkg() {
259         if [[ -n $(autotools_check_macro "$@") ]] ; then
260                 return 0
261         else
262                 # If the trace didn't find it (perhaps because aclocal.m4 hasn't
263                 # been generated yet), cheat, but be conservative.
264                 local macro args=()
265                 for macro ; do
266                         args+=( -e "^[[:space:]]*${macro}\>" )
267                 done
268                 egrep -q "${args[@]}" configure.??
269         fi
270 }
271 _at_uses_autoheader()  { _at_uses_pkg A{C,M}_CONFIG_HEADER{S,}; }
272 _at_uses_automake()    { _at_uses_pkg AM_INIT_AUTOMAKE; }
273 _at_uses_gettext()     { _at_uses_pkg AM_GNU_GETTEXT_{,REQUIRE_}VERSION; }
274 _at_uses_glibgettext() { _at_uses_pkg AM_GLIB_GNU_GETTEXT; }
275 _at_uses_intltool()    { _at_uses_pkg {AC,IT}_PROG_INTLTOOL; }
276 _at_uses_gtkdoc()      { _at_uses_pkg GTK_DOC_CHECK; }
277 _at_uses_gnomedoc()    { _at_uses_pkg GNOME_DOC_INIT; }
278 _at_uses_libtool()     { _at_uses_pkg A{C,M}_PROG_LIBTOOL LT_INIT; }
279 _at_uses_libltdl()     { _at_uses_pkg LT_CONFIG_LTDL_DIR; }
280
281 # @FUNCTION: eaclocal_amflags
282 # @DESCRIPTION:
283 # Extract the ACLOCAL_AMFLAGS value from the Makefile.am and try to handle
284 # (most) of the crazy crap that people throw at us.
285 eaclocal_amflags() {
286         local aclocal_opts amflags_file
287
288         for amflags_file in GNUmakefile.am Makefile.am GNUmakefile.in Makefile.in ; do
289                 [[ -e ${amflags_file} ]] || continue
290                 # setup the env in case the pkg does something crazy
291                 # in their ACLOCAL_AMFLAGS.  like run a shell script
292                 # which turns around and runs autotools. #365401
293                 # or split across multiple lines. #383525
294                 autotools_env_setup
295                 aclocal_opts=$(sed -n \
296                         "/^ACLOCAL_AMFLAGS[[:space:]]*=/{ \
297                           # match the first line
298                           s:[^=]*=::p; \
299                           # then gobble up all escaped lines
300                           : nextline /\\\\$/{ n; p; b nextline; } \
301                         }" ${amflags_file})
302                 eval aclocal_opts=\""${aclocal_opts}"\"
303                 break
304         done
305
306         echo ${aclocal_opts}
307 }
308
309 # @FUNCTION: eaclocal
310 # @DESCRIPTION:
311 # These functions runs the autotools using autotools_run_tool with the
312 # specified parametes. The name of the tool run is the same of the function
313 # without e prefix.
314 # They also force installing the support files for safety.
315 # Respects AT_M4DIR for additional directories to search for macro's.
316 eaclocal() {
317         [[ ! -f aclocal.m4 || -n $(grep -e 'generated.*by aclocal' aclocal.m4) ]] && \
318                 autotools_run_tool --at-m4flags aclocal "$@" $(eaclocal_amflags)
319 }
320
321 # @FUNCTION: _elibtoolize
322 # @DESCRIPTION:
323 # Runs libtoolize.
324 #
325 # Note the '_' prefix: avoid collision with elibtoolize() from libtool.eclass.
326 _elibtoolize() {
327         local LIBTOOLIZE=${LIBTOOLIZE:-$(type -P glibtoolize > /dev/null && echo glibtoolize || echo libtoolize)}
328
329         if [[ $1 == "--auto-ltdl" ]] ; then
330                 shift
331                 _at_uses_libltdl && set -- "$@" --ltdl
332         fi
333
334         [[ -f GNUmakefile.am || -f Makefile.am ]] && set -- "$@" --automake
335
336         autotools_run_tool ${LIBTOOLIZE} "$@"
337 }
338
339 # @FUNCTION: eautoheader
340 # @DESCRIPTION:
341 # Runs autoheader.
342 eautoheader() {
343         _at_uses_autoheader || return 0
344         autotools_run_tool --at-no-fail --at-m4flags autoheader "$@"
345 }
346
347 # @FUNCTION: eautoconf
348 # @DESCRIPTION:
349 # Runs autoconf.
350 eautoconf() {
351         if [[ ! -f configure.ac && ! -f configure.in ]] ; then
352                 echo
353                 eerror "No configure.{ac,in} present in '${PWD}'!"
354                 echo
355                 die "No configure.{ac,in} present!"
356         fi
357         if [[ ${WANT_AUTOCONF} != "2.1" && -e configure.in ]] ; then
358                 eqawarn "This package has a configure.in file which has long been deprecated.  Please"
359                 eqawarn "update it to use configure.ac instead as newer versions of autotools will die"
360                 eqawarn "when it finds this file.  See https://bugs.gentoo.org/426262 for details."
361         fi
362
363         autotools_run_tool --at-m4flags autoconf "$@"
364 }
365
366 # @FUNCTION: eautomake
367 # @DESCRIPTION:
368 # Runs automake.
369 eautomake() {
370         local extra_opts=()
371         local makefile_name
372
373         # Run automake if:
374         #  - a Makefile.am type file exists
375         #  - the configure script is using the AM_INIT_AUTOMAKE directive
376         for makefile_name in {GNUmakefile,{M,m}akefile}.am "" ; do
377                 [[ -f ${makefile_name} ]] && break
378         done
379
380         _automake_version() {
381                 autotools_run_tool --at-output automake --version 2>/dev/null |
382                         sed -n -e '1{s:.*(GNU automake) ::p;q}'
383         }
384
385         if [[ -z ${makefile_name} ]] ; then
386                 _at_uses_automake || return 0
387
388         elif [[ -z ${FROM_EAUTORECONF} && -f ${makefile_name%.am}.in ]]; then
389                 local used_automake
390                 local installed_automake
391
392                 installed_automake=$(WANT_AUTOMAKE= _automake_version)
393                 used_automake=$(head -n 1 < ${makefile_name%.am}.in | \
394                         sed -e 's:.*by automake \(.*\) from .*:\1:')
395
396                 if [[ ${installed_automake} != ${used_automake} ]]; then
397                         ewarn "Automake used for the package (${used_automake}) differs from" \
398                                 "the installed version (${installed_automake})."
399                         ewarn "Forcing a full rebuild of the autotools to workaround."
400                         eautoreconf
401                         return 0
402                 fi
403         fi
404
405         [[ -f INSTALL && -f AUTHORS && -f ChangeLog && -f NEWS && -f README ]] \
406                 || extra_opts+=( --foreign )
407
408         # Older versions of automake do not support --force-missing.  But we want
409         # to use this whenever possible to update random bundled files #133489.
410         case $(_automake_version) in
411         1.4|1.4[.-]*) ;;
412         *) extra_opts+=( --force-missing ) ;;
413         esac
414
415         autotools_run_tool automake --add-missing --copy "${extra_opts[@]}" "$@"
416 }
417
418 # @FUNCTION: eautopoint
419 # @DESCRIPTION:
420 # Runs autopoint (from the gettext package).
421 eautopoint() {
422         autotools_run_tool autopoint "$@"
423 }
424
425 # @FUNCTION: config_rpath_update
426 # @USAGE: [destination]
427 # @DESCRIPTION:
428 # Some packages utilize the config.rpath helper script, but don't
429 # use gettext directly.  So we have to copy it in manually since
430 # we can't let `autopoint` do it for us.
431 config_rpath_update() {
432         local dst src=$(type -P gettext | sed 's:bin/gettext:share/gettext/config.rpath:')
433
434         [[ $# -eq 0 ]] && set -- $(find -name config.rpath)
435         [[ $# -eq 0 ]] && return 0
436
437         einfo "Updating all config.rpath files"
438         for dst in "$@" ; do
439                 einfo "   ${dst}"
440                 cp "${src}" "${dst}" || die
441         done
442 }
443
444 # @FUNCTION: autotools_env_setup
445 # @INTERNAL
446 # @DESCRIPTION:
447 # Process the WANT_AUTO{CONF,MAKE} flags.
448 autotools_env_setup() {
449         # We do the "latest" → version switch here because it solves
450         # possible order problems, see bug #270010 as an example.
451         if [[ ${WANT_AUTOMAKE} == "latest" ]]; then
452                 local pv
453                 for pv in ${_LATEST_AUTOMAKE[@]/#*:} ; do
454                         # Break on first hit to respect _LATEST_AUTOMAKE order.
455                         local hv_args=""
456                         case ${EAPI:-0} in
457                                 5|6)
458                                         hv_args="--host-root"
459                                         ;;
460                                 7)
461                                         hv_args="-b"
462                                         ;;
463                         esac
464                         ROOT=/ has_version ${hv_args} "=sys-devel/automake-${pv}*" && export WANT_AUTOMAKE="${pv}" && break
465                 done
466                 [[ ${WANT_AUTOMAKE} == "latest" ]] && \
467                         die "Cannot find the latest automake! Tried ${_LATEST_AUTOMAKE[*]}"
468         fi
469         [[ ${WANT_AUTOCONF} == "latest" ]] && export WANT_AUTOCONF=2.5
470 }
471
472 # @FUNCTION: autotools_run_tool
473 # @USAGE: [--at-no-fail] [--at-m4flags] [--at-missing] [--at-output] <autotool> [tool-specific flags]
474 # @INTERNAL
475 # @DESCRIPTION:
476 # Run the specified autotool helper, but do logging and error checking
477 # around it in the process.
478 autotools_run_tool() {
479         # Process our own internal flags first
480         local autofail=true m4flags=false missing_ok=false return_output=false
481         while [[ -n $1 ]] ; do
482                 case $1 in
483                 --at-no-fail) autofail=false;;
484                 --at-m4flags) m4flags=true;;
485                 --at-missing) missing_ok=true;;
486                 --at-output)  return_output=true;;
487                 # whatever is left goes to the actual tool
488                 *) break;;
489                 esac
490                 shift
491         done
492
493         if [[ ${EBUILD_PHASE} != "unpack" && ${EBUILD_PHASE} != "prepare" ]]; then
494                 ewarn "QA Warning: running $1 in ${EBUILD_PHASE} phase"
495         fi
496
497         if ${missing_ok} && ! type -P ${1} >/dev/null ; then
498                 einfo "Skipping '$*' due $1 not installed"
499                 return 0
500         fi
501
502         autotools_env_setup
503
504         # Allow people to pass in full paths. #549268
505         local STDERR_TARGET="${T}/${1##*/}.out"
506         # most of the time, there will only be one run, but if there are
507         # more, make sure we get unique log filenames
508         if [[ -e ${STDERR_TARGET} ]] ; then
509                 local i=1
510                 while :; do
511                         STDERR_TARGET="${T}/${1##*/}-${i}.out"
512                         [[ -e ${STDERR_TARGET} ]] || break
513                         : $(( i++ ))
514                 done
515         fi
516
517         if ${m4flags} ; then
518                 set -- "${1}" $(autotools_m4dir_include) "${@:2}" $(autotools_m4sysdir_include)
519         fi
520
521         # If the caller wants to probe something, then let them do it directly.
522         if ${return_output} ; then
523                 "$@"
524                 return
525         fi
526
527         printf "***** $1 *****\n***** PWD: ${PWD}\n***** $*\n\n" > "${STDERR_TARGET}"
528
529         ebegin "Running $@"
530         "$@" >> "${STDERR_TARGET}" 2>&1
531         if ! eend $? && ${autofail} ; then
532                 echo
533                 eerror "Failed Running $1 !"
534                 eerror
535                 eerror "Include in your bugreport the contents of:"
536                 eerror
537                 eerror "  ${STDERR_TARGET}"
538                 echo
539                 die "Failed Running $1 !"
540         fi
541 }
542
543 # Internal function to check for support
544
545 # Keep a list of all the macros we might use so that we only
546 # have to run the trace code once.  Order doesn't matter.
547 ALL_AUTOTOOLS_MACROS=(
548         A{C,M}_PROG_LIBTOOL LT_INIT LT_CONFIG_LTDL_DIR
549         A{C,M}_CONFIG_HEADER{S,}
550         AC_CONFIG_SUBDIRS
551         AC_CONFIG_AUX_DIR AC_CONFIG_MACRO_DIR
552         AM_INIT_AUTOMAKE
553         AM_GLIB_GNU_GETTEXT
554         AM_GNU_GETTEXT_{,REQUIRE_}VERSION
555         {AC,IT}_PROG_INTLTOOL
556         GTK_DOC_CHECK
557         GNOME_DOC_INIT
558 )
559 autotools_check_macro() {
560         [[ -f configure.ac || -f configure.in ]] || return 0
561
562         # We can run in multiple dirs, so we have to cache the trace
563         # data in $PWD rather than an env var.
564         local trace_file=".__autoconf_trace_data"
565         if [[ ! -e ${trace_file} ]] || [[ ! aclocal.m4 -ot ${trace_file} ]] ; then
566                 WANT_AUTOCONF="2.5" autoconf \
567                         $(autotools_m4dir_include) \
568                         ${ALL_AUTOTOOLS_MACROS[@]/#/--trace=} > ${trace_file} 2>/dev/null
569         fi
570
571         local macro args=()
572         for macro ; do
573                 has ${macro} ${ALL_AUTOTOOLS_MACROS[@]} || die "internal error: add ${macro} to ALL_AUTOTOOLS_MACROS"
574                 args+=( -e ":${macro}:" )
575         done
576         grep "${args[@]}" ${trace_file}
577 }
578
579 # @FUNCTION: autotools_check_macro_val
580 # @USAGE: <macro> [macros]
581 # @INTERNAL
582 # @DESCRIPTION:
583 # Look for a macro and extract its value.
584 autotools_check_macro_val() {
585         local macro scan_out
586
587         for macro ; do
588                 autotools_check_macro "${macro}" | \
589                         gawk -v macro="${macro}" \
590                                 '($0 !~ /^[[:space:]]*(#|dnl)/) {
591                                         if (match($0, macro ":(.*)$", res))
592                                                 print res[1]
593                                 }' | uniq
594         done
595
596         return 0
597 }
598
599 _autotools_m4dir_include() {
600         local x include_opts flag
601
602         # Use the right flag to autoconf based on the version #448986
603         [[ ${WANT_AUTOCONF} == "2.1" ]] \
604                 && flag="l" \
605                 || flag="I"
606
607         for x in "$@" ; do
608                 case ${x} in
609                         # We handle it below
610                         -${flag}) ;;
611                         *)
612                                 [[ ! -d ${x} ]] && ewarn "autotools.eclass: '${x}' does not exist"
613                                 include_opts+=" -${flag} ${x}"
614                                 ;;
615                 esac
616         done
617
618         echo ${include_opts}
619 }
620 autotools_m4dir_include()    { _autotools_m4dir_include ${AT_M4DIR} ; }
621 autotools_m4sysdir_include() {
622         # First try to use the paths the system integrator has set up.
623         local paths=( $(eval echo ${AT_SYS_M4DIR}) )
624
625         if [[ ${#paths[@]} -eq 0 && -n ${SYSROOT} ]] ; then
626                 # If they didn't give us anything, then default to the SYSROOT.
627                 # This helps when cross-compiling.
628                 local path="${SYSROOT}/usr/share/aclocal"
629                 [[ -d ${path} ]] && paths+=( "${path}" )
630         fi
631         _autotools_m4dir_include "${paths[@]}"
632 }
633
634 fi