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