[Top][All Lists]

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

[PATCH] AC_CONFIG_MACRO_DIRS: improve tracing and add sanity checks

From: Eric Blake
Subject: [PATCH] AC_CONFIG_MACRO_DIRS: improve tracing and add sanity checks
Date: Fri, 9 Nov 2012 15:53:02 -0700

Too many legacy tools exist for us to unilaterally quit supporting
AC_CONFIG_MACRO_DIR - it is feasible for someone to want their
package to bootstrap with both automake 1.13 and libtool 2.4.2,
where the newer automake will only trace the new style of multiple
directory listings, but the older libtool does a sed and settles
on the one use of the old name.  So, we let both macros forward
to a new tracing macro, which also has the benefit of sanitizing
calls into one directory per trace; we also ensure that the old
macro is always traced, and appears at most once and before any
use of the new macro.

* doc/autoconf.texi (Input) <AC_CONFIG_MACRO_DIRS>: Document how
to trace this macro.
* lib/ (Autoreconf-preselections)
(Automake-preselections): Preselect this trace.
* lib/autoconf/general.m4 (AC_CONFIG_MACRO_DIR_TRACE): New trace.
* tests/ (autoconf --trace: AC_CONFIG_MACRO_DIRS): New
 doc/autoconf.texi       |  8 ++++--
 lib/autoconf/general.m4 | 37 +++++++++++++++++++++++---
 lib/         |  2 ++
 tests/          | 71 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 112 insertions(+), 6 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index ff8298a..d1483b8 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -2114,11 +2114,14 @@ Input
 @defmacx AC_CONFIG_MACRO_DIR (@var{dir})
 Specify the given directories as the location of additional local Autoconf
 macros.  These macros are intended for use by commands like
 @command{autoreconf} or @command{aclocal} that trace macro calls; they should
 be called directly from @file{} so that tools that install
-macros for @command{aclocal} can find the macros' declarations.
+macros for @command{aclocal} can find the macros' declarations.  Tools
+that want to learn which directories have been selected should trace
address@hidden, which will be called once per directory.

 AC_CONFIG_MACRO_DIRS is the preferred form, and can be called multiple
 times and with multiple arguments; in such cases, directories in earlier
@@ -2135,7 +2138,8 @@ Input
 AC_CONFIG_MACRO_DIRS([dir3 dir4])
 @end smallexample

-should cause the directories to be searched in this order:
+will cause the trace of AC_CONFIG_MACRO_DIR_TRACE to appear four times,
+and should cause the directories to be searched in this order:
 @samp{dir1 dir2 dir3 dir4}.

 Note that if you use @command{aclocal} from an Automake release prior to
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 96deb1e..5bc7f83 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -1727,18 +1727,47 @@ AC_PROVIDE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
 ## ------------------------ ##

+# ------------------------------
+# This macro exists solely for tracing - never invoke it directly.
+# It will be called once per directory listed in either form of
+[m4_fatal([Do not invoke $0 directly])])
+# --------------------------
+# Internal witness macro, redefined to empty after first directory is traced.
+m4_define([_AC_CONFIG_MACRO_DIRS_USED], [-])
+# ----------------------------------
+# Internal workhorse macro to ensure a sane calling pattern of CALLER, and
+# eventually trace DIR through the documented public trace point.
+[m4_if([$1], [-AC_CONFIG_MACRO_DIRS], [AC_CONFIG_MACRO_DIR([$2])],
+       [$1], [AC_CONFIG_MACRO_DIR], [m4_fatal([$1 can only be used once])],
+  [m4_define([$0_USED])m4_pushdef([AC_CONFIG_MACRO_DIR_TRACE])]]dnl
 # --------------------------------------------
 # Declare directories containing additional macros for aclocal.
 # This macro can be called multiple times, and with multiple arguments.
+# Do not trace this macro; instead trace AC_CONFIG_MACRO_DIR_TRACE.
+# If no directory has been traced yet, then this macro also triggers
+# a trace of AC_CONFIG_MACRO_DIR on the first directory.
+[m4_map_args_w([$1], [_$0(_$0_USED()[$0], ], [)])])

 # ------------------------
 # Declare directory containing additional macros for aclocal.
-# This is obsoleted by AC_CONFIG_MACRO_DIRS, and kept only for
-# backward compatibility.
+# This macro exists for backward compatibility; while tools can trace this,
+# we recommend tracing AC_CONFIG_MACRO_DIR_TRACE instead.  This macro can
+# only be used once, and must not be used after AC_CONFIG_MACRO_DIRS.
+[_$0S(_$0S_USED()[$0], [$1])])

 ## --------------------- ##
diff --git a/lib/ b/lib/
index 1eb1709..cd621a2 100644
--- a/lib/
+++ b/lib/
@@ -42,6 +42,7 @@ args: --preselect AC_CONFIG_FILES
 args: --preselect AC_CONFIG_HEADERS
 args: --preselect AC_CONFIG_LIBOBJ_DIR
 args: --preselect AC_CONFIG_LINKS
+args: --preselect AC_CONFIG_MACRO_DIR_TRACE
 args: --preselect AC_FC_FREEFORM
 args: --preselect AC_FC_SRCEXT
 args: --preselect AC_FC_PP_DEFINE
@@ -93,6 +94,7 @@ end-language: "Automake-preselections"
 begin-language: "Autoreconf-preselections"
 args: --preselect AC_CONFIG_AUX_DIR
 args: --preselect AC_CONFIG_HEADERS
+args: --preselect AC_CONFIG_MACRO_DIR_TRACE
 args: --preselect AC_CONFIG_SUBDIRS
 args: --preselect AC_INIT
 args: --preselect AC_PROG_LIBTOOL
diff --git a/tests/ b/tests/
index 4ffe3da..675cdfd 100644
--- a/tests/
+++ b/tests/
@@ -358,6 +358,77 @@ AT_CHECK_AUTOCONF([[-t define:'$1' -i| sed -n '$p']],

+# autoconf --trace: AC_CONFIG_MACRO_DIRS
+# --------------------------------------
+AT_SETUP([autoconf --trace: AC_CONFIG_MACRO_DIRS])
+AC_CONFIG_MACRO_DIRS([dir2 dir3 \
+# Legacy tracing
+# Preferred tracing
+# Legacy macro can only be used once
+AT_CHECK_AUTOCONF([], [1], [], [stderr])
+AT_CHECK([grep 'error: AC_CONFIG_MACRO_DIR can only be used once' stderr],
+[], [ignore])
+# Legacy macro must be used first, if present
+AT_CHECK_AUTOCONF([], [1], [], [stderr])
+AT_CHECK([grep 'error: AC_CONFIG_MACRO_DIR can only be used once' stderr],
+[], [ignore])
+# Only use the public macros
+AT_CHECK_AUTOCONF([], [1], [],
+[[ error: Do not invoke AC_CONFIG_MACRO_DIR_TRACE directly the top level
+autom4te: m4 failed with exit status: 1
+# Legacy macro use is not required, but still gets traced
+AT_CHECK_AUTOCONF([], [0], [], [])

 ## ---------------------------- ##
 ## autoconf: forbidden tokens.  ##

reply via email to

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