Autotool Notes—automake and Makefile.am

This just covers the Makefile.am file and its format.

The master automake documentation can be found at http://sources.redhat.com/automake/automake.pdf

See http://vipe.technion.ac.il/~shlomif/lecture/Autotools/slides/Makefile_am for some useful examples and elaboration.

A simple way to think about autotools is to separate them. You might use autoconf to build your project, writing your own Makefile.in. However, as your project complexity increases, you sense the need to resort to automake.


Super targets...

automake works by generating Makefile.in from Makefile.am. From the former, autoconf generates Makefile actually used.


Comments...

automake will not copy comments delimited with ## over into the output file.


Naming schemes (primaries)...

automake employs a uniform naming scheme in which primaries that tell it what is being built. One is PROGRAMS including bin_PROGRAMS, sbin_PROGRAMS, noinst_PROGRAMS, etc. You are used to seeing these in Makefile.am.

The primaries automake recognizes are:

All primaries must be prefixed; to fail to do so is nonsense and an error. Certain prefixes to the primaries have meaning...

automake requires canonicalized forms of objects when it has to make a variable of them, for instance, the primary for an installed binary to be named go-fish is nevertheless referred to as go_fish_PROGRAMS since the minus sign would not allow go-fish_PROGRAMS to be one identifier/token.


Shadow variables...

automake respects the ownership of common, traditional variable such as CFLAGS by leaving them to the user. (The user is not the package builder who writes Makefile.am.)

Instead, shadow variables are created that will be specially recognized by automake: AM_CFLAGS.


Super targets...

This is a partial list...

   
  bin_PROGRAMS(program-list) a program or programs build in the local directory that should be compiled, linked and installed.
  noinst_PROGRAMS(program-list) a program or programs build in the local directory that should be compiled, linked but not installed.
  bin_SCRIPTS(script-list) a script or scripts build in the local directory that should be installed.
  man_MANS(page-list) man pages that should be installed.
  lib_LTLIBRARIES(lib-list) a library or libraries that should be built using libtool.

Source files, headers and libraries...

(Note: in our sample names here, imagine a special pthread reader-writer locking package subtitled “first-com, first-served”.)

Specify the source files for each (super) target by typing the base name of the package with an underscore (_) rather than hyphen (-) followed by _SOURCES followed by an equal sign and a list of sources. For example,

	lockproj_SOURCES                  = main.c
	lib_LTLIBRARIES                   = libpthread_rwlock_fcfs.la
	libpthread_rwlock_fcfs_la_SOURCES = rwlock.c queue.c
	libpthread_rwlock_fcfs_la_HEADERS = rwlock_fcfs.h

To link a (super) target with an internal library, specify the target name as before along with _LDADD and the library name ending with .la:

	lockproj_LDADD = libpthread_rwlock_fcfs.la

Plain, old makefile syntax...

Plain makefile grammar rules may be specified in Makefile.am using meta variables like $<, $@ and $*. It also includes macros.


EXTRA_DIST...

...is used to specify all of the other files in a package that aren’t installed by default nor specified in any other way including README.txt, AUTHORS and maintenance scripts.


SUBDIRS...

...is used to list one or more subdirectories that are to participate in the project build, but with their own configuration (a different configure.in). Indicate the subdirectory thus, then use AC_CONFIG_SUBDIRS in configure.in to configure it as a separate directory (or directories).