automake: true
1
1 4.2 Building true and false
1 ===========================
1
1 Here is another, trickier example. It shows how to generate two
1 programs (‘true’ and ‘false’) from the same source file (‘true.c’). The
1 difficult part is that each compilation of ‘true.c’ requires different
1 ‘cpp’ flags.
1
1 bin_PROGRAMS = true false
1 false_SOURCES =
1 false_LDADD = false.o
1
1 true.o: true.c
1 $(COMPILE) -DEXIT_CODE=0 -c true.c
1
1 false.o: true.c
1 $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
1
1 Note that there is no ‘true_SOURCES’ definition. Automake will
11 implicitly assume that there is a source file named ‘true.c’ (⇒
Default _SOURCES), and define rules to compile ‘true.o’ and link
1 ‘true’. The ‘true.o: true.c’ rule supplied by the above ‘Makefile.am’,
1 will override the Automake generated rule to build ‘true.o’.
1
1 ‘false_SOURCES’ is defined to be empty—that way no implicit value is
1 substituted. Because we have not listed the source of ‘false’, we have
1 to tell Automake how to link the program. This is the purpose of the
1 ‘false_LDADD’ line. A ‘false_DEPENDENCIES’ variable, holding the
1 dependencies of the ‘false’ target will be automatically generated by
1 Automake from the content of ‘false_LDADD’.
1
1 The above rules won’t work if your compiler doesn’t accept both ‘-c’
1 and ‘-o’. The simplest fix for this is to introduce a bogus dependency
1 (to avoid problems with a parallel ‘make’):
1
1 true.o: true.c false.o
1 $(COMPILE) -DEXIT_CODE=0 -c true.c
1
1 false.o: true.c
1 $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
1
1 As it turns out, there is also a much easier way to do this same
1 task. Some of the above technique is useful enough that we’ve kept the
1 example in the manual. However if you were to build ‘true’ and ‘false’
1 in real life, you would probably use per-program compilation flags, like
1 so:
1
1 bin_PROGRAMS = false true
1
1 false_SOURCES = true.c
1 false_CPPFLAGS = -DEXIT_CODE=1
1
1 true_SOURCES = true.c
1 true_CPPFLAGS = -DEXIT_CODE=0
1
1 In this case Automake will cause ‘true.c’ to be compiled twice, with
1 different flags. In this instance, the names of the object files would
1 be chosen by automake; they would be ‘false-true.o’ and ‘true-true.o’.
1 (The name of the object files rarely matters.)
1