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:
- Why
make
decides to removea
andd
in case of success while keeping the rest of the files? I don't see a reason why these are removed. In casea
andd
are parts of implicit chain of rules, then the same must be applied tob
andc
, because they also don't exist whenmake
starts. - Why in case of failure,
make
removes onlya
andd
, but notb
andc
? I would expect.DELETE_ON_ERROR
to remove them as well and I can't explain this behavior. It behaves as ifb
andc
were defined as.PRECIOUS
.