summaryrefslogtreecommitdiff
path: root/lib/autoconf/functions.m4
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2020-06-29 18:55:39 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2020-06-29 23:17:15 -0700
commitd330dd62730234b1f1eafaf3a946cbebf8c6503a (patch)
tree69103942361311629d9e768515ca735ef6bec8f4 /lib/autoconf/functions.m4
parent25014b40e0a9d194f87e6047c394e9a45b5ae938 (diff)
downloadautoconf-d330dd62730234b1f1eafaf3a946cbebf8c6503a.tar.gz
AC_REPLACE_FUNCS: invoke _AH_CHECK_FUNC and AC_LIBSOURCE unconditionally.
While investigating something else, I noticed that AC_REPLACE_FUNCS calls _AH_CHECK_FUNC and AC_LIBSOURCE in the success branch of an AC_CHECK_FUNC. This doesn’t work; both of those are marker macros that need to be expanded unconditionally at m4 time so that traces (placed by autoheader and automake, respectively) will fire. In order to fix this while keeping the code readable, I would up doing a major refactor. There are now four internal macros implementing AC_REPLACE_FUNCS. _AC_REPLACE_FUNC_U is called unconditionally for every shell word in the list passed to AC_REPLACE_FUNCS, and does _AH_CHECK_FUNC + AC_LIBSOURCE if it can, or issues a warning if it can’t. (It could make sense to make this a public function, if we think shell variables in the AC_REPLACE_FUNCS list need to be supported long-term. I dunno if there’s a use case that can’t be handled by AC_REPLACE_FUNCS inside a shell conditional just as well.) _AC_REPLACE_FUNC_L and _AC_REPLACE_FUNC_NL implement the actual test performed for each function to be replaced; the difference is that _L (for literal) can only be used on a function whose name is known at m4 expansion time, _NL (nonliteral) works regardless. _AC_REPLACE_FUNCS, which already existed, handles looping either at m4 time or shell time as appropriate. AC_REPLACE_FUNCS remains a thin wrapper that runs _AC_REPLACE_FUNCS(m4_flatten([$1])). The _bulk_ of the patch is changes to the testsuite so that it notices the original bug. Specifically, AT_CHECK_AUTOHEADER now takes an argument which is a whitespace-separated list of preprocessor macro names that ought to appear in the generated config.h.in. This can be set to ‘ignore’ to skip the test, and unfortunately that’s what the “trivial” per-macro tests have to do (AT_CHECK_MACRO and friends), so coverage is not ideal, but it’s better than what we had. Also, AT_CHECK_M4 now normalizes the backtrace lines that appear in the output of an AC_DIAGNOSE, e.g. configure.ac:6: warning: The macro `AC_LANG_SAVE' is obsolete. configure.ac:6: You should run autoupdate. ../../lib/autoconf/lang.m4:125: AC_LANG_SAVE is expanded from... configure.ac:6: the top level becomes configure.ac:6: warning: The macro `AC_LANG_SAVE' is obsolete. configure.ac:6: You should run autoupdate. lang.m4: AC_LANG_SAVE is expanded from... configure.ac:6: the top level This allows us to write tests for these diagnostics that don’t depend on the relationship between the source and build directories, and won’t break when unrelated patches change the line number of a macro definition. * lib/autoconf/functions.m4 (AC_REPLACE_FUNCS, _AC_REPLACE_FUNCS) (_AC_REPLACE_FUNC): Refactor into AC_REPLACE_FUNCS, _AC_REPLACE_FUNCS, _AC_REPLACE_FUNC_U, _AC_REPLACE_FUNC_L, _AC_REPLACE_FUNC_NL. Ensure that _AH_CHECK_FUNC and AC_LIBSOURCE are invoked unconditionally at m4 expansion time for each literal function name in the argument to AC_CHECK_FUNCS. Issue warnings about non-literal names. * tests/local.at (AT_CHECK_M4): Normalize backtrace lines from the output of AC_DIAGNOSE / m4_warn. (AT_CHECK_AUTOHEADER): Add arg EXPECTED-TMPLS giving a list of preprocessor macro names that should appear in the generated config.h.in. Use AT_CHECK_M4 to invoke autoheader. (_AT_CHECK_AC_MACRO, AT_CHECK_MACRO, AT_CHECK_AU_MACRO): Update uses of AT_CHECK_AUTOHEADER. * tests/fortran.at, tests/semantics.at, tests/tools.at * tests/torture.at: Update all uses of AT_CHECK_AUTOHEADER. * tests/semantics.at (AC_REPLACE_FUNCS test): Make somewhat more thorough, using new functionality of AT_CHECK_M4 and AT_CHECK_AUTOHEADER. Signed-off-by: Zack Weinberg <zackw@panix.com>
Diffstat (limited to 'lib/autoconf/functions.m4')
-rw-r--r--lib/autoconf/functions.m439
1 files changed, 29 insertions, 10 deletions
diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4
index 608641b3..44730096 100644
--- a/lib/autoconf/functions.m4
+++ b/lib/autoconf/functions.m4
@@ -141,14 +141,35 @@ do
done])])
-# _AC_REPLACE_FUNC(FUNCTION)
-# --------------------------
+# _AC_REPLACE_FUNC_U(FUNCTION)
+# ----------------------------
+# Perform the actions that need to be performed unconditionally
+# for every FUNCTION that *could* be replaced by AC_REPLACE_FUNCS.
+m4_define([_AC_REPLACE_FUNC_U],
+[AS_LITERAL_WORD_IF([$1],
+ [_AH_CHECK_FUNC([$1])AC_LIBSOURCE([$1.c])],
+ [AC_DIAGNOSE([syntax], [AC_REPLACE_FUNCS($1): you should use literals])])])
+
+# _AC_REPLACE_FUNC_L(FUNCTION)
+# ----------------------------
# If FUNCTION exists, define HAVE_FUNCTION; else add FUNCTION.c
# to the list of library objects. FUNCTION must be literal.
-m4_define([_AC_REPLACE_FUNC],
+m4_define([_AC_REPLACE_FUNC_L],
+[_AC_REPLACE_FUNC_U([$1])]dnl
+[AC_CHECK_FUNC([$1],
+ [AC_DEFINE(AS_TR_CPP([HAVE_$1]))],
+ [_AC_LIBOBJ([$1])])])
+
+# _AC_REPLACE_FUNC_NL(FUNCTION)
+# -----------------------------
+# If FUNCTION exists, define HAVE_FUNCTION; else add FUNCTION.c
+# to the list of library objects. FUNCTION can be a shell variable.
+# (Because of this, neither _AH_CHECK_FUNC nor AC_LIBSOURCE is invoked
+# for FUNCTION.)
+m4_define([_AC_REPLACE_FUNC_NL],
[AC_CHECK_FUNC([$1],
- [_AH_CHECK_FUNC([$1])AC_DEFINE(AS_TR_CPP([HAVE_$1]))],
- [_AC_LIBOBJ([$1])AC_LIBSOURCE([$1.c])])])
+ [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_]$1))],
+ [_AC_LIBOBJ([$1])])])
# AC_REPLACE_FUNCS(FUNCTION...)
# -----------------------------
@@ -160,11 +181,9 @@ AC_DEFUN([AC_REPLACE_FUNCS],
m4_define([_AC_REPLACE_FUNCS],
[AS_LITERAL_IF([$1],
-[m4_map_args_w([$1], [_AC_REPLACE_FUNC(], [)
-])],
-[AC_CHECK_FUNCS([$1],
- [_AH_CHECK_FUNC([$ac_func])],
- [_AC_LIBOBJ([$ac_func])])])])
+ [m4_map_args_w([$1], [_AC_REPLACE_FUNC_L(], [)])],
+ [m4_map_args_w([$1], [_AC_REPLACE_FUNC_U(], [)])]dnl
+ [AS_FOR([AC_func], [ac_func], [$1], [_AC_REPLACE_FUNC_NL(AC_func)])])])
# AC_TRY_LINK_FUNC(FUNC, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)