2010-02-26 Eric Blake <eblake@redhat.com>
+ Optimize AC_REPLACE_FUNCS.
+ * lib/autoconf/functions.m4 (_AC_REPLACE_FUNC): New helper macro.
+ (AC_REPLACE_FUNCS): Use it to reduce forks when checking for
+ replacements, by using literal rather than shell variable.
+
Document how to safely override CFLAGS default.
* doc/autoconf.texi (C Compiler) <AC_PROG_CC>: Document a way to
change the default CFLAGS.
])
+# _AC_REPLACE_FUNC(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],
+[AC_CHECK_FUNC([$1],
+ [_AH_CHECK_FUNC([$1])AC_DEFINE(AS_TR_CPP([HAVE_$1]))],
+ [AC_LIBOBJ([$1])])])
+
# AC_REPLACE_FUNCS(FUNCTION...)
# -----------------------------
+# For each FUNCTION in the whitespace separated list, perform the
+# equivalent of AC_CHECK_FUNC, then call AC_LIBOBJ if the function
+# was not found.
AC_DEFUN([AC_REPLACE_FUNCS],
-[m4_map_args_w([$1], [AC_LIBSOURCE(], [.c)])]dnl
-[AC_CHECK_FUNCS([$1], , [_AC_LIBOBJ($ac_func)])
-])
+[m4_map_args_w([$1], [_AC_REPLACE_FUNC(], [)
+])])
# AC_TRY_LINK_FUNC(FUNC, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)