automake-patches
[Top][All Lists]
Advanced

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

[PATCH 1/2] aclocal: multiple local m4 macro dirs with AC_CONFIG_MACRO_D


From: Stefano Lattarini
Subject: [PATCH 1/2] aclocal: multiple local m4 macro dirs with AC_CONFIG_MACRO_DIR
Date: Wed, 4 Jul 2012 17:24:58 +0200

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

    AC_CONFIG_MACRO_DIR([dir1 dir2])

or issuing more invocations:

    AC_CONFIG_MACRO_DIR([dir1])
    AC_CONFIG_MACRO_DIR([dir2])

This will allow projects to use several m4 macro local dirs.  This is
especially important for projects that are used as nested subpackages
of larger projects.

Autoconf will soon follow suit, with a new macro AC_CONFIG_MACRO_DIRS.
Once that has been implemented in their git repo, we will start to
support it as well.

See also:
<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>

* 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 multiple arguments in AC_CONFIG_MACRO_DIR
and to multiple AC_CONFIG_MACRO_DIR invocations.
(main loop): Append '@ac_config_macro_dirs', not '$ac_config_macro_dir',
to '@user_includes'.
* t/aclocal-macrodir.tap: Extend and enhance.
* t/subpkg-macrodir.sh: New test.
* t/list-of-tests.mk: Add it.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 aclocal.in             |   23 ++++---
 t/aclocal-macrodir.tap |  159 ++++++++++++++++++++++++++++++++++++++++++++++--
 t/list-of-tests.mk     |    1 +
 t/subpkg-macrodir.sh   |   88 +++++++++++++++++++++++++++
 4 files changed, 255 insertions(+), 16 deletions(-)
 create mode 100755 t/subpkg-macrodir.sh

diff --git a/aclocal.in b/aclocal.in
index e2e9536..46286bb 100644
--- a/aclocal.in
+++ b/aclocal.in
@@ -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_DIR.
+# 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;
@@ -741,7 +741,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 +763,7 @@ sub trace_used_macros ()
         }
       elsif ($macro eq 'AC_CONFIG_MACRO_DIR')
         {
-          $ac_config_macro_dir = $arg1;
+          push @ac_config_macro_dirs, split (/\s+/, $arg1);
         }
     }
 
@@ -1094,13 +1094,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_DIR
+        # 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;
diff --git a/t/aclocal-macrodir.tap b/t/aclocal-macrodir.tap
index c35d9e0..aa59c40 100755
--- a/t/aclocal-macrodir.tap
+++ b/t/aclocal-macrodir.tap
@@ -20,7 +20,7 @@
 am_create_testdir=empty
 . ./defs || exit 1
 
-plan_ later
+plan_ 11
 
 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"
@@ -94,7 +93,55 @@ test_end
 
 #---------------------------------------------------------------------------
 
-test_begin "AC_CONFIG_MACRO_DIR([foo]) interaction with --install"
+two_dirs_check ()
+{
+  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_DIR: several arguments"
+
+cat > configure.ac <<'END'
+AC_INIT([more-args], [0.2])
+AC_CONFIG_MACRO_DIR([dir1 dir2])
+MY_FOO
+MY_BAR
+END
+
+two_dirs_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR: several calls"
+
+cat > configure.ac <<'END'
+AC_INIT([more-calls], [2.0])
+AC_CONFIG_MACRO_DIR([dir1])
+AC_CONFIG_MACRO_DIR([dir2])
+MY_FOO
+MY_BAR
+END
+
+two_dirs_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR interaction with --install"
 
 cat > configure.ac << 'END'
 AC_INIT([inst], [1.0])
@@ -114,6 +161,54 @@ 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_DIR arguments and --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst2a], [1.0])
+AC_CONFIG_MACRO_DIR([dir1 dir2])
+THE_MACRO
+AX_FOO
+END
+
+two_dirs_install_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+
+test_begin "several AC_CONFIG_MACRO_DIR calls and --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst2b], [1.0])
+AC_CONFIG_MACRO_DIR([dir1])
+AC_CONFIG_MACRO_DIR([dir2])
+THE_MACRO
+AX_FOO
+END
+
+two_dirs_install_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
 test_begin "'-I' option wins over AC_CONFIG_MACRO_DIR"
 
 cat > configure.ac <<'END'
@@ -158,4 +253,60 @@ 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
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR([non-existent]) errors out (2)"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIR([dir-ok])
+AC_CONFIG_MACRO_DIR([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_DIR([non-existent]) errors out (tricky setup)" \
+           TODO
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIR([dir-ok])
+AC_CONFIG_MACRO_DIR([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 fdb4878..b747dca 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -1044,6 +1044,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..c171475
--- /dev/null
+++ b/t/subpkg-macrodir.sh
@@ -0,0 +1,88 @@
+#! /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_DIR.
+
+. ./defs || exit 1
+
+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_DIR([macros])
+AC_CONFIG_MACRO_DIR([../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 || exit 1
+(cd pkg && $MAKE test) || exit 1
+
+$MAKE distcheck
+
+:
-- 
1.7.9.5




reply via email to

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