On 10/17/2012 10:05 PM, Nick Bowler wrote:
> On 2012-10-17 09:25 +0200, Stefano Lattarini wrote:
>> On 10/16/2012 10:46 PM, Nick Bowler wrote:
>>> I think it's important to have, for testing, a version of aclocal that
>>> actually makes use of this feature.
>>>
>> The reason I wrote this patch is because I want to make use of this
>> feature in aclocal 1.13.  See also:
>> <http://lists.gnu.org/archive/html/automake-patches/2012-07/msg00030.html>
> 
> Right, I didn't mean to suggest that you weren't planning to use it:
> what I'd like to see is
> 
>  * a patch to autoconf (we have this: currently under discussion)
>  * a patch to aclocal
>  * a patch to libtoolize
> 
> so that people (like me) can apply all these patches, try to convert
> their projects to use AC_CONFIG_MACRO_DIRS, and actually see how things
> behave first hand.  The linked aclocal patches don't seem like they'd
> work with *this* autoconf patch under discussion.
>
Of course, they were written before these autoconf patches :-)

Anyway, I agree some early testing by real users would be very useful,
so here is a first cut at the Automake part of the AC_CONFIG_MACRO_DIRS
support (see attached patches).

>>> That way, it's actually possible to
>>> validate that this feature works in a useful manner.  Bonus points for
>>> demonstrating that we can kill off ACLOCAL_AMFLAGS entirely (this means
>>> patching at least libtool as well as automake and autoconf).  While it's
>>> not my call, a testable implementation should be a prerequisite for
>>> merging another macro like this into Autoconf.
>>
>> Well, I agree that is be a prerequisite for adding this new macro into a
>> *released* Autoconf, but we can be more relaxed for what concerns the Git
>> repository; if this turns out to be a bad idea, we can revert the relevant
>> changes before cutting the 2.70 release out of the repository, no?
> 
> Well, it seems weird to me commit something to master with the caveat
> "we must revert this feature before the next release if it remains
> untestable by that time".  But sure, if the Autoconf maintainer(s)
> want to do it this way then that's totally their prerogative.
> 
> I just want to avoid a repeat of AC_CONFIG_MACRO_DIR where we carry
> around a worthless macro forever because it doesn't behave in any useful
> manner.  As I mentioned a little while ago on this list[1], I actually
> think that, right now, AC_CONFIG_MACRO_DIR has negative value: it has
> a maintenence cost to put it in your configure.ac (mainly due to
> duplication of information in Makefile.am, gratuitously enforced by
> libtoolize) for exactly zero benefit.
>
IMHO, that is no more true after automake commit v1.12.1-165-gcd1a9cc:
<http://git.savannah.gnu.org/cgit/automake.git/commit/?h=ng/master&id=v1.12.1-165-gcd1a9cc>
But of course, the new semantics of AC_CONFIG_MACRO_DIR will be more
powerful (allowing declaration of multiple local m4 directories), so
that's the way to go in the future.

> PS, as I might not have been clear: I think we absolutely can and should
> make this feature work!  I will be happy to delete many occurrences of
> ACLOCAL_AMFLAGS the day that happens.
> 
> [1] http://permalink.gmane.org/gmane.comp.sysutils.automake.patches/8848
> 
> Cheers,

Thanks,
  Stefano
>From a21cf2c1e342ec8888dfd835d77f21f772cd8308 Mon Sep 17 00:00:00 2001
Message-Id: <a21cf2c1e342ec8888dfd835d77f21f772cd8308.1350550930.git.stefano.lattar...@gmail.com>
From: Stefano Lattarini <stefano.lattar...@gmail.com>
Date: Wed, 4 Jul 2012 15:23:50 +0200
Subject: [PATCH 1/2] aclocal: multiple local m4 macro dirs with
 AC_CONFIG_MACRO_DIRS

A new macro 'AC_CONFIG_MACRO_DIRS' has been recently introduced in
autoconf (and is expected to appear in the autoconf 2.70 release),
allowing us to declare several local m4 macro directories for a
package.

It can be done either passing several arguments to a single invocation:

    AC_CONFIG_MACRO_DIRS([dir1 dir2])

