Makefile规则和If语句 - 如何? [英] Makefile Rules and If Statements -- How?
问题描述
我是Makefiles的新手所以请耐心等待。
I'm new to Makefiles so please bear with me.
我需要修改一个Makefile,这样一些规则会根据变量调用不同的实用程序。
I need to modify a Makefile so some rules call different utilities depending on a variable.
现在,规则如下:
ci:
[shell syntax for tool (A)]
但现在我需要ci才能有所不同语法取决于变量。所以我在文件的顶部定义了一个全局变量:
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
或
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?
谢谢!!
编辑:工具语法比一行更复杂。有时它的多行而不仅仅是toolA args等。抱歉造成混淆!
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!
推荐答案
你只是遗漏了一些括号:
You're just missing some parentheses:
ifeq ($(TOOL), toolA)
...
PS 您可以使条件稍微收紧(并删除一点冗余):
P.S. You can make the conditional a little tighter (and remove a little redundancy):
ci:
ifeq ($(TOOL), toolA)
[syntax for tool (A)]
else
[syntax for tool (B)
endif
这篇关于Makefile规则和If语句 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!