Go to the first, previous, next, last section, table of contents.


Building etags and ctags

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

bin_PROGRAMS = etags ctags
ctags_SOURCES =
ctags_LDADD = ctags.o

etags.o: etags.c
        $(COMPILE) -DETAGS_REGEXPS -c etags.c

ctags.o: etags.c
        $(COMPILE) -DCTAGS -o ctags.o -c etags.c

Note that ctags_SOURCES is defined to be empty--that way no implicit value is substituted. The implicit value, however, is used to generate etags from `etags.o'.

ctags_LDADD is used to get `ctags.o' into the link line. ctags_DEPENDENCIES is generated by Automake.

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):

etags.o: etags.c ctags.o
        $(COMPILE) -DETAGS_REGEXPS -c etags.c

ctags.o: etags.c
        $(COMPILE) -DCTAGS -c etags.c && mv etags.o ctags.o

Also, these explicit rules do not work if the de-ANSI-fication feature is used (see section Automatic de-ANSI-fication). Supporting de-ANSI-fication requires a little more work:

etags._o: etags._c ctags.o
        $(COMPILE) -DETAGS_REGEXPS -c etags.c

ctags._o: etags._c
        $(COMPILE) -DCTAGS -c etags.c && mv etags._o ctags.o

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

bin_PROGRAMS = ctags etags

ctags_SOURCES = etags.c
ctags_CFLAGS = -DCTAGS

etags_SOURCES = etags.c
etags_CFLAGS = -DETAGS_REGEXPS

In this case Automake will cause `etags.c' to be compiled twice, with different flags. De-ANSI-fication will work automatically. In this instance, the names of the object files would be chosen by automake; they would be `ctags-etags.c' and `etags-etags.o'. (The name of the object files rarely matters.)


Go to the first, previous, next, last section, table of contents.