autotools.eclass 19 KB

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