Next: Suggested Ordering Up: Dependencies Between Macros
9.4.1 Prerequisite Macros
A macro that you write might need to use values that have previously
been computed by other macros. For example, `AC_DECL_YYTEXT' examines
the output of `flex' or `lex', so it depends on `AC_PROG_LEX' having
been called first to set the shell variable `LEX'.
Rather than forcing the user of the macros to keep track of the
dependencies between them, you can use the `AC_REQUIRE' macro to do it
automatically. `AC_REQUIRE' can ensure that a macro is only called if
it is needed, and only called once.
-- Macro: AC_REQUIRE (MACRO-NAME)
If the M4 macro MACRO-NAME has not already been called, call it
(without any arguments). Make sure to quote MACRO-NAME with
square brackets. MACRO-NAME must have been defined using
`AC_DEFUN' or else contain a call to `AC_PROVIDE' to indicate that
it has been called.
`AC_REQUIRE' must be used inside a macro defined by `AC_DEFUN'; it
must not be called from the top level.
`AC_REQUIRE' is often misunderstood. It really implements
dependencies between macros in the sense that if one macro depends upon
another, the latter is expanded _before_ the body of the former. To be
more precise, the required macro is expanded before the outermost
defined macro in the current expansion stack. In particular,
`AC_REQUIRE([FOO])' is not replaced with the body of `FOO'. For
instance, this definition of macros:
[test "$body_temperature_in_celsius" -gt "38" &&
[test "$hair_style" = "curly" &&
[if date | grep '^Sat.*pm' >/dev/null 2>&1; then
with this `configure.ac'
AC_INIT([Dance Manager], [1.0], [email@example.com])
if test "$dance_floor" = occupied; then
AC_MSG_ERROR([cannot pick up here, let's move])
does not leave you with a better chance to meet a kindred soul at other
times than Saturday night since it expands into:
test "$body_temperature_in_Celsius" -gt "38" &&
test "$hair_style" = "curly" &&
if date | grep '^Sat.*pm' >/dev/null 2>&1; then
This behavior was chosen on purpose: (i) it prevents messages in
required macros from interrupting the messages in the requiring macros;
(ii) it avoids bad surprises when shell conditionals are used, as in:
if ...; then
The helper macros `AS_IF' and `AS_CASE' may be used to enforce
expansion of required macros outside of shell conditional constructs.
You are furthermore encouraged to put all `AC_REQUIRE' calls at the
beginning of a macro. You can use `dnl' to avoid the empty lines they
automatically generated by info2www