开发者

how to get a particular dependency from the dependency list for a target

Suppose I have a following rul开发者_JS百科e in the Makefile:

%.foo: %.bar %.spam %.bot

<tab> echo "hello1" > $<

how can I also echo "hello2" into the second dependency (but not the .bot file), i.e. the .spam file? Thanks


%.foo: %.bar %.spam %.bot
    echo "hello1" > $<    
    echo hello2 > $(word 2,$^)

(Note that > overwrites, at least in the shells I know, which makes the whole exercise pretty pointless. To append, use >>.)


What you're asking is antithetical to the normal operation of make: a rule should modify the files named on the left of the colon, not the files on the right of the colon. You haven't given much context here, so it's hard to give you more specific advise than that.

As far as the particular question you've asked, you could use something like this:

%.foo: %.bar %.spam %.bot
    echo "hello1" > $<
    echo "hello2" > $*.spam

This uses the $* automatic variable, which is defined as the part of the filename that matched the % character in a pattern rule.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