autoconf: Shell Script Compiler

1 
1 3.1.1 A Shell Script Compiler
1 -----------------------------
1 
1 Just as for any other computer language, in order to properly program
1 `configure.ac' in Autoconf you must understand _what_ problem the
1 language tries to address and _how_ it does so.
1 
1    The problem Autoconf addresses is that the world is a mess.  After
1 all, you are using Autoconf in order to have your package compile
1 easily on all sorts of different systems, some of them being extremely
1 hostile.  Autoconf itself bears the price for these differences:
1 `configure' must run on all those systems, and thus `configure' must
1 limit itself to their lowest common denominator of features.
1 
1    Naturally, you might then think of shell scripts; who needs
1 `autoconf'?  A set of properly written shell functions is enough to
1 make it easy to write `configure' scripts by hand.  Sigh!
1 Unfortunately, even in 2008, where shells without any function support
1 are far and few between, there are pitfalls to avoid when making use of
1 them.  Also, finding a Bourne shell that accepts shell functions is not
1 trivial, even though there is almost always one on interesting porting
1 targets.
1 
1    So, what is really needed is some kind of compiler, `autoconf', that
1 takes an Autoconf program, `configure.ac', and transforms it into a
1 portable shell script, `configure'.
1 
1    How does `autoconf' perform this task?
1 
1    There are two obvious possibilities: creating a brand new language or
1 extending an existing one.  The former option is attractive: all sorts
1 of optimizations could easily be implemented in the compiler and many
1 rigorous checks could be performed on the Autoconf program (e.g.,
1 rejecting any non-portable construct).  Alternatively, you can extend
1 an existing language, such as the `sh' (Bourne shell) language.
1 
1    Autoconf does the latter: it is a layer on top of `sh'.  It was
1 therefore most convenient to implement `autoconf' as a macro expander:
1 a program that repeatedly performs "macro expansions" on text input,
1 replacing macro calls with macro bodies and producing a pure `sh'
1 script in the end.  Instead of implementing a dedicated Autoconf macro
1 expander, it is natural to use an existing general-purpose macro
1 language, such as M4, and implement the extensions as a set of M4
1 macros.
1