or issuing more invocations:

    AC_CONFIG_MACRO_DIRS([dir1])
    AC_CONFIG_MACRO_DIRS([dir2])

or a combination of the two:

    AC_CONFIG_MACRO_DIRS([dir1 dir2])
    AC_CONFIG_MACRO_DIRS([dir3])

This will allow projects to use several m4 macro local dirs, without the
need to use ACLOCAL_AMFLAGS (which we want to make obsolete and finally
remove).  This is especially important for projects that are used as
nested subpackages of larger projects.

For more information, refer to these past discussions:

<http://lists.gnu.org/archive/html/autoconf/2011-12/msg00037.html>
<http://lists.gnu.org/archive/html/automake-patches/2012-07/msg00010.html>
<http://lists.gnu.org/archive/html/autoconf-patches/2012-07/msg00000.html>
<http://lists.gnu.org/archive/html/autoconf-patches/2012-07/msg00012.html>
<http://lists.gnu.org/archive/html/autoconf-patches/2012-10/msg00007.html>

as well as to Automake commit v1.12.1-165-gcd1a9cc of 2012-07-03,
"aclocal: deprecate ACLOCAL_AMFLAGS, trace AC_CONFIG_MACRO_DIR instead".

* aclocal.in ($ac_config_macro_dir): Turn this global scalar it into ...
(@ac_config_macro_dirs): ... this global array.
(trace_used_macros): Update '@ac_config_macro_dirs' instead of
re-defining '$ac_config_macro_dir'.  Cater to calls the now-preferred
macro 'AC_CONFIG_MACRO_DIRS' in addition to the "obsolescent" one
AC_CONFIG_MACRO_DIR.
(main loop): Append '@ac_config_macro_dirs', not '$ac_config_macro_dir',
to '@user_includes'.
* t/subpkg-macrodir.sh: New test.
* t/aclocal-macrodirs.tap: Likewise.
* t/list-of-tests.mk: Add them.
* t/aclocal-macrodir.tap: Adjust and extend a little to keep it more in
sync with 'aclocal-macrodirs.tap'.

Signed-off-by: Stefano Lattarini <stefano.lattar...@gmail.com>
---
 aclocal.in              |  34 ++---
 t/aclocal-macrodir.tap  |  24 +++-
 t/aclocal-macrodirs.tap | 328 ++++++++++++++++++++++++++++++++++++++++++++++++
 t/list-of-tests.mk      |   2 +
 t/subpkg-macrodir.sh    |  93 ++++++++++++++
 5 files changed, 462 insertions(+), 19 deletions(-)
 create mode 100755 t/aclocal-macrodirs.tap
 create mode 100755 t/subpkg-macrodir.sh

diff --git a/aclocal.in b/aclocal.in
index e2e9536..ea96025 100644
--- a/aclocal.in
+++ b/aclocal.in
@@ -52,7 +52,7 @@ $perl_threads = 0;
 # user-supplied directories first, then the directory containing the
 # automake macros, and finally the system-wide directories for
 # third-party macros.
-# @user_includes can be augmented with -I or AC_CONFIG_MACRO_DIR.
+# @user_includes can be augmented with -I or AC_CONFIG_MACRO_DIRS.
 # @automake_includes can be reset with the '--automake-acdir' option.
 # @system_includes can be augmented with the 'dirlist' file or the
 # ACLOCAL_PATH environment variable, and reset with the '--system-acdir'
@@ -146,10 +146,10 @@ my $serial_number_rx = '^\d+(?:\.\d+)*$';
 # Autoconf version.  This variable is set by 'trace_used_macros'.
 my $ac_version;
 
-# Primary user directory containing extra m4 files for macros
-# definition, as extracted from call to macro AC_CONFIG_MACRO_DIR.
-# This variable is set by 'trace_used_macros'.
-my $ac_config_macro_dir;
+# User directory containing extra m4 files for macros definition,
+# as extracted from calls to the macro AC_CONFIG_MACRO_DIRS.
+# This variable is updated by 'trace_used_macros'.
+my @ac_config_macro_dirs;
 
 # If set, names a temporary file that must be erased on abnormal exit.
 my $erase_me;
