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


6 The top-level Makefile.am

In packages with subdirectories, 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 packages that use subdirectories, 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 = @MY_SUBDIRS@

Then in your configure.in you can specify:

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

(Note that we don’t use the variable name SUBDIRS in our configure.in; that would cause Automake to believe that every Makefile.in should recurse into the listed subdirectories.)

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. When Automake invokes make in a subdirectory, it uses the value of the MAKE variable. It passes the value of the variable AM_MAKEFLAGS to the make invocation; this can be set in Makefile.am if there are flags you must always pass to make.

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. All ‘clean’ targets are run in reverse order of build targets.

Sometimes, such as when running make dist, you want all possible subdirectories to be examined. In this case Automake will use DIST_SUBDIRS, instead of SUBDIRS, to determine where to recurse. This variable will also be used when the user runs distclean or maintainer-clean. It should be set to the full list of subdirectories in the project. If this macro is not set, Automake will attempt to set it for you.


Next: An Alternative Approach to Subdirectories, Previous: Scanning configure.in, Up: GNU Automake   [Contents][Index]