Previous: , Up: Dependencies Between Macros   [Contents][Index]

8.5.4.3 One-Shot Macros

Some macros should be called only once, either because calling them multiple time is unsafe, or because it is bad style. For instance Autoconf ensures that AC_CANONICAL_BUILD and cousins (see Canonicalizing) are evaluated only once, because it makes no sense to run these expensive checks more than once. Such one-shot macros can be defined using AC_DEFUN_ONCE.

Macro: AC_DEFUN_ONCE (macro-name, macro-body)

Declare macro macro-name like AC_DEFUN would (see Macro Definitions), but add additional logic that guarantees that only the first use of the macro (whether by direct expansion or AC_REQUIRE) causes an expansion of macro-body; the expansion will occur before the start of any enclosing macro defined by AC_DEFUN. Subsequent expansions are silently ignored. Generally, it does not make sense for macro-body to use parameters such as $1.

Prior to Autoconf 2.64, a macro defined by AC_DEFUN_ONCE would emit a warning if it was directly expanded a second time, so for portability, it is better to use AC_REQUIRE than direct invocation of macro-name inside a macro defined by AC_DEFUN (see Prerequisite Macros).