automake: Usage of Conditionals
1
1 20.1 Usage of Conditionals
1 ==========================
1
1 Before using a conditional, you must define it by using ‘AM_CONDITIONAL’
1 in the ‘configure.ac’ file (⇒Macros).
1
1 -- Macro: AM_CONDITIONAL (CONDITIONAL, CONDITION)
1 The conditional name, CONDITIONAL, should be a simple string
1 starting with a letter and containing only letters, digits, and
1 underscores. It must be different from ‘TRUE’ and ‘FALSE’ that are
1 reserved by Automake.
1
1 The shell CONDITION (suitable for use in a shell ‘if’ statement) is
1 evaluated when ‘configure’ is run. Note that you must arrange for
1 _every_ ‘AM_CONDITIONAL’ to be invoked every time ‘configure’ is
1 run. If ‘AM_CONDITIONAL’ is run conditionally (e.g., in a shell
1 ‘if’ statement), then the result will confuse ‘automake’.
1
1 Conditionals typically depend upon options that the user provides to
1 the ‘configure’ script. Here is an example of how to write a
1 conditional that is true if the user uses the ‘--enable-debug’ option.
1
1 AC_ARG_ENABLE([debug],
1 [ --enable-debug Turn on debugging],
1 [case "${enableval}" in
1 yes) debug=true ;;
1 no) debug=false ;;
1 *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
1 esac],[debug=false])
1 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
1
1 Here is an example of how to use that conditional in ‘Makefile.am’:
1
1 if DEBUG
1 DBG = debug
1 else
1 DBG =
1 endif
1 noinst_PROGRAMS = $(DBG)
1
1 This trivial example could also be handled using ‘EXTRA_PROGRAMS’
1 (⇒Conditional Programs).
1
1 You may only test a single variable in an ‘if’ statement, possibly
1 negated using ‘!’. The ‘else’ statement may be omitted. Conditionals
1 may be nested to any depth. You may specify an argument to ‘else’ in
1 which case it must be the negation of the condition used for the current
1 ‘if’. Similarly you may specify the condition that is closed on the
1 ‘endif’ line:
1
1 if DEBUG
1 DBG = debug
1 else !DEBUG
1 DBG =
1 endif !DEBUG
1
1 Unbalanced conditions are errors. The ‘if’, ‘else’, and ‘endif’
1 statements should not be indented, i.e., start on column one.
1
1 The ‘else’ branch of the above two examples could be omitted, since
1 assigning the empty string to an otherwise undefined variable makes no
1 difference.
1
1 In order to allow access to the condition registered by
1 ‘AM_CONDITIONAL’ inside ‘configure.ac’, and to allow conditional
1 ‘AC_CONFIG_FILES’, ‘AM_COND_IF’ may be used:
1
1 -- Macro: AM_COND_IF (CONDITIONAL, [IF-TRUE], [IF-FALSE])
1 If CONDITIONAL is fulfilled, execute IF-TRUE, otherwise execute
1 IF-FALSE. If either branch contains ‘AC_CONFIG_FILES’, it will
1 cause ‘automake’ to output the rules for the respective files only
1 for the given condition.
1
1 ‘AM_COND_IF’ macros may be nested when m4 quotation is used properly
1 (⇒(autoconf)M4 Quotation).
1
1 Here is an example of how to define a conditional config file:
1
1 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
1 AM_COND_IF([SHELL_WRAPPER],
1 [AC_CONFIG_FILES([wrapper:wrapper.in])])
1