[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why is make not deleting intermediate files?

From: Reece Hart
Subject: Why is make not deleting intermediate files?
Date: Thu, 19 Jan 2012 14:48:02 -0800

Environment: Ubuntu 11.10, make 3.81

make is not deleting intermediate files when the dependency appears in
more than one rule. This occurs even when I explicitly declare the
intermediate file as such using .INTERMEDIATE with a pattern, the
literal filename, or both.

I've distilled the issue to this test case:

    @echo no $@ target; exit 1

oncetwice: once twice
    @echo $@: $^

## Uncommenting the following line is sufficient to cause GNU make 3.81 to
## not delete the intermediate 'twice.dep', even if it didn't exist
## previously (i.e., was created by this invocation).
#another: twice.dep

%: %.dep
    @echo $^ >$@

## the following .INTERMEDIATE has no effect re: the twice: twice.dep
## dependency
    @echo $@ >$@

N.B. command blocks must be tab-indented.

That is, the target `once' depends on `once.dep' and `twice' depends
on `twice.dep'. In addition, `another' also depends on `twice.dep'. It
is this line that causes `twice.dep' to never be removed, even if make
created it and despite the .INTERMEDIATE line (which seems to have no

The Makefile as posted gives:

snafu$ rm -f once* twice*; make oncetwice
oncetwice: once twice
rm once.dep twice.dep

Uncommenting the twice: twice.dep line:

snafu$ rm -f once* twice*; make oncetwice
oncetwice: once twice
rm once.dep

Notice that `twice.dep' is not rm'd in the second invocation.

>From the info pages:

The targets which .INTERMEDIATE depends on are treated as intermediate files.


Intermediate files are remade using their rules just like all other
files. But intermediate files are treated differently in two ways.

The first difference [...]

**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.**

My expectation is that `twice.dep' would be deleted even without the
.INTERMEDIATE declaration, and especially with it given the info
manual description above. It appears that `twice.dep' is being treated
more like a .SECONDARY file than an intermediate.

I've tried: 1) making `another: twice.dep' a rule with a command
block; 2) variations of specifying .INTERMEDIATE as a pattern, a
literal filename, and both; 3) using .PHONY; 4) browsing make-3.82
NEWS for relevant fixes.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]