4.2 Building true and false

Here is another, trickier example. It shows how to generate two
programs (true and false) from the same source file
(true.c). The difficult part is that each compilation of
true.c requires different cpp flags.

Note that there is no true_SOURCES definition. Automake will
implicitly assume that there is a source file named true.c
(see Default _SOURCES), and
define rules to compile true.o and link true. The
‘true.o: true.c’ rule supplied by the above Makefile.am,
will override the Automake generated rule to build true.o.

false_SOURCES is defined to be empty—that way no implicit value
is substituted. Because we have not listed the source of
false, we have to tell Automake how to link the program. This is
the purpose of the false_LDADD line. A false_DEPENDENCIES
variable, holding the dependencies of the false target will be
automatically generated by Automake from the content of
false_LDADD.

The above rules won’t work if your compiler doesn’t accept both
-c and -o. The simplest fix for this is to introduce a
bogus dependency (to avoid problems with a parallel make):

As it turns out, there is also a much easier way to do this same task.
Some of the above technique is useful enough that we’ve kept the
example in the manual. However if you were to build true and
false in real life, you would probably use per-program
compilation flags, like so:

In this case Automake will cause true.c to be compiled twice,
with different flags. In this instance, the names of the object files
would be chosen by automake; they would be false-true.o and
true-true.o. (The name of the object files rarely matters.)