我可以将ifeq/else-if-eq/else语法与任何条件一起使用吗?或者我必须针对多个值只测试一个变量.(就像一个



make文档表示复杂条件的语法如下:

conditional-directive-one
text-if-one-is-true
else conditional-directive-two
text-if-two-is-true
else
text-if-one-and-two-are-false
endif

但我看到的所有例子都是";条件定向-n";正在测试与第一个条件指令中相同的$var。实际上,它就像一个用例语句,针对多个可能的值测试一个变量。像这样:

ifeq ($(option), 1)
CC=gcc
else ifeq ($(option), 2)
CC=clang
else
CC=mipsel-linux-gcc
endif

我的问题是,这是一项要求吗?或者我可以有完全不同的条件指令,比如:

ifeq ($(option), 1)
CC=gcc
else ifeq ($(myhostname), "JohnsLaptop")
CC=johnsCompiler
else
CC=
endif

那么,它真的只是一个case语句的时髦语法,还是每个"else-ifeq"都是独立的。

我知道我能做到:

ifeq ($(option), 1)
CC=gcc
else
ifeq ($(myhostname), "johnsLaptop")
CC=johnsCompiler
else
CC=mipsel-linux-gcc
endif
endif

但那太难看了。如果没有缩进,我宁愿不嵌套if/else。

我在非标准版本的make上测试了这一点,结果是每个条件指令都是独立的。多亏了madScientist的评论,这似乎证实了这是标准和gnumake的正确答案

此代码有效:

ifneq ($(findstring mbist_rtl,$@),)
RTL_OPT = mixed findSrc_targets_memwrap.ini
else ifeq ($(DFT), 1)
RTL_OPT = dft
else ifeq ($(BB), 1)
RTL_OPT = ndft
else
RTL_OPT = syn
endif

最新更新