automake: amhello's configure.ac Setup Explained

1 
1 2.4.2 ‘amhello’’s ‘configure.ac’ Setup Explained
1 ------------------------------------------------
1 
1 Let us begin with the contents of ‘configure.ac’.
1 
1      AC_INIT([amhello], [1.0], [bug-automake@gnu.org])
1      AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1      AC_PROG_CC
1      AC_CONFIG_HEADERS([config.h])
1      AC_CONFIG_FILES([
1       Makefile
1       src/Makefile
1      ])
1      AC_OUTPUT
1 
1    This file is read by both ‘autoconf’ (to create ‘configure’) and
1 ‘automake’ (to create the various ‘Makefile.in’s).  It contains a series
1 of M4 macros that will be expanded as shell code to finally form the
1 ‘configure’ script.  We will not elaborate on the syntax of this file,
11 because the Autoconf manual has a whole section about it (⇒Writing
 ‘configure.ac’ (autoconf)Writing Autoconf Input.).
1 
1    The macros prefixed with ‘AC_’ are Autoconf macros, documented in the
11 Autoconf manual (⇒Autoconf Macro Index (autoconf)Autoconf Macro
 Index.).  The macros that start with ‘AM_’ are Automake macros,
1 documented later in this manual (⇒Macro Index).
1 
1    The first two lines of ‘configure.ac’ initialize Autoconf and
1 Automake.  ‘AC_INIT’ takes in as parameters the name of the package, its
1 version number, and a contact address for bug-reports about the package
1 (this address is output at the end of ‘./configure --help’, for
1 instance).  When adapting this setup to your own package, by all means
1 please do not blindly copy Automake’s address: use the mailing list of
1 your package, or your own mail address.
1 
1    The argument to ‘AM_INIT_AUTOMAKE’ is a list of options for
1 ‘automake’ (⇒Options).  ‘-Wall’ and ‘-Werror’ ask ‘automake’ to
1 turn on all warnings and report them as errors.  We are speaking of
1 *Automake* warnings here, such as dubious instructions in ‘Makefile.am’.
1 This has absolutely nothing to do with how the compiler will be called,
1 even though it may support options with similar names.  Using ‘-Wall
1 -Werror’ is a safe setting when starting to work on a package: you do
1 not want to miss any issues.  Later you may decide to relax things a
1 bit.  The ‘foreign’ option tells Automake that this package will not
1 follow the GNU Standards.  GNU packages should always distribute
1 additional files such as ‘ChangeLog’, ‘AUTHORS’, etc.  We do not want
1 ‘automake’ to complain about these missing files in our small example.
1 
1    The ‘AC_PROG_CC’ line causes the ‘configure’ script to search for a C
1 compiler and define the variable ‘CC’ with its name.  The
1 ‘src/Makefile.in’ file generated by Automake uses the variable ‘CC’ to
1 build ‘hello’, so when ‘configure’ creates ‘src/Makefile’ from
1 ‘src/Makefile.in’, it will define ‘CC’ with the value it has found.  If
1 Automake is asked to create a ‘Makefile.in’ that uses ‘CC’ but
1 ‘configure.ac’ does not define it, it will suggest you add a call to
1 ‘AC_PROG_CC’.
1 
1    The ‘AC_CONFIG_HEADERS([config.h])’ invocation causes the ‘configure’
1 script to create a ‘config.h’ file gathering ‘#define’s defined by other
1 macros in ‘configure.ac’.  In our case, the ‘AC_INIT’ macro already
1 defined a few of them.  Here is an excerpt of ‘config.h’ after
1 ‘configure’ has run:
1 
1      ...
1      /* Define to the address where bug reports for this package should be sent. */
1      #define PACKAGE_BUGREPORT "bug-automake@gnu.org"
1 
1      /* Define to the full name and version of this package. */
1      #define PACKAGE_STRING "amhello 1.0"
1      ...
1 
1    As you probably noticed, ‘src/main.c’ includes ‘config.h’ so it can
1 use ‘PACKAGE_STRING’.  In a real-world project, ‘config.h’ can grow
1 really big, with one ‘#define’ per feature probed on the system.
1 
1    The ‘AC_CONFIG_FILES’ macro declares the list of files that
1 ‘configure’ should create from their ‘*.in’ templates.  Automake also
1 scans this list to find the ‘Makefile.am’ files it must process.  (This
1 is important to remember: when adding a new directory to your project,
1 you should add its ‘Makefile’ to this list, otherwise Automake will
1 never process the new ‘Makefile.am’ you wrote in that directory.)
1 
1    Finally, the ‘AC_OUTPUT’ line is a closing command that actually
1 produces the part of the script in charge of creating the files
1 registered with ‘AC_CONFIG_HEADERS’ and ‘AC_CONFIG_FILES’.
1 
1    When starting a new project, we suggest you start with such a simple
1 ‘configure.ac’, and gradually add the other tests it requires.  The
1 command ‘autoscan’ can also suggest a few of the tests your package may
11 need (⇒(automake))).
1