@@ -731,7 +731,8 @@ sub trace_used_macros ()
 		     'AC_DEFUN_ONCE',
 		     'AU_DEFUN',
 		     '_AM_AUTOCONF_VERSION',
-		     'AC_CONFIG_MACRO_DIR')),
+		     'AC_CONFIG_MACRO_DIR',
+		     'AC_CONFIG_MACRO_DIRS')),
 		   # Do not trace $1 for all other macros as we do
 		   # not need it and it might contains harmful
 		   # characters (like newlines).
@@ -741,7 +742,7 @@ sub trace_used_macros ()
 
   my $tracefh = new Automake::XFile ("$traces $configure_ac |");
 
-  $ac_config_macro_dir = undef;
+  @ac_config_macro_dirs = ();
 
   my %traced = ();
 
@@ -763,7 +764,11 @@ sub trace_used_macros ()
         }
       elsif ($macro eq 'AC_CONFIG_MACRO_DIR')
         {
-          $ac_config_macro_dir = $arg1;
+          @ac_config_macro_dirs = ($arg1);
+        }
+      elsif ($macro eq 'AC_CONFIG_MACRO_DIRS')
+        {
+          push @ac_config_macro_dirs, split (/\s+/, $arg1);
         }
     }
 
@@ -1094,13 +1099,12 @@ while (1)
     last if $exit_code;
     my %macro_traced = trace_used_macros;
 
-    if (!$rerun_due_to_macrodir && defined $ac_config_macro_dir)
+    if (!$rerun_due_to_macrodir && @ac_config_macro_dirs)
       {
-         # The directory specified by the AC_CONFIG_MACRO_DIR m4 macro
-         # (if any) must after the user includes specified explicitly
-         # with the '-I' option.
-         push @user_includes, $ac_config_macro_dir
-           if defined $ac_config_macro_dir;
+        # The directory specified in calls to the AC_CONFIG_MACRO_DIRS
+        # m4 macro (if any) must go after the user includes specified
+        # explicitly with the '-I' option.
+        push @user_includes, @ac_config_macro_dirs;
         # We might have to scan some new directory of .m4 files.
         $rerun_due_to_macrodir++;
         next;
@@ -1109,7 +1113,7 @@ while (1)
     if ($install && !@user_includes)
       {
         fatal "installation of third-party macros impossible without " .
-              "-I options nor AC_CONFIG_MACRO_DIR m4 macro";
+              "-I options nor AC_CONFIG_MACRO_DIR{,S} m4 macro(s)";
       }
 
     last if write_aclocal ($output_file, keys %macro_traced);
diff --git a/t/aclocal-macrodir.tap b/t/aclocal-macrodir.tap
index c35d9e0..667b6c0 100755
--- a/t/aclocal-macrodir.tap
+++ b/t/aclocal-macrodir.tap
@@ -15,12 +15,12 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIR with
-# aclocal.
+# aclocal.  See also related test 'aclocal-macrodir.tap'.
 
 am_create_testdir=empty
 . ./defs || exit 1
 
-plan_ later
+plan_ 5
 
 ocwd=$(pwd) || fatal_ "getting current working directory"
 ACLOCAL_PATH=; unset ACLOCAL_PATH
@@ -44,6 +44,7 @@ test_begin ()
   else
     r=ok
     description=$1
+    directive=${2-}
     echo "$description" > README.txt
     shift
   fi
@@ -68,8 +69,6 @@ test_end ()
   fi
 }
 
-test_todo () { directive=TODO; }
-
 #---------------------------------------------------------------------------
 
 test_begin "AC_CONFIG_MACRO_DIR is honored"
@@ -158,4 +157,21 @@ test_end
 
 #---------------------------------------------------------------------------
 
+test_begin "AC_CONFIG_MACRO_DIR([non-existent]) errors out (1)"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIR([non-existent])
+END
+
+not $ACLOCAL 2>stderr \
+  && cat stderr >&2 \
+  && grep "couldn't open directory 'non-existent'" stderr \
+  || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+
 :
