Bug#4073: make pattern rules delete intermediate files
I have looked at make 3.75 and the behaviour persists
;-(. However, I did come across a special target .SECONDARY.
The targets which `.SECONDARY' depends on are treated as intermediate
files, except that they are never automatically deleted. *Note
Chains of Implicit Rules: Chained Rules.*.
Unfortunately, using .SECONDARY special target is not
convenient, since unlike .PRECIOUS, it does not accept a pattern as a
target; one has to explicitly mention each possible target.
Oh, and the docs now state that suffix rules are deprecated
and only supported in make for compatibility reasons (of course,
that's no excuse for being inconsistent).
I am forwarding this report to the upstream maintainer. I
took the liberty of including the documentation I managed to snarf in
this mail message.
Synopsis of the Bug:
Consider the dependency graph (a --> b means a is required to generate
b, and b depends on a):
a --> b --+--> d
where b and d are automatically generated.
Now if you start with a clean directory and say `make d' make
generates b from a, and then d from b and c. However, it then deletes
b again. If you edit c and want to rebuild it has to regenerate b,
and it ends up doing this every time.
This is silly. If the final target has dependencies other than the
intermediate target, this defeats the purpose of using make, which is
supposed to avoid rebuilding files unnecessarily.
(a) One way to turn it off, using .PRECIOUS, has other undesirable
side-effects - namely, it prevents make from removing the file
when interrupted, so that the timestamp may be wrong for the next
(b) Using .SECONDARY special target is not convenient, since unlike
.PRECIOUS, it does not accept a pattern as a target; one has to
explicitly mention each possible target.
(c) Using .SECONDARY with no targets did not prevent deletion of
t.bar, since I guess t.bar is not a file target (just a target in
a pattern rule).
(d) It doesn't say that it doesn't remove the intermediate targets of
suffix rules. (I know that suffix rules are only supported for
compatibility reasons, but may they should be consistent vis-a-vis
Special Built-in Target Names
The targets which `.PRECIOUS' depends on are given the following
special treatment: if `make' is killed or interrupted during the
execution of their commands, the target is not deleted. *Note
Interrupting or Killing `make': Interrupts. Also, if the target
is an intermediate file, it will not be deleted after it is no
longer needed, as is normally done. *Note Chains of Implicit
Rules: Chained Rules.
You can also list the target pattern of an implicit rule (such as
`%.o') as a dependency file of the special target `.PRECIOUS' to
preserve intermediate files created by rules whose target patterns
match that file's name.
The targets which `.INTERMEDIATE' depends on are treated as
intermediate files. *Note Chains of Implicit Rules: Chained Rules.
`.INTERMEDIATE' with no dependencies marks all file targets
mentioned in the makefile as intermediate.
The targets which `.SECONDARY' depends on are treated as
intermediate files, except that they are never automatically
deleted. *Note Chains of Implicit Rules: Chained Rules.
`.SECONDARY' with no dependencies marks all file targets mentioned
in the makefile as secondary.
Any defined implicit rule suffix also counts as a special target if
it appears as a target, and so does the concatenation of two suffixes,
such as `.c.o'. These targets are suffix rules, an obsolete way of
defining implicit rules (but a way still widely used). In principle,
any target name could be special in this way if you break it in two and
add both pieces to the suffix list. In practice, suffixes normally
begin with `.', so these special target names also begin with `.'.
*Note Old-Fashioned Suffix Rules: Suffix Rules.
Chains of Implicit Rules
Intermediate files are remade using their rules just like all other
files. But intermediate files are treated differently in two ways.
The first difference is what happens if the intermediate file does
not exist. If an ordinary file B does not exist, and `make' considers
a target that depends on B, it invariably creates B and then updates
the target from B. But if B is an intermediate file, then `make' can
leave well enough alone. It won't bother updating B, or the ultimate
target, unless some dependency of B is newer than that target or there
is some other reason to update that target.
The second difference is that if `make' *does* create B in order to
update something else, it deletes B later on after it is no longer
needed. Therefore, an intermediate file which did not exist before
`make' also does not exist after `make'. `make' reports the deletion
to you by printing a `rm -f' command showing which file it is deleting.
Ordinarily, a file cannot be intermediate if it is mentioned in the
makefile as a target or dependency. However, you can explicitly mark a
file as intermediate by listing it as a dependency of the special target
`.INTERMEDIATE'. This takes effect even if the file is mentioned
explicitly in some other way.
You can prevent automatic deletion of an intermediate file by
marking it as a "secondary" file. To do this, list it as a dependency
of the special target `.SECONDARY'. When a file is secondary, `make'
will not create the file merely because it does not already exist, but
`make' does not automatically delete the file. Marking a file as
secondary also marks it as intermediate.
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 file's name; see *Note Interrupts::.
Old-Fashioned Suffix Rules
"Suffix rules" are the old-fashioned way of defining implicit rules
for `make'. Suffix rules are obsolete because pattern rules are more
general and clearer. They are supported in GNU `make' for
compatibility with old makefiles. They come in two kinds:
"double-suffix" and "single-suffix".
A double-suffix rule is defined by a pair of suffixes: the target
suffix and the source suffix. It matches any file whose name ends with
the target suffix. The corresponding implicit dependency is made by
replacing the target suffix with the source suffix in the file name. A
two-suffix rule whose target and source suffixes are `.o' and `.c' is
equivalent to the pattern rule `%.o : %.c'.
A single-suffix rule is defined by a single suffix, which is the
source suffix. It matches any file name, and the corresponding implicit
dependency name is made by appending the source suffix. A single-suffix
rule whose source suffix is `.c' is equivalent to the pattern rule `% :
Suffix rule definitions are recognized by comparing each rule's
target against a defined list of known suffixes. When `make' sees a
rule whose target is a known suffix, this rule is considered a
single-suffix rule. When `make' sees a rule whose target is two known
suffixes concatenated, this rule is taken as a double-suffix rule.
"You must either master politics or be mastered by those that do."
Manoj Srivastava <firstname.lastname@example.org>
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-REQUEST@lists.debian.org . Trouble? e-mail to Bruce@Pixar.com