handle multiline ACLOCAL_AMFLAGS #383525 by Mikael Morin
authorMike Frysinger <vapier@gentoo.org>
Fri, 23 Sep 2011 04:14:02 +0000 (04:14 +0000)
committerMike Frysinger <vapier@gentoo.org>
Fri, 23 Sep 2011 04:14:02 +0000 (04:14 +0000)
eclass/autotools.eclass
eclass/tests/autotools:eaclocal_amflags.sh [new file with mode: 0755]

index ab67d5c66e79aba655e8f3cc429e16f1ec3aaa04..0ed2556db2b6cef053420fcf3ce7540cd0f85ae9 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/autotools.eclass,v 1.106 2011/08/22 19:39:52 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/autotools.eclass,v 1.107 2011/09/23 04:14:02 vapier Exp $
 
 # @ECLASS: autotools.eclass
 # @MAINTAINER:
@@ -153,30 +153,44 @@ eautoreconf() {
        return 0
 }
 
-# @FUNCTION: eaclocal
+# @FUNCTION: eaclocal_amflags
 # @DESCRIPTION:
-# These functions runs the autotools using autotools_run_tool with the
-# specified parametes. The name of the tool run is the same of the function
-# without e prefix.
-# They also force installing the support files for safety.
-# Respects AT_M4DIR for additional directories to search for macro's.
-eaclocal() {
-       local aclocal_opts
+# Extract the ACLOCAL_AMFLAGS value from the Makefile.am and try to handle
+# (most) of the crazy crap that people throw at us.
+eaclocal_amflags() {
+       local aclocal_opts amflags_file
 
-       local amflags_file
        for amflags_file in GNUmakefile.am Makefile.am GNUmakefile.in Makefile.in ; do
                [[ -e ${amflags_file} ]] || continue
                # setup the env in case the pkg does something crazy
                # in their ACLOCAL_AMFLAGS.  like run a shell script
-               # which turns around and runs autotools #365401
+               # which turns around and runs autotools. #365401
+               # or split across multiple lines. #383525
                autotools_env_setup
-               aclocal_opts=$(sed -n '/^ACLOCAL_AMFLAGS[[:space:]]*=/s:[^=]*=::p' ${amflags_file})
-               eval aclocal_opts=\"${aclocal_opts}\"
+               aclocal_opts=$(sed -n \
+                       "/^ACLOCAL_AMFLAGS[[:space:]]*=/{ \
+                         # match the first line
+                         s:[^=]*=::p; \
+                         # then gobble up all escaped lines
+                         : nextline /\\\\$/{ n; p; b nextline; } \
+                       }" ${amflags_file})
+               eval aclocal_opts=\""${aclocal_opts}"\"
                break
        done
 
+       echo ${aclocal_opts}
+}
+
+# @FUNCTION: eaclocal
+# @DESCRIPTION:
+# These functions runs the autotools using autotools_run_tool with the
+# specified parametes. The name of the tool run is the same of the function
+# without e prefix.
+# They also force installing the support files for safety.
+# Respects AT_M4DIR for additional directories to search for macro's.
+eaclocal() {
        [[ ! -f aclocal.m4 || -n $(grep -e 'generated.*by aclocal' aclocal.m4) ]] && \
-               autotools_run_tool aclocal $(autotools_m4dir_include) "$@" ${aclocal_opts}
+               autotools_run_tool aclocal $(autotools_m4dir_include) "$@" $(eaclocal_amflags)
 }
 
 # @FUNCTION: _elibtoolize
diff --git a/eclass/tests/autotools:eaclocal_amflags.sh b/eclass/tests/autotools:eaclocal_amflags.sh
new file mode 100755 (executable)
index 0000000..ac0ab76
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+source tests-common.sh
+
+inherit autotools
+
+test-it() {
+       ebegin "Testing eaclocal_amflags $1: $2"
+       printf "ACLOCAL_AMFLAGS = %b\n" "$2" > Makefile.am
+       local flags=$(eaclocal_amflags) exp=${3:-$2}
+       [[ "${flags}" == "${exp}" ]]
+       if ! eend $? ; then
+               printf '### INPUT:\n%s\n' "$2"
+               printf '### FILE:\n%s\n' "$(<Makefile.am)"
+               printf '### EXPECTED:\n%s\n' "${exp}"
+               printf '### ACTUAL:\n%s\n' "${flags}"
+       fi
+       rm Makefile.am
+}
+
+test-it simple "-Im4"
+test-it simple "-I m4 -I lakdjfladsfj /////"
+
+test-it shell-exec '`echo hi`' "hi"
+test-it shell-exec '`echo {0..3}`' "0 1 2 3"
+
+test-it multiline '-I oneline \\\n\t-I twoline' "-I oneline -I twoline"