A have a make target foo/%.bar
. It matches files like:
foo/x/y/z.bar
foo/a.bar
Now, I want a prerequisite prereq.o
which must reside in the same folder than the .bar
file. Thus, for foo/x/y/z.bar
the prerequisite should be foo/x/y/prereq.o
, for foo/a.bar
it should be foo/prereq.o
.
How to achieve this?
I tried using the dir
function like this:
foo/%.bar : foo/$(dir %)prereq.o
However, this does not work because functions are evaluated before the patterns are expanded. So how does it work?
You have to use .SECONDEXPANSION
:
.SECONDEXPANSION:
foo/%.bar : foo/$$(dir %)prereq.o
@echo $@ $<
The $$
in $$(dir...)
is necessary so that it is not evaluated until the second expansion occurs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With