f78
Chains of Implicit Rules
Contents|Index|Previous|Next
Chains of Implicit Rules
Sometimes a file can be made by a sequence of implicit rules. For example, a
file n.o could be made from n.y by running first Yacc and then cc. Such a sequence is called a chain.
If the file
n.c exists, or is mentioned in the makefile, no special searching is required:
make finds that the object file can be made by C compilation from n.c; later on, when considering how to make n.c, the rule for running Yacc is used. Ultimately both n.c and n.o are updated.
However, even if
n.c does not exist and is not mentioned, make knows how to envision it as the
missing link between n.o and n.y! In this case, n.c is called an intermediate file. Once make has decided to use the intermediate file, it is entered in the data base as if it had been mentioned in the makefile,
along with the implicit rule that says how to create it.
Intermediate files are remade using their rules just like all other files. The
difference is that the intermediate file is deleted when
make is finished. Therefore, the intermediate file which did not exist before make also does not exist after make. The deletion is reported to you by printing a rm -f command that shows what make is doing. (You can list the target pattern of
an implicit rule (such as %.o) as a dependency of the special target, .PRECIOUS, to preserve intermediate files made by implicit rules whose target patterns
match that files name; see Interrupting or Killing
892
make.)
A chain can involve more than two implicit rules. For example, it is possible
to make a file
foo from RCS/foo.y,v by running RCS, Yacc and cc. Then both foo.y and foo.c are intermediate files that are deleted at the end.
No single implicit rule can appear more than once in a chain. This means that
make will not even consider such a ridiculous thing as making foo from foo.o.o by running the linker twice. This constraint has the added benefit of
preventing any infinite loop in the search for an implicit rule chain.
There are some special implicit rules to optimize certain cases that would
otherwise be handled by rule chains. For example, making
foo from foo.c could be handled by compiling and linking with separate chained rules, using
foo.o as an intermediate file. But what actually happens is that a special rule
for this case does the compilation and linking with a single cc command. The optimized rule is used in preference to the step-by-step chain
because it comes earlier in the ordering of rules.
0