I have intermediate files that I want to keep only if they were successfully produced.
Here is my current attempt:
all: foo.result
%.result: %.intermediate
cp $^ $@
%.input:
touch $@
%.intermediate: %.input
touch $@
$(if $(FAIL),exit 1)
.PRECIOUS: %.intermediate
.DELETE_ON_ERROR: %.intermediate
clean:
rm -f *.intermediate *.input *.result
To make it painfully clear what I'm after, run this and try to get no output:
(make clean && make foo.result) |&> /dev/null; if [[ ! -e foo.intermediate ]]; then echo "make removed precious intermediate file"; fi; (make clean && make foo.result FAIL=1) |&> /dev/null; if [[ -e foo.intermediate ]]; then echo "make did not remove corrupt file"; fi;