automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCHv2 1/8] aclocal: multiple local m4 macro dirs with AC_CONFIG_MACRO


From: Stefano Lattarini
Subject: [PATCHv2 1/8] aclocal: multiple local m4 macro dirs with AC_CONFIG_MACRO_DIRS
Date: Sat, 10 Nov 2012 14:55:50 +0100

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 and rationales, 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://thread.gmane.org/gmane.comp.sysutils.autoconf.patches/8037/>
<http://thread.gmane.org/gmane.comp.sysutils.autoconf.patches/8087>
<http://thread.gmane.org/gmane.comp.sysutils.automake.patches/8956>

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",
autoconf commit v2.69-42-gd73770f of 2012-10-17, "AC_CONFIG_MACRO_DIRS:
new macro, mostly for aclocal".

* 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 <address@hidden>
---
 aclocal.in              |  34 +++---
 t/aclocal-macrodir.tap  |  24 +++-
 t/aclocal-macrodirs.tap | 318 ++++++++++++++++++++++++++++++++++++++++++++++++
 t/list-of-tests.mk      |   2 +
 t/subpkg-macrodir.sh    |  93 ++++++++++++++
 5 files changed, 452 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 && address@hidden)
       {
         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 3daedad..5ef1ee4 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
 . test-init.sh
 
-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..aaac4b4
--- /dev/null
+++ b/t/aclocal-macrodirs.tap
@@ -0,0 +1,318 @@
+#! /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
+. test-init.sh
+
+{ $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 ()
+{
+  mkdir 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 ()
+{
+  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 89ec37d..9651dc7 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 \
@@ -1035,6 +1036,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..275af0d
--- /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.
+
+. test-init.sh
+
+{ $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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]