_SOURCES variables are used to specify source files of programs
(see A Program), libraries (see A Library), and Libtool
libraries (see A Shared Library).
When no such variable is specified for a target, Automake will define
one itself. The default is to compile a single C file whose base name
is the name of the target itself, with any extension replaced by
AM_DEFAULT_SOURCE_EXT, which defaults to .c.
For example if you have the following somewhere in your
Makefile.am with no corresponding
lib_LIBRARIES = libfoo.a sub/libc++.a
libfoo.a will be built using a default source file named
libfoo.c, and sub/libc++.a will be built from
sub/libc++.c. (In older versions sub/libc++.a
would be built from sub_libc___a.c, i.e., the default source
was the canonized name of the target, with .c appended.
We believe the new behavior is more sensible, but for backward
compatibility automake will use the old name if a file or a rule
with that name exists and
AM_DEFAULT_SOURCE_EXT is not used.)
Default sources are mainly useful in test suites, when building many test programs each from a single source. For instance, in
check_PROGRAMS = test1 test2 test3 AM_DEFAULT_SOURCE_EXT = .cpp
test1, test2, and test3 will be built from test1.cpp, test2.cpp, and test3.cpp. Without the last line, they will be built from test1.c, test2.c, and test3.c.
Another case where this is convenient is building many Libtool modules (modulen.la), each defined in its own file (modulen.c).
AM_LDFLAGS = -module lib_LTLIBRARIES = module1.la module2.la module3.la
Finally, there is one situation where this default source computation
needs to be avoided: when a target should not be built from sources.
We already saw such an example in true; this happens when all
the constituents of a target have already been compiled and just need
to be combined using a
_LDADD variable. Then it is necessary
to define an empty
_SOURCES variable, so that automake
does not compute a default.
bin_PROGRAMS = target target_SOURCES = target_LDADD = libmain.a libmisc.a