[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [CFT] Shell functionization patch (if you don't know what that means

From: Eric Blake
Subject: Re: [CFT] Shell functionization patch (if you don't know what that means, it's faster Autoconf and leaner configure scripts)
Date: Thu, 16 Oct 2008 20:24:58 +0000 (UTC)
User-agent: Loom/3.14 (

Paolo Bonzini <bonzini <at>> writes:

First thought, before I even begin a thorough review:

>  # -----------------------------------------------------------------
> -[AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$1])dnl
> -AC_CACHE_CHECK([for $1], [ac_var],
> -             [AS_VAR_SET([ac_var], [yes])],
> -             [AS_VAR_SET([ac_var], [no])])])
> +[AS_REQUIRE_SHELL_FN([ac_func_]_AC_LANG_ABBREV[_check_func], [
> +  AS_LINENO_PUSH([$[]1])
> +  AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$[]2])dnl
> +  AC_CACHE_CHECK([for $[]2], [ac_var],
> +               [AS_VAR_SET([ac_var], [yes])],
> +               [AS_VAR_SET([ac_var], [no])])])
> +  AS_VAR_POPDEF([ac_var])dnl
> +])dnl
> +ac_func_[]_AC_LANG_ABBREV[]_check_func "$LINENO" "$1"
> +AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$1])dnl
>  AS_VAR_IF([ac_var], [yes], [$2], [$3])dnl
>  AS_VAR_POPDEF([ac_var])dnl

This is getting slightly hard to review without shell comments describing how a 
function is to be used (for example, AS_LINENO_PUSH([$[]1]) as the first line 
of the function body means that the function expects $LINENO as its first 
argument, but that isn't commented anywhere other than by examining how the 
function is called); this means that the function appears in the configure file 
with no comments whatsoever.  I propose that we modify AS_REQUIRE_SHELL_FN as 

# AS_REQUIRE_SHELL_FN(name, [comment], body, [diversion])
# --------

And define a helper function:

# AS_FUNCTION_DESCRIBE(name, [args], description)
# -----------------------------------------------
# Output a shell comment that looks like:
#   # ---------
# where the second line sizes itself according to the first, and where
# DESCRIPTION is treated as a whitespace separated list of words
# to be wrapped at 76 columns.

[I can help with the m4sugar magic needed here, if you like the idea; borrowing 

Then back to a concern I raised earlier - time spent parsing complex shell 
functions listed early in the script makes 'configure --help' that much 
slower.  I'd like reserve M4SH-INIT-FN for as_func_*, and see all ac_func_* 
dumped in a different diversion (for argument sake, let's call it AC_INIT_FN, 
and that it is between VERSION_END and INIT_PREPARE).  So, to efficiently 
output functions into this diversion (and to use my above idea of outputting 
shell comments), I would add this wrapper at the autoconf level:

# AC_REQUIRE_SHELL_FN(name, [args], description, body)
# ----------------------------------------------------
# Ensure that function ac_func_NAME that takes arguments ARGS is defined,
# with comments DESCRIPTION and contents BODY, and is emitted prior to
# anyone who wants to call the function, but after --help is handled.
  [AS_FUNCTION_DESCRIBE([ac_func_$1], [$2], [$3])],
  [$4], [AC_INIT_FN])])

With the wrapper in place, the above code could be written:

AC_REQUIRE_SHELL_FN(_AC_LANG_ABBREV[_check_func], [line name],
[Check whether it is possible to link against the ]_AC_LANG_ABBREV[
function NAME, and log the result with a message that includes LINE
as its point of origin.], [
  AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$[]2])dnl
ac_func_[]_AC_LANG_ABBREV[]_check_func $LINENO "$1"

and the configure file after AC_CHECK_FUNC([cos]) would look like:

# ac_func_C_check_func line name
# ------------------------------
# Check whether it is possible to link against the C function NAME, and
# log the result with a message that includes LINE as its point of
# origin.
ac_func_C_check_func () {
[much later, in BODY]
ac_func_C_check_func $LINENO "cos"

What do you think?

Eric Blake

reply via email to

[Prev in Thread] Current Thread [Next in Thread]