Makefile 规则和 If 语句——如何实现?
我是 Makefiles 新手,所以请耐心等待。
我需要修改 Makefile,以便某些规则根据变量调用不同的实用程序。
现在,规则如下:
ci:
[shell syntax for tool (A)]
但现在我需要 ci 根据变量具有不同的语法。所以我在文件顶部定义了一个全局变量:
TOOL = toolA
或者
TOOL = toolB
理想情况下我想要的是这样的东西,但是显然它不起作用:
ifeq ($TOOL, toolA)
ci:
[syntax for tool (A)]
else
ci:
[syntax for tool (B)
endif
有谁知道实现类似的东西的最佳方法这对吗?
谢谢!!
编辑:工具语法比一行更复杂。有时它是多行,而不仅仅是“toolA args等”。抱歉造成混乱!
I'm new to Makefiles so please bear with me.
I need to modify a Makefile so some rules call different utilities depending on a variable.
Right now, a rule looks like:
ci:
[shell syntax for tool (A)]
But now I need ci to have a different syntax depending on the variable. So I define a global variable at the top of the file:
TOOL = toolA
or
TOOL = toolB
Ideally what I'd like is something like this, but obviously it doesn't work:
ifeq ($TOOL, toolA)
ci:
[syntax for tool (A)]
else
ci:
[syntax for tool (B)
endif
Does anyone know the best way to implement something like this properly?
Thanks!!
EDIT: The tool syntax is more complicated than one line. Sometimes its multiple lines and not just "toolA args etc etc". Sorry for the confusion!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只是缺少一些括号:
PS 您可以使条件更严格一些(并删除一些冗余):
You're just missing some parentheses:
P.S. You can make the conditional a little tighter (and remove a little redundancy):
通常,您可以使用宏来完成此操作:
可以使用诸如
TOOLARGS
宏之类的东西来扩展,例如然后您可以修改 makefile,或者将宏放在命令行上
如果您想封装它,您可以使用 if 来设置参数。
Usually, you do that with a macro:
That can be extended with something like a
TOOLARGS
macro, so something likeThen you can modify the makefile, or put the macros on the command line
If you want to encapsulate it, you could use an if to set the arguments.
试试这个:
现在如果
TOOL
是toolA
它将使用参数-a1 -a2
,如果TOOL
是toolB
然后它将使用参数-b1 -b2
。Try this:
Now if
TOOL
istoolA
it will use the args-a1 -a2
, and ifTOOL
istoolB
then it will use the args-b1 -b2
.