如何从目标的依赖项列表中获取特定的依赖项
假设我在 Makefile 中有以下规则:
%.foo: %.bar %.spam %.bot
<代码><选项卡>回声“你好1”> $<
我怎样才能将“hello2”回显到第二个依赖项(但不是 .bot 文件),即 .spam 文件?谢谢
Suppose I have a following rule 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(请注意,
>
会覆盖,至少在我所知道的 shell 中是这样,这使得整个练习毫无意义。要附加,请使用>>
。)(Note that
>
overwrites, at least in the shells I know, which makes the whole exercise pretty pointless. To append, use>>
.)您所要求的内容与 make 的正常操作相反:规则应该修改冒号左侧上命名的文件,而不是冒号右侧上命名的文件冒号。您在这里没有提供太多背景信息,因此很难给您比这更具体的建议。
至于您提出的特定问题,您可以使用如下内容:
这使用
$*
自动变量,它被定义为与%< 匹配的文件名部分/code> 模式规则中的字符。
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:
This uses the
$*
automatic variable, which is defined as the part of the filename that matched the%
character in a pattern rule.