Next: , Previous: , Up: GNU Automake   [Contents][Index]


6 The top-level Makefile.am

In non-flat packages, the top level Makefile.am must tell Automake which subdirectories are to be built. This is done via the SUBDIRS variable.

The SUBDIRS macro holds a list of subdirectories in which building of various sorts can occur. Many targets (e.g. all) in the generated Makefile will run both locally and in all specified subdirectories. Note that the directories listed in SUBDIRS are not required to contain Makefile.ams; only Makefiles (after configuration). This allows inclusion of libraries from packages which do not use Automake (such as gettext). The directories mentioned in SUBDIRS must be direct children of the current directory. For instance, you cannot put ‘src/subdir’ into SUBDIRS.

In a deep package, the top-level Makefile.am is often very short. For instance, here is the Makefile.am from the GNU Hello distribution:

EXTRA_DIST = BUGS ChangeLog.O README-alpha
SUBDIRS = doc intl po src tests

It is possible to override the SUBDIRS variable if, like in the case of GNU Inetutils, you want to only build a subset of the entire package. In your Makefile.am include:

SUBDIRS = @SUBDIRS@

Then in your configure.in you can specify:

SUBDIRS = "src doc lib po"
AC_SUBST(SUBDIRS)

The upshot of this is that Automake is tricked into building the package to take the subdirs, but doesn’t actually bind that list until configure is run.

Although the SUBDIRS macro can contain configure substitutions (e.g. ‘@DIRS@’); Automake itself does not actually examine the contents of this variable.

If SUBDIRS is defined, then your configure.in must include AC_PROG_MAKE_SET.

The use of SUBDIRS is not restricted to just the top-level Makefile.am. Automake can be used to construct packages of arbitrary depth.

By default, Automake generates Makefiles which work depth-first (‘postfix’). However, it is possible to change this ordering. You can do this by putting ‘.’ into SUBDIRS. For instance, putting ‘.’ first will cause a ‘prefix’ ordering of directories.


Next: Building Programs and Libraries, Previous: Scanning configure.in, Up: GNU Automake   [Contents][Index]