3
votes

I have a makefile that does something like this:

.INTERMEDIATE: gen0.tmp gen1.tmp
.PHONY: %_test
%_test: tests/%.so
    ln -fs $< test.so
tests/%.so: gen.o test_src/%.c
    cc -shared $^ -o $@
gen.c: gen0.tmp gen1.tmp
    cat $^ > $@
gen%.tmp:
    seds and awks and non-relevant stuff    

As far as i have understood make's documentation, all files created from implicit rules are treated as intermediate, but that is not true for pattern rules, yet whatever .so i create with %_test rule is being deleted with other intermediate files, unless it existed before calling make. What is wrong here?

Also

.SECONDARY: tests/%.so

Doesn't work and

.SECONDARY:

does, but then targets explicitly marked as .INTERMEDIATE aren't beeing deleted, and i don't think marking my main target as .SECONDARY is good practice.

PS: i use make version 3.81

1
Have you tried using .PRECIOUS? It should work even with patterns. - Eugeniu Rosca
it still would be just a workaround. other good workaround is to remove %_test rule and do the ln in `test/%.so. I'm not looking for a way to preserve intermediate file, i'm looking for a way to make file non-intermediate, as it should be - Ryba

1 Answers

1
votes

I don't understand your statement all files created from implicit rules are treated as intermediate, but that is not true for pattern rules.

A pattern rule IS a (type of) implicit rule. It absolutely is the case that targets which are created as a result of a pattern rule may be considered intermediate.