Function in the premise

A have a make target foo/%.bar. It corresponds to files, for example:

foo/x/y/z.bar foo/a.bar

Now I want a precondition prereq.othat must be in the same folder as the file .bar. Thus, for foo/x/y/z.bara prerequisite should be foo/x/y/prereq.o, for foo/a.barit should be foo/prereq.o.

How to do it?

I tried using the function diras follows:

foo/%.bar : foo/$(dir %)prereq.o

However, this does not work, because functions are evaluated before the templates are expanded. So how does it work?

+4
source share
1 answer

You should use .SECONDEXPANSION:

.SECONDEXPANSION:
foo/%.bar : foo/$$(dir %)prereq.o
    @echo $@ $<

$$ $$(dir...) , , .

+4

Source: https://habr.com/ru/post/1568475/


All Articles