19 Include

Automake supports an include directive that can be used to include other Makefile fragments when automake is run. Note that these fragments are read and interpreted by automake, not by make. As with conditionals, make has no idea that include is in use.

There are two forms of include:

include $(srcdir)/file

Include a fragment that is found relative to the current source directory.

include $(top_srcdir)/file

Include a fragment that is found relative to the top source directory.

Note that if a fragment is included inside a conditional, then the condition applies to the entire contents of that fragment.

Makefile fragments included this way are always distributed because they are needed to rebuild Makefile.in.

Inside a fragment, the construct %reldir% is replaced with the directory of the fragment relative to the base Makefile.am. Similarly, %canon_reldir% is replaced with the canonicalized (see How derived variables are named) form of %reldir%. As a convenience, %D% is a synonym for %reldir%, and %C% is a synonym for %canon_reldir%.

A special feature is that if the fragment is in the same directory as the base Makefile.am (i.e., %reldir% is .), then:

%reldir%

together with a following slash expands to the empty string, otherwise it expands to a dot;

%canon_reldir%

together with a following underscore expands to the empty string, otherwise it expands to an underscore.

Thus, a Makefile fragment might look like this:

bin_PROGRAMS += %reldir%/mumble
%canon_reldir%_mumble_SOURCES = %reldir%/one.c