On 08/12/2009 02:37 AM, Reuben Thomas wrote:
2009/8/7 Paolo Bonzini<[email protected]>:
AS_INIT ensures that you can define shell functions normally using
foo () {
# body
}
Alternatively, there is AS_REQUIRE_SHELL_FN that provides a way to define
shell functions from within a m4 macro,
So when should one use AS_INIT, and when should one prefer AS_REQUIRE _SHELL_FN?
It's different things.
AS_INIT initializes m4sh, including ensuring that the current shell
supports functions. After that you can define shell functions with the
normal syntax.
If you write a m4sh script, you can then define shell functions normally
using shell syntax. Even if write a library like Autotest, shell
functions that are always needed can be defined normally using shell syntax.
AS_REQUIRE_SHELL_FN is a separate thing. It provides a convenience for
defining a shell function, and will expand the function definition just
once. Also, the function definition will be placed early in the file,
just after the initialization code.
AS_REQUIRE_SHELL_FN is useful if you do not know in advance which
functions will be needed, or what code they will expand to.
For example, AC_CHECK_FUNC does two things: 1) it uses
AS_REQUIRE_SHELL_FN to generate a shell function with the test code, and
2) it produces a call to the function. The call ends up where
AC_CHECK_FUNC was in the configure.ac file, while the shell function is
placed early in the configure script.
AC_CHECK_FUNC uses AS_REQUIRE_SHELL_FN because Autoconf scripts may not
all need the check-function test code, and because the body of the
function is not known, say, when AC_INIT is executed (because it depends
on the language being tested).
Paolo