Next: , Previous: , Up: Programs   [Contents][Index]

7.1.3 Default sources

_SOURCES variables are used to specify source files of programs (see Programs), libraries (see Libraries), and Libtool libraries (see Shared libraries).

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 with no corresponding libfoo_a_SOURCES:

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 can be useful in test suites, when building many test programs each from a single source. For instance, in

check_PROGRAMS = test1 test2 test3

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 (, each defined in its own file (modulen.c).

AM_LDFLAGS = -module

Finally, there is one situation where this default source computation needs to be avoided: when a target should not be built from sources. 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

Next: , Previous: , Up: Programs   [Contents][Index]