autoconf: Conditional constructs
1
1 8.3.4 Conditional constructs
1 ----------------------------
1
1 The following macros provide additional conditional constructs as
1 convenience wrappers around `m4_if'.
1
1 -- Macro: m4_bmatch (STRING, REGEX-1, VALUE-1, [REGEX-2], [VALUE-2],
1 ..., [DEFAULT])
1 The string STRING is repeatedly compared against a series of REGEX
1 arguments; if a match is found, the expansion is the corresponding
1 VALUE, otherwise, the macro moves on to the next REGEX. If no
1 REGEX match, then the result is the optional DEFAULT, or nothing.
1
1 -- Macro: m4_bpatsubsts (STRING, REGEX-1, SUBST-1, [REGEX-2],
1 [SUBST-2], ...)
1 The string STRING is altered by REGEX-1 and SUBST-1, as if by:
1 m4_bpatsubst([[STRING]], [REGEX], [SUBST])
1
1 The result of the substitution is then passed through the next set
1 of REGEX and SUBST, and so forth. An empty SUBST implies deletion
1 of any matched portions in the current string. Note that this
1 macro over-quotes STRING; this behavior is intentional, so that
1 the result of each step of the recursion remains as a quoted
1 string. However, it means that anchors (`^' and `$' in the REGEX
1 will line up with the extra quotations, and not the characters of
1 the original string. The overquoting is removed after the final
1 substitution.
1
1 -- Macro: m4_case (STRING, VALUE-1, IF-VALUE-1, [VALUE-2],
1 [IF-VALUE-2], ..., [DEFAULT])
1 Test STRING against multiple VALUE possibilities, resulting in the
1 first IF-VALUE for a match, or in the optional DEFAULT. This is
1 shorthand for:
1 m4_if([STRING], [VALUE-1], [IF-VALUE-1],
1 [STRING], [VALUE-2], [IF-VALUE-2], ...,
1 [DEFAULT])
1
1 -- Macro: m4_cond (TEST-1, VALUE-1, IF-VALUE-1, [TEST-2], [VALUE-2],
1 [IF-VALUE-2], ..., [DEFAULT])
1 This macro was introduced in Autoconf 2.62. Similar to `m4_if',
1 except that each TEST is expanded only when it is encountered.
1 This is useful for short-circuiting expensive tests; while `m4_if'
1 requires all its strings to be expanded up front before doing
1 comparisons, `m4_cond' only expands a TEST when all earlier tests
1 have failed.
1
1 For an example, these two sequences give the same result, but in
1 the case where `$1' does not contain a backslash, the `m4_cond'
1 version only expands `m4_index' once, instead of five times, for
1 faster computation if this is a common case for `$1'. Notice that
1 every third argument is unquoted for `m4_if', and quoted for
1 `m4_cond':
1
1 m4_if(m4_index([$1], [\]), [-1], [$2],
1 m4_eval(m4_index([$1], [\\]) >= 0), [1], [$2],
1 m4_eval(m4_index([$1], [\$]) >= 0), [1], [$2],
1 m4_eval(m4_index([$1], [\`]) >= 0), [1], [$3],
1 m4_eval(m4_index([$1], [\"]) >= 0), [1], [$3],
1 [$2])
1 m4_cond([m4_index([$1], [\])], [-1], [$2],
1 [m4_eval(m4_index([$1], [\\]) >= 0)], [1], [$2],
1 [m4_eval(m4_index([$1], [\$]) >= 0)], [1], [$2],
1 [m4_eval(m4_index([$1], [\`]) >= 0)], [1], [$3],
1 [m4_eval(m4_index([$1], [\"]) >= 0)], [1], [$3],
1 [$2])
1
1 -- Macro: m4_default (EXPR-1, EXPR-2)
1 -- Macro: m4_default_quoted (EXPR-1, EXPR-2)
1 -- Macro: m4_default_nblank (EXPR-1, [EXPR-2])
1 -- Macro: m4_default_nblank_quoted (EXPR-1, [EXPR-2])
1 If EXPR-1 contains text, use it. Otherwise, select EXPR-2.
1 `m4_default' expands the result, while `m4_default_quoted' does
1 not. Useful for providing a fixed default if the expression that
1 results in EXPR-1 would otherwise be empty. The difference
1 between `m4_default' and `m4_default_nblank' is whether an
1 argument consisting of just blanks (space, tab, newline) is
1 significant. When using the expanding versions, note that an
1 argument may contain text but still expand to an empty string.
1
1 m4_define([active], [ACTIVE])dnl
1 m4_define([empty], [])dnl
1 m4_define([demo1], [m4_default([$1], [$2])])dnl
1 m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
1 m4_define([demo3], [m4_default_nblank([$1], [$2])])dnl
1 m4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnl
1 demo1([active], [default])
1 =>ACTIVE
1 demo1([], [active])
1 =>ACTIVE
1 demo1([empty], [text])
1 =>
1 -demo1([ ], [active])-
1 =>- -
1 demo2([active], [default])
1 =>active
1 demo2([], [active])
1 =>active
1 demo2([empty], [text])
1 =>empty
1 -demo2([ ], [active])-
1 =>- -
1 demo3([active], [default])
1 =>ACTIVE
1 demo3([], [active])
1 =>ACTIVE
1 demo3([empty], [text])
1 =>
1 -demo3([ ], [active])-
1 =>-ACTIVE-
1 demo4([active], [default])
1 =>active
1 demo4([], [active])
1 =>active
1 demo4([empty], [text])
1 =>empty
1 -demo4([ ], [active])-
1 =>-active-
1
1 -- Macro: m4_define_default (MACRO, [DEFAULT-DEFINITION])
1 If MACRO does not already have a definition, then define it to
1 DEFAULT-DEFINITION.
1
1 -- Macro: m4_ifblank (COND, [IF-BLANK], [IF-TEXT])
1 -- Macro: m4_ifnblank (COND, [IF-TEXT], [IF-BLANK])
1 If COND is empty or consists only of blanks (space, tab, newline),
1 then expand IF-BLANK; otherwise, expand IF-TEXT. Two variants
1 exist, in order to make it easier to select the correct logical
1 sense when using only two parameters. Note that this is more
1 efficient than the equivalent behavior of:
1 m4_ifval(m4_normalize([COND]), IF-TEXT, IF-BLANK)
1
1 -- Macro: m4_ifndef (MACRO, IF-NOT-DEFINED, [IF-DEFINED])
1 This is shorthand for:
1 m4_ifdef([MACRO], [IF-DEFINED], [IF-NOT-DEFINED])
1
1 -- Macro: m4_ifset (MACRO, [IF-TRUE], [IF-FALSE])
1 If MACRO is undefined, or is defined as the empty string, expand
1 to IF-FALSE. Otherwise, expands to IF-TRUE. Similar to:
1 m4_ifval(m4_defn([MACRO]), [IF-TRUE], [IF-FALSE])
1 except that it is not an error if MACRO is undefined.
1
1 -- Macro: m4_ifval (COND, [IF-TRUE], [IF-FALSE])
1 Expands to IF-TRUE if COND is not empty, otherwise to IF-FALSE.
1 This is shorthand for:
1 m4_if([COND], [], [IF-FALSE], [IF-TRUE])
1
1 -- Macro: m4_ifvaln (COND, [IF-TRUE], [IF-FALSE])
1 Similar to `m4_ifval', except guarantee that a newline is present
1 after any non-empty expansion. Often followed by `dnl'.
1
1 -- Macro: m4_n (TEXT)
1 Expand to TEXT, and add a newline if TEXT is not empty. Often
1 followed by `dnl'.
1