diff --git a/t/aclocal-macrodirs.tap b/t/aclocal-macrodirs.tap
new file mode 100755
index 0000000..e06f26a
--- /dev/null
+++ b/t/aclocal-macrodirs.tap
@@ -0,0 +1,328 @@
+#! /bin/sh
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIRS with
+# aclocal.  See also related test 'aclocal-macrodir.tap'.
+
+am_create_testdir=empty
+. ./defs || exit 1
+
+{ $AUTOCONF -o /dev/null - <<END
+    AC_INIT([x], [0])
+    AC_CONFIG_MACRO_DIRS([.])
+END
+} || skip_all_ "autoconf doesn't define the AC_CONFIG_MACRO_DIRS macro"
+
+plan_ 11
+
+ocwd=$(pwd) || fatal_ "getting current working directory"
+ACLOCAL_PATH=; unset ACLOCAL_PATH
+
+#
+# General utility functions and variables.
+#
+# TODO: These should maybe be refactored, generalized and
+#       moved into 't/ax/tap-functions.sh' ...
+#
+
+tcount=0
+r=invalid
+description=''
+directive=''
+
+test_begin ()
+{
+  if test -n "$description"; then
+    fatal_ "'test_begin' called, but another test seems active already"
+  else
+    r=ok
+    description=$1
+    directive=${2-}
+    echo "$description" > README.txt
+    shift
+  fi
+  tcount=$(($tcount + 1)) && test $tcount -gt 0 \
+    || fatal_ "failed to bump the test count"
+  mkdir $tcount.d
+  cd $tcount.d
+}
+
+test_end ()
+{
+  if test -z "$description"; then
+    fatal_ "'test_end' called, but no test seems active"
+  else
+    cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
+    result_ "$r" -D "$directive" -- "$description"
+    # Don't leave directories for successful subtests hanging around.
+    if test -z "$directive" && test "$r" = ok; then
+      rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
+    fi
+    r=invalid directive= description=
+  fi
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS is honored"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [10.0])
+AC_CONFIG_MACRO_DIRS([macro-dir])
+MY_FOO
+END
+
+mkdir macro-dir
+echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4
+
+$ACLOCAL \
+  && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
+  && $AUTOCONF \
+  && not $FGREP 'MY_FOO' configure \
+  && $FGREP '::my::foo::' configure \
+  || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+two_dirs_check ()
+{
+  if test $have_macrodirs = no; then
+    directive=SKIP
+    reason='AC_CONFIG_MACRO_DIRS not supported'
+    return
+  fi
+  mkdir sys-dir dir1 dir2
+  echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > dir1/foo.m4
+  echo 'AC_DEFUN([MY_BAR], [!!my!!bar!!])' > dir2/zap.m4
+  $ACLOCAL \
+    && $FGREP 'm4_include([dir1/foo.m4])' aclocal.m4 \
+    && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
+    && $AUTOCONF \
+    && not $EGREP 'MY_(FOO|BAR)' configure \
+    && $FGREP '::my::foo::' configure \
+    && $FGREP '!!my!!bar!!' configure \
+    || r='not ok'
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS: several arguments"
+
+cat > configure.ac <<'END'
+AC_INIT([more-args], [0.2])
+AC_CONFIG_MACRO_DIRS([dir1 dir2])
+MY_FOO
+MY_BAR
+END
+
+two_dirs_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS: several calls"
+
+cat > configure.ac <<'END'
+AC_INIT([more-calls], [2.0])
+AC_CONFIG_MACRO_DIRS([dir1])
+AC_CONFIG_MACRO_DIRS([dir2])
+MY_FOO
+MY_BAR
+END
+
+two_dirs_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS interaction with --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst], [1.0])
+AC_CONFIG_MACRO_DIRS([the-dir])
+THE_MACRO
+END
+
+mkdir sys-dir the-dir
+echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
+
+test ! -r the-dir/my.m4 \
+  && $ACLOCAL --install --system-acdir ./sys-dir \
+  && diff sys-dir/my.m4 the-dir/my.m4 \
+  || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+two_dirs_install_check ()
+{
+  if test $have_macrodirs = no; then
+    directive=SKIP
+    reason='AC_CONFIG_MACRO_DIRS not supported'
+    return
+  fi
+  mkdir sys-dir dir1 dir2
+  echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
+  echo 'AC_DEFUN([AX_FOO], [:])' > dir2/zap.m4
+  test ! -r dir1/my.m4 \
+    && $ACLOCAL --install --system-acdir ./sys-dir \
+    && diff sys-dir/my.m4 dir1/my.m4 \
+    && test ! -e dir2/my.m4 \
+    && $FGREP 'm4_include([dir1/my.m4])' aclocal.m4 \
+    && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
+    || r='not ok'
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "several AC_CONFIG_MACRO_DIRS arguments and --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst2a], [1.0])
+AC_CONFIG_MACRO_DIRS([dir1 dir2])
+THE_MACRO
+AX_FOO
+END
+
+two_dirs_install_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+
+test_begin "several AC_CONFIG_MACRO_DIRS calls and --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst2b], [1.0])
+AC_CONFIG_MACRO_DIRS([dir1])
+AC_CONFIG_MACRO_DIRS([dir2])
+THE_MACRO
+AX_FOO
+END
+
+two_dirs_install_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "'-I' option wins over AC_CONFIG_MACRO_DIRS"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [4.6])
+AC_CONFIG_MACRO_DIRS([dir1])
+MY_FOO
+END
+
+mkdir dir1 dir2
+echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
+echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
+
+$ACLOCAL -I dir2 \
+  && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
+  && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
+  && $AUTOCONF \
+  && not $FGREP '::ko::ko::' configure \
+  && $FGREP '::ok::ok::' configure \
+  || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([foo]) can create directory 'foo'"
+
+cat > configure.ac << 'END'
+AC_INIT([x], [1.0])
+AC_CONFIG_MACRO_DIRS([foo])
+MY_MACRO
+END
+
+mkdir acdir
+echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
+
+test ! -d foo \
+  && $ACLOCAL --install --system-acdir ./acdir \
+  && diff acdir/bar.m4 foo/bar.m4 \
+  || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (1)"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([non-existent])
+END
+
+not $ACLOCAL 2>stderr \
+  && cat stderr >&2 \
+  && grep "couldn't open directory 'non-existent'" stderr \
+  || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (2)"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([dir-ok])
+AC_CONFIG_MACRO_DIRS([dir-ko])
+END
+
+mkdir dir-ok
+not $ACLOCAL 2>stderr \
+  && cat stderr >&2 \
+  && grep "couldn't open directory 'dir-ko'" stderr \
+  && not grep "dir-ok" stderr \
+  || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (tricky setup)" \
+           TODO
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([dir-ok])
+AC_CONFIG_MACRO_DIRS([dir-ko])
+END
+
+mkdir dir-ok
+
+not $ACLOCAL --install 2>stderr \
+  && cat stderr >&2 \
+  && grep "couldn't open directory 'dir-ko'" stderr \
+  && test ! -e dir-ko \
+  || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+:
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index c3b8cf4..664b450 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -98,6 +98,7 @@ t/acloca23.sh \
 t/aclocal-acdir.sh \
 t/aclocal-install-absdir.sh \
 t/aclocal-macrodir.tap \
