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
Run Code Online (Sandbox Code Playgroud)
但我见过的所有示例中的每个“条件指令 n”都在测试与第一个条件指令中相同的 $var 。实际上,它就像一个 case 语句,针对多个可能值测试一个变量。像这样:
ifeq ($(option), 1)
CC=gcc
else ifeq ($(option), 2)
CC=clang
else
CC=mipsel-linux-gcc
endif
Run Code Online (Sandbox Code Playgroud)
我的问题是,这是一个要求吗?或者我可以有完全不同的条件指令,如下所示:
ifeq ($(option), 1)
CC=gcc
else ifeq ($(myhostname), "JohnsLaptop")
CC=johnsCompiler
else
CC=
endif
Run Code Online (Sandbox Code Playgroud)
那么它真的只是一个 case 语句的时髦语法,还是每个“else ifeq”都是独立的。
我知道我可以这样做:
ifeq ($(option), 1)
CC=gcc
else
ifeq ($(myhostname), "johnsLaptop")
CC=johnsCompiler
else
CC=mipsel-linux-gcc
endif
endif
Run Code Online (Sandbox Code Playgroud)
但那很丑。如果不需要的话,我宁愿不嵌套没有缩进的 if/else。