While the result of the autoconf stage
is a complete script compatible with POSIX sh,
the language used to write the configure.ac
is called M4sh, to make clear that it's based
off both sh and the macro language M4.
The reason the M4sh language is often confused with simple sh syntax is because it actually is based on that, augmented with the autoconf proper macros and a few more macros that replace part of the sh syntax.
The major change between the standard sh syntax and M4sh is found
in two macros: AS_IF
and
AS_CASE
. The two macros, as it's easy to
guess, replace two constructs from sh:
if..then..elif..else..fi
and
case..esac
.
The two macros are actually replaced with the standard sh syntax after autoconf processing, but they exist for good reasons: they make it known to autoconf the conditional segments of the script. This in turn helps resolving issues with macros and conditionality.
The basic M4sh macros have a syntax that is directly translatable to sh syntax. It is thus easier to just see how the macros translate:
AS_IF([test], [true], [false]) if test; then true else false fi AS_IF([test1], [true], [test2], [true2], [false]) if test1; then true elif test2; then true2 else false fi
As you can see, the parameters to the macro aren't in a fixed number: you can chain a series of alternative conditions as you would with the usual sh script.
The parameters are positional: the parameters in odd position
(the first, the third, …) with the exception of the last one are
the truth conditions (the tests); the parameters in even
position are the conditional code executed if the previous
parameter results true, and if there is a last odd parameter,
it's considered the final alternative condition (the
else
condition).
Similarly, for AS_CASE
:
AS_CASE([$variable], [foo*], [run1], [bar*], [run2], [catchall]) case $variable in foo*) run1 ;; bar*) run2 ;; *) catchall ;; esac
As for AS_IF
, the parameters here are
positional, but since the first parameter is reserved to be the
argument to the case
statement, the even
places are for the compared expressions, and the odd ones
(starting from the third) contain the code that is executed,
conditionally. Finally, almost identical to the previous macro,
the last parameter is the code executed when nothing else
matched up.