automake: Default _SOURCES

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