Subject: Bug#4073: make pattern rules delete intermediate files

From: Ian Jackson <[email-masked]>
Date: Thu, 8 Aug 96 17:39 BST

Package: make
Version: 3.74-11

Given the Makefile below in an empty directory:
 chiark:d> make clean
 rm -f t.* u.*
 chiark:d> make
 echo bar >t.bar
 echo foo >t.foo
 echo wombat >u.wombat
 echo spong >u.spong
 rm t.bar
 chiark:d>

We see that the intermediate file used for the pattern rules (%.bar)
is removed by make, and that this doesn't happen if we use suffix
rules.

This is silly.  Consider the dependency graph (a --> b means a is
required to generate b, and b depends on a):
  a --> b --+--> d
  c --------'
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 defeats the purpose of
using make, which is supposed to avoid rebuilding files unnecessarily.

This doesn't appear to happen if the rules involved are ordinary
targets, only if they're pattern targets.

I can't find any documentation about this `feature', and there doesn't
appear to be a way to turn it off.

Ian.

PS: You may need to put this Makefile through `unexpand' to put the
tabs back.  It has them now when I send the message, but tabs are
notorious for being mangled.

.SUFFIXES:
.SUFFIXES: .spong .wibble .wombat

all:		t.foo u.spong

%.foo:		%.bar
		echo foo >$@

%.bar:
		echo bar >$@

.spong.wibble:
		echo wibble >$@

.wombat.spong:
		echo spong >$@

u.wombat:
		echo wombat >$@

clean:
		rm -f t.* u.*

---

From: Ian Jackson <[email-masked]>
Date: Fri, 9 Aug 96 14:30 BST

I've since found the documentation where it explains where this
happens.

However:

(a) It doesn't say that it doesn't remove the intermediate targets of
suffix rules.

(b) The documented 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
build.

(c) I think that the feature is of doubtful value anyway, especially
when the final target has dependencies other than the intermediate
target.

(d) There is no general way to turn the feature off, except perhaps by
saying `.PRECIOUS: %' - see (b).

My apologies for missing the documentation for this the first time
round, but I still think there are issues to be resolved here.

Ian.