at the beginning of a macro. You can use @code{dnl} to avoid the empty
lines they leave.
+Autoconf will normally warn if an @code{AC_REQUIRE} call refers to a
+macro that has not been defined. However, the @command{aclocal} tool
+relies on parsing an incomplete set of input files to trace which macros
+have been required, in order to then pull in additional files that
+provide those macros; for this particular use case, pre-defining the
+macro @code{m4_require_silent_probe} will avoid the warnings.
+
@node Suggested Ordering
@subsection Suggested Ordering
@cindex Macros, ordering
#
# This is called frequently, so minimize the number of macro invocations
# by avoiding dnl and other overhead on the common path.
+# The use of a witness macro protecting the warning allows aclocal
+# to silence any warnings when probing for what macros are required
+# and must therefore be located, when using the Autoconf-without-aclocal-m4
+# autom4te language. For more background, see:
+# https://lists.gnu.org/archive/html/automake-patches/2012-11/msg00035.html
m4_define([_m4_require_call],
[m4_pushdef([_m4_divert_grow], m4_decr(_m4_divert_grow))]dnl
[m4_pushdef([_m4_diverting([$1])])m4_pushdef([_m4_diverting], [$1])]dnl
[m4_divert_push(_m4_divert_grow, [-])]dnl
[m4_if([$2], [], [$1], [$2])
m4_provide_if([$1], [m4_set_remove([_m4_provide], [$1])],
- [m4_warn([syntax], [$1 is m4_require'd but not m4_defun'd])])]dnl
+ [m4_ifndef([m4_require_silent_probe],
+ [m4_warn([syntax], [$1 is m4_require'd but not m4_defun'd])])])]dnl
[_m4_divert_raw($3)_m4_undivert(_m4_divert_grow)]dnl
[m4_divert_pop(_m4_divert_grow)_m4_popdef([_m4_divert_grow],
[_m4_diverting([$1])], [_m4_diverting])])
AT_CLEANUP
+## ----------------------------- ##
+## m4_require: warning message. ##
+## ----------------------------- ##
+
+AT_SETUP([m4@&t@_require: warning message])
+AT_KEYWORDS([m4@&t@_require m4@&t@_require_silent_probe])
+
+# Mirror the job of aclocal on a typical scenario: the user invokes a
+# single macro that comes from one included file, which in turn requires
+# another macro from a second file. When using the incomplete set of
+# files, we want a warning, unless we are merely learning which additional
+# macros are needed in order to regenerate the list of files to include.
+AT_DATA_M4SUGAR([script.4s],
+[[m4_init
+m4_include([script1.4s])
+foo
+]])
+
+AT_DATA_M4SUGAR([script1.4s],
+[[m4_defun([foo], [m4_require([bar])])
+]])
+
+AT_DATA_M4SUGAR([script2.4s],
+[[m4_defun([bar], [BAR])
+]])
+
+AT_CHECK_M4SUGAR([], [0], [],
+[[script.4s:3: warning: bar is m4@&t@_require'd but not m4@&t@_defun'd
+script1.4s:1: foo is expanded from...
+script.4s:3: the top level
+]])
+
+# Inline expansion of AT_CHECK_M4SUGAR, mirroring how aclocal will
+# inject a definition of our witness macro for a silent run.
+echo 'm4@&t@_define([m4@&t@_require_silent_probe])' |
+ AT_CHECK_AUTOM4TE([--language=m4sugar - script.4s -o script],
+[0], [], [])
+
+# Now that we have recomputed the set of include files, things should work.
+AT_DATA_M4SUGAR([script.4s],
+[[m4_init
+m4_include([script1.4s])
+m4_include([script2.4s])
+foo
+]])
+
+AT_CHECK_M4SUGAR([], [0], [], [])
+
+AT_CLEANUP
+
+
## ----------------------------------- ##
## m4_require: circular dependencies. ##
## ----------------------------------- ##