+t/aclocal-macrodirs.tap \
 t/aclocal-amflags.sh \
 t/aclocal-print-acdir.sh \
 t/aclocal-path.sh \
@@ -1044,6 +1045,7 @@ t/subpkg2.sh \
 t/subpkg3.sh \
 t/subpkg4.sh \
 t/subpkg-yacc.sh \
+t/subpkg-macrodir.sh \
 t/subst.sh \
 t/subst3.sh \
 t/subst4.sh \
diff --git a/t/subpkg-macrodir.sh b/t/subpkg-macrodir.sh
new file mode 100755
index 0000000..d161d2c
--- /dev/null
+++ b/t/subpkg-macrodir.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2002-2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Subpackages that want to use m4 macros from their superpackages,
+# with AC_CONFIG_MACRO_DIRS.
+
+. ./defs || exit 1
+
+{ $AUTOCONF -o /dev/null - <<END
+    AC_INIT([x], [0])
+    AC_CONFIG_MACRO_DIRS([.])
+END
+} || skip_ "autoconf doesn't define the AC_CONFIG_MACRO_DIRS macro"
+
+cat > configure.ac <<'END'
+AC_INIT([super], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SUBDIRS([pkg])
+AX_BAR
+AX_FOO
+END
+
+mkdir m4
+
+cat > m4/foo.m4 <<'EOF'
+AC_DEFUN([AX_FOO], [
+  AC_CONFIG_FILES([Makefile])
+  AC_OUTPUT
+])
+EOF
+
+cat > m4/bar.m4 <<'EOF'
+AC_DEFUN([AX_BAR], [AC_SUBST([WHOMAI], [SuperPkg])])
+EOF
+
+cat > Makefile.am << 'END'
+test-whomai:
+	test '$(WHOAMI)' = SuperPkg
+check-local: test
+.PHONY: test
+END
+
+mkdir pkg
+
+cat > pkg/configure.ac <<'END'
+AC_INIT([super], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIRS([macros ../m4])
+AX_BAR
+AX_FOO
+END
+
+mkdir pkg/macros
+cat > pkg/macros/zardoz.m4 << 'END'
+AC_DEFUN([AX_BAR], [AC_SUBST([WHOMAI], [sub-pkg])])
+END
+
+cat > pkg/Makefile.am << 'END'
+test-whomai:
+	test '$(WHOAMI)' = sub-pkg
+check-local: test
+.PHONY: test
+END
+
+AUTOMAKE=$AUTOMAKE ACLOCAL=$ACLOCAL AUTOCONF=$AUTOCONF $AUTORECONF -vi
+
+$FGREP 'm4_include([m4/foo.m4])' aclocal.m4
+$FGREP 'm4_include([m4/bar.m4])' aclocal.m4
+$FGREP 'm4_include([../m4/foo.m4])' pkg/aclocal.m4
+$FGREP 'm4_include([macros/zardoz.m4])' pkg/aclocal.m4
+
+./configure
+
+$MAKE test
+(cd pkg && $MAKE test) || exit 1
+
+$MAKE distcheck
+
+:
-- 
1.8.0.rc2.11.gd25c58c

>From dfc79c73944464473e179e0a13252a5eadcb6d54 Mon Sep 17 00:00:00 2001
Message-Id: <dfc79c73944464473e179e0a13252a5eadcb6d54.1350550930.git.stefano.lattar...@gmail.com>
In-Reply-To: <a21cf2c1e342ec8888dfd835d77f21f772cd8308.1350550930.git.stefano.lattar...@gmail.com>
References: <a21cf2c1e342ec8888dfd835d77f21f772cd8308.1350550930.git.stefano.lattar...@gmail.com>
From: Stefano Lattarini <stefano.lattar...@gmail.com>
Date: Wed, 4 Jul 2012 15:37:46 +0200
Subject: [PATCH 2/2] aclocal: diagnose non-existing directories in
 AC_CONFIG_MACRO_DIRS better

This new implementation ensures that any directory (possibly excluding
the first one, if the '--install' option is used) that is declared with
AC_CONFIG_MACRO_DIRS and that is non-existent will cause an error from
aclocal.

* aclocal.in (scan_m4_dirs): Add a new argument, telling whether it's OK
for the scanned directory to be non-existing.  Adjust the implementation
accordingly.
($first_user_m4dir): Remove, no more needed.
(scan_m4_files): Update 'scan_m4_dirs' invocations so that aclocal will
not complain if the first user macro directory is non-existing and the
'--install' option is given: such directory will be created later by
aclocal itself.
* t/aclocal-macrodir.tap: Do not mark the last test as TODO anymore;
it now passes.  Make stricter by ensuring a non-existing directory in
AC_CONFIG_MACRO_DIRS causes an hard error, not a warning.

Signed-off-by: Stefano Lattarini <stefano.lattar...@gmail.com>
---
 aclocal.in              | 35 +++++++++++++++++------------------
 t/aclocal-macrodir.tap  |  3 +--
 t/aclocal-macrodirs.tap |  5 ++---
 3 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/aclocal.in b/aclocal.in
index ea96025..751ab49 100644
--- a/aclocal.in
+++ b/aclocal.in
@@ -164,7 +164,7 @@ sub check_acinclude ();
 sub reset_maps ();
 sub install_file ($$);
 sub list_compare (\@\@);
-sub scan_m4_dirs ($@);
+sub scan_m4_dirs ($$@);
 sub scan_m4_files ();
 sub add_macro ($);
 sub scan_configure_dep ($);
@@ -344,28 +344,20 @@ sub list_compare (\@\@)
 
 ################################################################
 
-# scan_m4_dirs($TYPE, @DIRS)
-# --------------------------
+# scan_m4_dirs($TYPE, $ERR_ON_NONEXISTING, @DIRS)
+# -----------------------------------------------
 # Scan all M4 files installed in @DIRS for new macro definitions.
 # Register each file as of type $TYPE (one of the FT_* constants).
-my $first_user_m4dir = 1;
-sub scan_m4_dirs ($@)
+sub scan_m4_dirs ($$@)
 {
-  my ($type, @dirlist) = @_;
+  my ($type, $err_on_nonexisting, @dirlist) = @_;
 
   foreach my $m4dir (@dirlist)
     {
       if (! opendir (DIR, $m4dir))
 	{
-	  if ($install && $type == FT_USER && $first_user_m4dir)
-            {
-              # We will try to create this directory later, so don't
-              # complain if it doesn't exist.
-              # TODO: maybe we should avoid complaining only if errno
-              # is ENONENT?
-              $first_user_m4dir = 0;
-              next;
-            }
+	  # TODO: maybe avoid complaining only if errno == ENONENT?
+	  next unless $err_on_nonexisting;
 	  fatal "couldn't open directory '$m4dir': $!";
 	}
 
@@ -400,9 +392,16 @@ sub scan_m4_files ()
     }
 
   # Finally, scan all files in our search paths.
-  scan_m4_dirs (FT_USER, @user_includes);
-  scan_m4_dirs (FT_AUTOMAKE, @automake_includes);
-  scan_m4_dirs (FT_SYSTEM, @system_includes);
+
+  if (@user_includes)
+    {
+      # Don't complain if the first user directory doesn't exist, in case
+      # we need to create it later (can happen if '--install' was given).
+      scan_m4_dirs (FT_USER, !$install, $user_includes[0]);
+      scan_m4_dirs (FT_USER, 1, @user_includes[1..$#user_includes]);
+    }
+  scan_m4_dirs (FT_AUTOMAKE, 1, @automake_includes);
+  scan_m4_dirs (FT_SYSTEM,   1, @system_includes);
 
   # Construct a new function that does the searching.  We use a
   # function (instead of just evaluating $search in the loop) so that
diff --git a/t/aclocal-macrodir.tap b/t/aclocal-macrodir.tap
index 667b6c0..a206953 100755
--- a/t/aclocal-macrodir.tap
+++ b/t/aclocal-macrodir.tap
@@ -164,7 +164,7 @@ AC_INIT([oops], [1.0])
 AC_CONFIG_MACRO_DIR([non-existent])
 END
 
-not $ACLOCAL 2>stderr \
+not $ACLOCAL -Wnone 2>stderr \
   && cat stderr >&2 \
   && grep "couldn't open directory 'non-existent'" stderr \
   || r='not ok'
@@ -173,5 +173,4 @@ test_end
 
 #---------------------------------------------------------------------------
 
-
 :
diff --git a/t/aclocal-macrodirs.tap b/t/aclocal-macrodirs.tap
index e06f26a..a0eeb96 100755
--- a/t/aclocal-macrodirs.tap
+++ b/t/aclocal-macrodirs.tap
@@ -304,8 +304,7 @@ test_end
 
 #---------------------------------------------------------------------------
 
-test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (tricky setup)" \
-           TODO
+test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (tricky setup)"
 
 cat > configure.ac << 'END'
 AC_INIT([oops], [1.0])
@@ -315,7 +314,7 @@ END
 
 mkdir dir-ok
 
-not $ACLOCAL --install 2>stderr \
+not $ACLOCAL -Wnone --install 2>stderr \
   && cat stderr >&2 \
   && grep "couldn't open directory 'dir-ko'" stderr \
   && test ! -e dir-ko \
-- 
1.8.0.rc2.11.gd25c58c

Reply via email to