1

I've read the official documentation about chains of implicit rules and I believe that this is the reason why I observe this behavior, although I can't quite comprehend why.

Let's say we have the following Makefile:

.DELETE_ON_ERROR:
.PHONY: all

SOURCES := $(wildcard *.source)
RESULTS := $(SOURCES:.source=/done)

%/a %/b %/c : %.source
    mkdir $* && cd $* && touch a && touch b && touch c

%/d : %/a
    cd $* && touch d

%/done : %/d %/b %/c
    touch $@

all : $(RESULTS)
    echo "Handled: $^"

If i go to some local directory and do the following steps:

$ touch 123.source
$ make
mkdir 123 && cd 123 && touch a && touch b && touch c
cd 123 && touch d
touch 123/done
echo "Handled: 123/done"
Handled: 123/done
rm 123/d 123/a

The thing that looks confusing to me is that make only removes d and a, but not the rest of the intermediate files, why so? The same happens when make fails. If I insert an exit 1 step inside a rule for %/done, then make will remove a and d upon failure and will keep the rest of the files.

So my questions would be:

  1. Why make decides to remove a and d in case of success while keeping the rest of the files? I don't see a reason why these are removed. In case a and d are parts of implicit chain of rules, then the same must be applied to b and c, because they also don't exist when make starts.
  2. Why in case of failure, make removes only a and d, but not b and c? I would expect .DELETE_ON_ERROR to remove them as well and I can't explain this behavior. It behaves as if b and c were defined as .PRECIOUS.
Daniel
  • 635
  • 1
  • 5
  • 22
  • 2
    Seems like a bug to me. Rather than what you suggest, I believe it more likely that the handling of grouped targets is not interacting with intermediate files properly. You might consider filing a bug about it. – MadScientist Sep 23 '20 at 16:13
  • 1
    I agree with @MadScientist. If you run `make -p` you can notice that only `123/a` and `123/d` are marked as intermediate (`# File is an intermediate prerequisite.`) hence only those two are removed. – raspy Sep 27 '20 at 20:05

0 Answers0