开发者

How can I create make pattern rule that can expand the target as a dependency?

开发者 https://www.devze.com 2023-04-01 12:14 出处:网络
I\'m trying to create a makefile that has rule something like: ~/$ cat >开发者_开发技巧; Makefile << EOF

I'm trying to create a makefile that has rule something like:

~/$ cat >开发者_开发技巧; Makefile << EOF
FILES=a b c
$(FILES): % : src/%/%
        @echo "$@ $<"
EOF

Running the command gives:

~/$ make a
make: *** No rule to make target `src/a/%', needed by `a'.  Stop.

And what I'd like to see is:

~/$ make a
a src/a/a

How do a create rule to expand the second %?


In this case, secondary expansion might help.
For example:

FILES=a b c
.SECONDEXPANSION:
$(FILES): % : src/$$*/$$*
    @echo "$@ $<"

If your GNU make's version is 3.80 or lower, $* might not work. In that case, $@ and some text manipulation might be needed instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消