automake: Creating amhello

1 
1 2.4.1 Creating ‘amhello-1.0.tar.gz’
1 -----------------------------------
1 
1 Here is how we can recreate ‘amhello-1.0.tar.gz’ from scratch.  The
1 package is simple enough so that we will only need to write 5 files.
1 (You may copy them from the final ‘amhello-1.0.tar.gz’ that is
1 distributed with Automake if you do not want to write them.)
1 
1    Create the following files in an empty directory.
1 
1    • ‘src/main.c’ is the source file for the ‘hello’ program.  We store
1      it in the ‘src/’ subdirectory, because later, when the package
1      evolves, it will ease the addition of a ‘man/’ directory for man
1      pages, a ‘data/’ directory for data files, etc.
1           ~/amhello % cat src/main.c
1           #include <config.h>
1           #include <stdio.h>
1 
1           int
1           main (void)
1           {
1             puts ("Hello World!");
1             puts ("This is " PACKAGE_STRING ".");
1             return 0;
1           }
1 
1    • ‘README’ contains some very limited documentation for our little
1      package.
1           ~/amhello % cat README
1           This is a demonstration package for GNU Automake.
1           Type 'info Automake' to read the Automake manual.
1 
1    • ‘Makefile.am’ and ‘src/Makefile.am’ contain Automake instructions
1      for these two directories.
1 
1           ~/amhello % cat src/Makefile.am
1           bin_PROGRAMS = hello
1           hello_SOURCES = main.c
1           ~/amhello % cat Makefile.am
1           SUBDIRS = src
1           dist_doc_DATA = README
1 
1    • Finally, ‘configure.ac’ contains Autoconf instructions to create
1      the ‘configure’ script.
1 
1           ~/amhello % cat configure.ac
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    Once you have these five files, it is time to run the Autotools to
1 instantiate the build system.  Do this using the ‘autoreconf’ command as
1 follows:
1 
1      ~/amhello % autoreconf --install
1      configure.ac: installing './install-sh'
1      configure.ac: installing './missing'
1      configure.ac: installing './compile'
1      src/Makefile.am: installing './depcomp'
1 
1    At this point the build system is complete.
1 
1    In addition to the three scripts mentioned in its output, you can see
1 that ‘autoreconf’ created four other files: ‘configure’, ‘config.h.in’,
1 ‘Makefile.in’, and ‘src/Makefile.in’.  The latter three files are
1 templates that will be adapted to the system by ‘configure’ under the
1 names ‘config.h’, ‘Makefile’, and ‘src/Makefile’.  Let’s do this:
1 
1      ~/amhello % ./configure
1      checking for a BSD-compatible install... /usr/bin/install -c
1      checking whether build environment is sane... yes
1      checking for gawk... no
1      checking for mawk... mawk
1      checking whether make sets $(MAKE)... yes
1      checking for gcc... gcc
1      checking for C compiler default output file name... a.out
1      checking whether the C compiler works... yes
1      checking whether we are cross compiling... no
1      checking for suffix of executables...
1      checking for suffix of object files... o
1      checking whether we are using the GNU C compiler... yes
1      checking whether gcc accepts -g... yes
1      checking for gcc option to accept ISO C89... none needed
1      checking for style of include used by make... GNU
1      checking dependency style of gcc... gcc3
1      configure: creating ./config.status
1      config.status: creating Makefile
1      config.status: creating src/Makefile
1      config.status: creating config.h
1      config.status: executing depfiles commands
1 
1    You can see ‘Makefile’, ‘src/Makefile’, and ‘config.h’ being created
1 at the end after ‘configure’ has probed the system.  It is now possible
1 to run all the targets we wish (⇒Standard Targets).  For
1 instance:
1 
1      ~/amhello % make
1      ...
1      ~/amhello % src/hello
1      Hello World!
1      This is amhello 1.0.
1      ~/amhello % make distcheck
1      ...
1      =============================================
1      amhello-1.0 archives ready for distribution:
1      amhello-1.0.tar.gz
1      =============================================
1 
1    Note that running ‘autoreconf’ is only needed initially when the GNU
1 Build System does not exist.  When you later change some instructions in
1 a ‘Makefile.am’ or ‘configure.ac’, the relevant part of the build system
1 will be regenerated automatically when you execute ‘make’.
1 
1    ‘autoreconf’ is a script that calls ‘autoconf’, ‘automake’, and a
1 bunch of other commands in the right order.  If you are beginning with
1 these tools, it is not important to figure out in which order all of
1 these tools should be invoked and why.  However, because Autoconf and
1 Automake have separate manuals, the important point to understand is
1 that ‘autoconf’ is in charge of creating ‘configure’ from
1 ‘configure.ac’, while ‘automake’ is in charge of creating ‘Makefile.in’s
1 from ‘Makefile.am’s and ‘configure.ac’.  This should at least direct you
1 to the right manual when seeking answers.
1