4

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

Eugeniu Rosca
  • 5,177
  • 16
  • 45
Ryba
  • 681
  • 4
  • 13
  • Have you tried using [`.PRECIOUS`](https://www.gnu.org/software/make/manual/html_node/Special-Targets.html)? It should work even [with patterns](http://stackoverflow.com/questions/27090032/why-secondary-does-not-work-with-patterns-while-precious-does). – Eugeniu Rosca Jul 09 '15 at 07:29
  • 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 Jul 09 '15 at 07:48

1 Answers1

2

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.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • then i may have understood doc wrong. I tought that by implicit it means whatever is not in makefile, but works. – Ryba Jul 10 '15 at 07:01
  • Nope. Explicit rules are ones where the target is an actual file; this includes static pattern rules. Implicit rules are ones where make computes the target from the rule: it includes both suffix rules and pattern rules. The list of rules make knows about internally that aren't in the makefile are referred to as built-in rules. – MadScientist Jul 10 '15 at 16:13