automake processes Makefile.am to produce a
automake does a lot of work
for you: it keeps up with dependencies between source
files, for example. It creates all the standard targets,
such as install and clean. It also creates more complex
targets: simply typing make
dist creates a standard
.tar.gz file if your
Makefile.am is correct.
The Makefile.am in the top source
directory is generally very simple; here is an example:
SUBDIRS = macros po intl src pixmaps doc
## We dist autogen.sh since this is an example program
## Real-world programs do not need to distribute autogen.sh
EXTRA_DIST = \
Applicationsdir = $(datadir)/gnome/apps/Applications
Applications_DATA = gnome-hello.desktop
The SUBDIRS line instructs automake to recursively look for
Makefile.am files in the given
section called .desktop
Entries describes the remainder of the file, ignore
it for now.) The Makefile.am in
the src directory is a little
INCLUDES = -I$(top_srcdir) -I$(includedir) $(GNOME_INCLUDEDIR) \
-DG_LOG_DOMAIN=\"GnomeHello\" -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
bin_PROGRAMS = gnome-hello
gnome_hello_SOURCES = \
gnome_hello_LDADD = $(GNOMEUI_LIBS) $(GNOME_LIBDIR) $(INTLLIBS)
automake understands a number
of "magic variables" and can use them to create Makefile.in. In the small example above,
the following variables are used:
INCLUDES specifies flags
to pass to the C compiler during the compile phase (as
opposed to the link phase). The variables used in this
line come from the
configure.in shown in the previous section.
bin_PROGRAMS lists the
programs to be compiled.
hello_SOURCES lists the
files to be compiled and linked to create the program
called hello; hello must be listed in bin_PROGRAMS. All files in this
variable are automatically included in the
hello_LDADD lists flags to
be passed to the linker. In this case, Gnome library
flags determined by
Several elements of the
INCLUDES line should be used in all Gnome programs.
G_LOG_DOMAIN should always be
defined; error messages from checks and assertions will
report this value, so you can determine where the error
occurred (in your code, or in a library). GNOMELOCALEDIR is used to locate
translation files. The intl
directory is added to the header search path so the
application can find the intl
There are many more complex things one can do in Makefile.am; in particular, you can add @-bounded variables to be
substituted by configure, you can
conditionally include portions of the
Makefile based on configure
checks, and you can build libraries. The automake manual gives more details.
Table 1 summarizes
the most interesting targets generated by automake. Of course the default target
is all, which compiles the
program. The GNU Coding Standards (http://www.gnu.org/prep/standards_toc.html) have
more information about these targets and GNU makefiles in
Table 1. Standard make
Builds a tarball (.tar.gz) for distribution
Builds a tarball, then tries to compile it
Deletes the results of compilation (object files and
executables), but may not delete some generated files
that come with the distribution.
Creates installation directories if needed, and
copies the software into them.
Reverses the install (deletes installed files).
Reverse the effects of the
configure script and the all target; that is, revert a
tarball to its pristine state.
Nearly the same as
clean, but leaves some object files that most
likely don't need to be rebuilt.
More thorough than
clean; may delete some files that require
special tools to rebuild, such as machine-generated
Creates a tag table, for use with Emacs.
Runs a test suite if you have one