[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: m4_defun_init
From: |
Eric Blake |
Subject: |
Re: m4_defun_init |
Date: |
Fri, 24 Oct 2008 20:14:36 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Eric Blake <ebb9 <at> byu.net> writes:
> > I will probably do another followup for autoconf macros that do one-shot
> > initialization (think _AC_*_IFELSE, for starters), for even more speedup.
>
> Phooey. _AC_*_IFELSE aren't currently one-shot (when you use multiple
> languages, they create multiple ac_func_*_try_* shell functions across
separate
> invocations). But maybe AC_LANG_PUSH could be made to help out, by copying
the
> basic _AC_*_IFELSE implementation as part of AC_LANG(lang), so that each
> language gets its own one-shot initializer copy. I'm still playing with it...
This works for creating multiple one-shot macros, one for each language.
However, run times before and after this patch are about the same (no huge
speedup), so I'm not sure I want to apply it.
From: Eric Blake <address@hidden>
Date: Fri, 24 Oct 2008 14:05:17 -0600
Subject: [PATCH] Use one-shot initializers for _AC_*_IFELSE.
* lib/autoconf/general.m4 (_AC_PREPROC_IFELSE, _AC_COMPILE_IFELSE)
(_AC_LINK_IFELSE, _AC_RUN_IFELSE): Rewrite as wrappers...
(_AC_PREPROC_IFELSE(), _AC_COMPILE_IFELSE(), _AC_LINK_IFELSE())
(_AC_RUN_IFELSE()): ...around new one-shot macros, to be copied
once per language.
* lib/autoconf/lang.m4 (_AC_LANG_PREP): New macro, to copy
one-shots once per language.
* lib/autoconf/c.m4 (AC_LANG(C), AC_LANG(C++), AC_LANG(Objective
C)): Use it.
* lib/autoconf/erlang.m4 (AC_LANG(Erlang)): Likewise.
* lib/autoconf/fortran.m4 (AC_LANG(Fortran77), AC_LANG(Fortran)):
Likewise.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 16 +++++++++
lib/autoconf/c.m4 | 23 +++++++------
lib/autoconf/erlang.m4 | 67 +++++++++++++++++++-------------------
lib/autoconf/fortran.m4 | 2 +
lib/autoconf/general.m4 | 81 ++++++++++++++++++++++++++++++-----------------
lib/autoconf/lang.m4 | 19 +++++++++--
6 files changed, 132 insertions(+), 76 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b26d7ca..a1a707c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2008-10-24 Eric Blake <address@hidden>
+ Use one-shot initializers for _AC_*_IFELSE.
+ * lib/autoconf/general.m4 (_AC_PREPROC_IFELSE, _AC_COMPILE_IFELSE)
+ (_AC_LINK_IFELSE, _AC_RUN_IFELSE): Rewrite as wrappers...
+ (_AC_PREPROC_IFELSE(), _AC_COMPILE_IFELSE(), _AC_LINK_IFELSE())
+ (_AC_RUN_IFELSE()): ...around new one-shot macros, to be copied
+ once per language.
+ * lib/autoconf/lang.m4 (_AC_LANG_PREP): New macro, to copy
+ one-shots once per language.
+ * lib/autoconf/c.m4 (AC_LANG(C), AC_LANG(C++), AC_LANG(Objective
+ C)): Use it.
+ * lib/autoconf/erlang.m4 (AC_LANG(Erlang)): Likewise.
+ * lib/autoconf/fortran.m4 (AC_LANG(Fortran77), AC_LANG(Fortran)):
+ Likewise.
+
+2008-10-24 Eric Blake <address@hidden>
+
Work around fact that gnulib-tool doesn't use m4_copy.
* lib/autoconf/general.m4 (AC_LIBOBJ, AC_LIBSOURCES): Defun, not
define, so that an initial location is present, to account for
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index f3b3e5f..31f7c05 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -81,6 +81,7 @@
# AC_LANG(C)
# ----------
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+_AC_LANG_PREP([C])
m4_define([AC_LANG(C)],
[ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
@@ -114,6 +115,7 @@ m4_define([_AC_LANG_PREFIX(C)], [C])
# AC_LANG(C++)
# ------------
# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+_AC_LANG_PREP([C++])
m4_define([AC_LANG(C++)],
[ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
@@ -146,6 +148,7 @@ m4_define([_AC_LANG_PREFIX(C++)], [CXX])
# AC_LANG(Objective C)
# --------------------
+_AC_LANG_PREP([Objective C])
m4_define([AC_LANG(Objective C)],
[ac_ext=m
ac_cpp='$OBJCPP $CPPFLAGS'
diff --git a/lib/autoconf/erlang.m4 b/lib/autoconf/erlang.m4
index 9bed007..e2da91e 100644
--- a/lib/autoconf/erlang.m4
+++ b/lib/autoconf/erlang.m4
@@ -121,6 +121,7 @@ fi
# AC_LANG(Erlang)
# ---------------
+_AC_LANG_PREP([Erlang])
m4_define([AC_LANG(Erlang)],
[ac_ext=erl
ac_compile='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 34d9301..c5717fb 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -162,6 +162,7 @@ fi[]dnl
# AC_LANG(Fortran 77)
# -------------------
+_AC_LANG_PREP([Fortran 77])
m4_define([AC_LANG(Fortran 77)],
[ac_ext=f
ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
@@ -172,6 +173,7 @@ ac_compiler_gnu=$ac_cv_f77_compiler_gnu
# AC_LANG(Fortran)
# ----------------
+_AC_LANG_PREP([Fortran])
m4_define([AC_LANG(Fortran)],
[ac_ext=${ac_fc_srcext-f}
ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext
>&AS_MESSAGE_LOG_FD'
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 299facd..eeff47f 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -2399,22 +2399,28 @@ m4_define([_AC_PREPROC_IFELSE_BODY],
return $ac_retval
])# _AC_PREPROC_IFELSE_BODY
-
-# _AC_PREPROC_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
-# ----------------------------------------------------------------
-# Try to preprocess PROGRAM.
+# _AC_PREPROC_IFELSE()(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# ------------------------------------------------------------------
+# Try to preprocess PROGRAM. This is a template, designed to be
+# copied once per AC_LANG.
#
# This macro can be used during the selection of a preprocessor.
# eval is necessary to expand ac_cpp.
-AC_DEFUN([_AC_PREPROC_IFELSE],
+m4_defun_init([_AC_PREPROC_IFELSE()],
[AC_REQUIRE_SHELL_FN([ac_func_]_AC_LANG_ABBREV[_try_cpp],
[AS_FUNCTION_DESCRIBE([ac_func_]_AC_LANG_ABBREV[_try_cpp], [LINENO],
[Try to preprocess conftest.$ac_ext, and return whether this succeeded.])],
- [$0_BODY])]dnl
+ [_AC_PREPROC_IFELSE_BODY])],
[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])]dnl
[AS_IF([ac_func_[]_AC_LANG_ABBREV[]_try_cpp "$LINENO"], [$2], [$3])
rm -f conftest.err[]m4_ifval([$1], [ conftest.$ac_ext])[]dnl
-])# _AC_PREPROC_IFELSE
+])# _AC_PREPROC_IFELSE()
+
+# _AC_PREPROC_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# ----------------------------------------------------------------
+# Try to preprocess PROGRAM. Defer to the language-specific copy.
+m4_define([_AC_PREPROC_IFELSE],
+[m4_indir([$0(]_AC_LANG[)], $@)])
# AC_PREPROC_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
# ---------------------------------------------------------------
@@ -2471,6 +2477,7 @@ AC_DEFUN([AC_EGREP_HEADER],
## Examining syntax. ##
## ------------------ ##
+
# _AC_COMPILE_IFELSE_BODY
# -----------------------
# Shell function body for _AC_COMPILE_IFELSE.
@@ -2488,21 +2495,26 @@ m4_define([_AC_COMPILE_IFELSE_BODY],
return $ac_retval
])# _AC_COMPILE_IFELSE_BODY
-
-# _AC_COMPILE_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
-# ----------------------------------------------------------------
-# Try to compile PROGRAM.
+# _AC_COMPILE_IFELSE()(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# ------------------------------------------------------------------
+# Try to compile PROGRAM. This is a template, designed to be
+# copied once per AC_LANG.
# This macro can be used during the selection of a compiler.
-AC_DEFUN([_AC_COMPILE_IFELSE],
+m4_defun_init([_AC_COMPILE_IFELSE()],
[AC_REQUIRE_SHELL_FN([ac_func_]_AC_LANG_ABBREV[_try_compile],
[AS_FUNCTION_DESCRIBE([ac_func_]_AC_LANG_ABBREV[_try_compile], [LINENO],
[Try to compile conftest.$ac_ext, and return whether this succeeded.])],
- [$0_BODY])]dnl
+ [_AC_COMPILE_IFELSE_BODY])],
[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])]dnl
[AS_IF([ac_func_[]_AC_LANG_ABBREV[]_try_compile "$LINENO"], [$2], [$3])
-rm -f core conftest.err conftest.$ac_objext[]m4_ifval([$1], [
conftest.$ac_ext])[]dnl
-])# _AC_COMPILE_IFELSE
+rm -f core conftest.err conftest.$ac_objext[]m4_ifval([$1],
+ [ conftest.$ac_ext])[]])# _AC_COMPILE_IFELSE()
+# _AC_COMPILE_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# ----------------------------------------------------------------
+# Try to compile PROGRAM. Defer to the language-specific copy.
+m4_define([_AC_COMPILE_IFELSE],
+[m4_indir([$0(]_AC_LANG[)], $@)])
# AC_COMPILE_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
# ---------------------------------------------------------------
@@ -2553,9 +2565,10 @@ m4_define([_AC_LINK_IFELSE_BODY],
])# _AC_LINK_IFELSE_BODY
-# _AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
-# -------------------------------------------------------------
-# Try to link PROGRAM.
+# _AC_LINK_IFELSE()(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# ---------------------------------------------------------------
+# Try to link PROGRAM. This is a template, designed to be
+# copied once per AC_LANG.
# This macro can be used during the selection of a compiler.
#
# Test that resulting file is executable; see the problem reported by mwoehlke
@@ -2563,18 +2576,22 @@ m4_define([_AC_LINK_IFELSE_BODY],
# But skip the test when cross-compiling, to prevent problems like the one
# reported by Chris Johns in
# <http://lists.gnu.org/archive/html/autoconf/2007-03/msg00085.html>.
-#
-AC_DEFUN([_AC_LINK_IFELSE],
+m4_defun_init([_AC_LINK_IFELSE()],
[AC_REQUIRE_SHELL_FN([ac_func_]_AC_LANG_ABBREV[_try_link],
[AS_FUNCTION_DESCRIBE([ac_func_]_AC_LANG_ABBREV[_try_link], [LINENO],
[Try to link conftest.$ac_ext, and return whether this succeeded.])],
- [$0_BODY])]dnl
+ [_AC_LINK_IFELSE_BODY])],
[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])]dnl
[AS_IF([ac_func_[]_AC_LANG_ABBREV[]_try_link "$LINENO"], [$2], [$3])
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext[]m4_ifval([$1], [ conftest.$ac_ext])[]dnl
])# _AC_LINK_IFELSE
+# _AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# -------------------------------------------------------------
+# Try to link PROGRAM. Defer to the language-specific copy.
+m4_define([_AC_LINK_IFELSE],
+[m4_indir([$0(]_AC_LANG[)], $@)])
# AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
# ------------------------------------------------------------
@@ -2624,25 +2641,31 @@ m4_define([_AC_RUN_IFELSE_BODY],
return $ac_retval
])# _AC_RUN_IFELSE_BODY
-
-# _AC_RUN_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
-# ------------------------------------------------------------
-# Compile, link, and run.
+# _AC_RUN_IFELSE()(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# --------------------------------------------------------------
+# Compile, link, and run. This is a template, designed to be
+# copied once per AC_LANG.
# This macro can be used during the selection of a compiler.
# We also remove conftest.o as if the compilation fails, some compilers
# don't remove it. We remove gmon.out and bb.out, which may be
# created during the run if the program is built with profiling support.
-AC_DEFUN([_AC_RUN_IFELSE],
+m4_defun_init([_AC_RUN_IFELSE()],
[AC_REQUIRE_SHELL_FN([ac_func_]_AC_LANG_ABBREV[_try_run],
[AS_FUNCTION_DESCRIBE([ac_func_]_AC_LANG_ABBREV[_try_run], [LINENO],
[Try to link conftest.$ac_ext, and return whether this succeeded.
Assumes that executables *can* be run.])],
- [$0_BODY])]dnl
+ [_AC_RUN_IFELSE_BODY])],
[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])]dnl
[AS_IF([ac_func_[]_AC_LANG_ABBREV[]_try_run "$LINENO"], [$2], [$3])
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
- conftest.$ac_objext conftest$ac_exeext[]m4_ifval([$1], [ conftest.$ac_ext])[]
dnl
-])# _AC_RUN_IFELSE
+ conftest.$ac_objext conftest$ac_exeext[]m4_ifval([$1],
+ [ conftest.$ac_ext])[]])# _AC_RUN_IFELSE
+
+# _AC_RUN_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# ------------------------------------------------------------
+# Compile, link, and run. Defer to the language-specific copy.
+m4_define([_AC_RUN_IFELSE],
+[m4_indir([$0(]_AC_LANG[)], $@)])
# AC_RUN_IFELSE(PROGRAM,
# [ACTION-IF-TRUE], [ACTION-IF-FALSE],
diff --git a/lib/autoconf/lang.m4 b/lib/autoconf/lang.m4
index c48f1de..5fd477b 100644
--- a/lib/autoconf/lang.m4
+++ b/lib/autoconf/lang.m4
@@ -105,13 +105,24 @@ m4_defun([_AC_LANG_SET],
[_AC_LANG_DISPATCH([AC_LANG], [$2])])
+# _AC_LANG_PREP(LANG)
+# -------------------
+# Initialize the definition of one-shot _AC_*_IFELSE macros
+# appropriate for LANG. Each language must define `AC_LANG(LANG)' and
+# invoke this function, prior to autoconf freezing time.
+m4_define([_AC_LANG_PREP],
+[m4_copy([_AC_PREPROC_IFELSE()], [_AC_PREPROC_IFELSE($1)])]dnl
+[m4_copy([_AC_COMPILE_IFELSE()], [_AC_COMPILE_IFELSE($1)])]dnl
+[m4_copy([_AC_LINK_IFELSE()], [_AC_LINK_IFELSE($1)])]dnl
+[m4_copy([_AC_RUN_IFELSE()], [_AC_RUN_IFELSE($1)])])
+
+
# AC_LANG(LANG)
# -------------
# Set the current language to LANG.
m4_defun([AC_LANG],
-[_AC_LANG_SET(m4_ifdef([_AC_LANG], [m4_defn([_AC_LANG])]),
- [$1])dnl
-m4_define([_AC_LANG], [$1])])
+[_AC_LANG_SET(m4_ifdef([_AC_LANG], [m4_defn([_AC_LANG])]), [$1])]dnl
+[m4_define([_AC_LANG], [$1])])
# AC_LANG_PUSH(LANG)
--
1.6.0.2