Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep intermediate files only on failure

Tags:

gnu-make

I've got a chained rule in my Makefile:

%.int: %.src
        preprocess -i $< -o $@

%.dst: %.int
        compile -i $< -o $@

SRCS=$(wildcard *.src)
DSTS=$(patsubst %.src,$.dst,$(SRCS))

all: $(DSTS)

It preprocesses .src to .int, and then compiles .int to .dst.

It works fine, except that GNU Make always deletes the intermediate files.

That's fine; I read the docs; I understand why it does that. I know that I can keep them around if I use .PRECIOUS or .SECONDARY pseudo-targets.

However, what I'd like to do is keep the intermediate file if and only if the int2dst step failed. Basically, I'd like to see what mess the preprocessor left me with.

Can I do that with GNU Make?

like image 611
Roger Lipscombe Avatar asked Mar 11 '26 23:03

Roger Lipscombe


1 Answers

A possible solution, though perhaps not a pretty one, would be to go ahead and put those files into .PRECIOUS, but then manually delete from the build rule:

%.dst: %.int
        compile -i $< -o $@
        rm $<
like image 93
Ove Avatar answered Mar 14 '26 08:03

Ove