@defmacx AC_CONFIG_MACRO_DIR (@var{dir})
@acindex{CONFIG_MACRO_DIRS}
@acindex{CONFIG_MACRO_DIR}
+@acindex{CONFIG_MACRO_DIR_TRACE}
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{configure.ac} 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
+@code{AC_CONFIG_MACRO_DIR_TRACE}, 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
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
## ------------------------ ##
+# AC_CONFIG_MACRO_DIR_TRACE(DIR)
+# ------------------------------
+# This macro exists solely for tracing - never invoke it directly.
+# It will be called once per directory listed in either form of
+# AC_CONFIG_MACRO_DIR[S].
+m4_define([AC_CONFIG_MACRO_DIR_TRACE],
+[m4_fatal([Do not invoke $0 directly])])
+
+# _AC_CONFIG_MACRO_DIRS_USED
+# --------------------------
+# Internal witness macro, redefined to empty after first directory is traced.
+m4_define([_AC_CONFIG_MACRO_DIRS_USED], [-])
+
+# _AC_CONFIG_MACRO_DIRS(CALLER, DIR)
+# ----------------------------------
+# Internal workhorse macro to ensure a sane calling pattern of CALLER, and
+# eventually trace DIR through the documented public trace point.
+m4_define([_AC_CONFIG_MACRO_DIRS],
+[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
+[[AC_CONFIG_MACRO_DIR_TRACE([$2])m4_popdef([AC_CONFIG_MACRO_DIR_TRACE])])])
+
# AC_CONFIG_MACRO_DIRS(DIR-1 [DIR-2 ... DIR-n])
# --------------------------------------------
# Declare directories containing additional macros for aclocal.
# This macro can be called multiple times, and with multiple arguments.
-AC_DEFUN([AC_CONFIG_MACRO_DIRS], [])
+# 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.
+AC_DEFUN([AC_CONFIG_MACRO_DIRS],
+[m4_map_args_w([$1], [_$0(_$0_USED()[$0], ], [)])])
# AC_CONFIG_MACRO_DIR(DIR)
# ------------------------
# Declare directory containing additional macros for aclocal.
-# This is obsoleted by AC_CONFIG_MACRO_DIRS, and kept only for
-# backward compatibility.
-AC_DEFUN([AC_CONFIG_MACRO_DIR], [])
+# 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.
+AC_DEFUN([AC_CONFIG_MACRO_DIR],
+[_$0S(_$0S_USED()[$0], [$1])])
## --------------------- ##
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
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
AT_CLEANUP
+# autoconf --trace: AC_CONFIG_MACRO_DIRS
+# --------------------------------------
+AT_SETUP([autoconf --trace: AC_CONFIG_MACRO_DIRS])
+AT_KEYWORDS([AC_CONFIG_MACRO_DIR AC_CONFIG_MACRO_DIR_TRACE])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_MACRO_DIR([dir1])
+AC_CONFIG_MACRO_DIRS([dir2 dir3 \
+dir4])
+AC_CONFIG_MACRO_DIRS([dir5])
+]])
+
+# Legacy tracing
+AT_CHECK_AUTOCONF([-t AC_CONFIG_MACRO_DIR], 0,
+[[configure.ac:2:AC_CONFIG_MACRO_DIR:dir1
+]])
+
+# Preferred tracing
+AT_CHECK_AUTOCONF([-t AC_CONFIG_MACRO_DIR_TRACE], 0,
+[[configure.ac:2:AC_CONFIG_MACRO_DIR_TRACE:dir1
+configure.ac:3:AC_CONFIG_MACRO_DIR_TRACE:dir2
+configure.ac:3:AC_CONFIG_MACRO_DIR_TRACE:dir3
+configure.ac:3:AC_CONFIG_MACRO_DIR_TRACE:dir4
+configure.ac:5:AC_CONFIG_MACRO_DIR_TRACE:dir5
+]])
+
+# Legacy macro can only be used once
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_MACRO_DIR([dir1])
+AC_CONFIG_MACRO_DIR([dir2])
+]])
+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_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_MACRO_DIRS([dir1])
+AC_CONFIG_MACRO_DIR([dir2])
+]])
+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_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_MACRO_DIR_TRACE([dir1])
+]])
+AT_CHECK_AUTOCONF([], [1], [],
+[[configure.ac:2: error: Do not invoke AC_CONFIG_MACRO_DIR_TRACE directly
+configure.ac:2: the top level
+autom4te: m4 failed with exit status: 1
+]])
+
+# Legacy macro use is not required, but still gets traced
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_MACRO_DIRS([dir1])
+AC_CONFIG_MACRO_DIRS([dir2])
+]])
+AT_CHECK_AUTOCONF([], [0], [], [])
+AT_CHECK_AUTOCONF([-t AC_CONFIG_MACRO_DIR], [0],
+[[configure.ac:2:AC_CONFIG_MACRO_DIR:dir1
+]])
+
+AT_CLEANUP
+
## ---------------------------- ##
## autoconf: forbidden tokens. ##