如何在 make 模式规则的依赖项中使用模式相关变量
我想使用模式相关变量中的依赖项来定义 GNU make 模式规则。我想要的是这样的:
%.exe : $(%_EXE_SOURCES) $(%_EXE_RESOURCES)
$(CSC_V)$(CSC) $(CSCFLAGS) $($*_EXE_CSCFLAGS) -target:exe \
-out:$@ $($*_EXE_SOURCES) $($*_EXE_RESOURCES)
稍后定义类似的内容
FOO_EXE_SOURCES = src/Foo.cs
all: Foo.exe
提出的规则可以构建;在规则正文中,$($*_EXE_SOURCES)
变量扩展为 $(FOO_EXE_SOURCES)
,后者扩展为 src/Foo.cs
。然而,依赖关系不能正确扩展;更改 src/Foo.cs 不会导致 Foo.exe 被重建。
我怀疑这实际上不能在 make 中完成,但也许有人有一个类似工作的 make 片段?
I'd like to define a GNU make pattern rule with the dependencies in a pattern-dependent variable. What I'd like is something like this:
%.exe : $(%_EXE_SOURCES) $(%_EXE_RESOURCES)
$(CSC_V)$(CSC) $(CSCFLAGS) $($*_EXE_CSCFLAGS) -target:exe \
-out:$@ $($*_EXE_SOURCES) $($*_EXE_RESOURCES)
And to later define something like
FOO_EXE_SOURCES = src/Foo.cs
all: Foo.exe
The rule presented works to build; in the body of the rule the $($*_EXE_SOURCES)
variable is expanded to $(FOO_EXE_SOURCES)
, which expands to src/Foo.cs
. The dependencies don't expand properly, however; changing src/Foo.cs does not cause Foo.exe to be rebuilt.
I suspect that this can't actually be done in make, but perhaps someone has a work-alike make fragment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用“二次扩展”。像这样的事情应该可以实现您正在寻找的内容:
启用二次扩展允许在先决条件列表中使用自动变量(即本例中的
$*
),否则不会工作。You could use "secondary expansion". Something like this should accomplish what you are looking for:
Enabling secondary expansion allows the use of automatic variables (i.e.
$*
in this case) in the prerequesites list, which is something that would otherwise not work.