首页 > 解决方案 > 我也可以在 elif 中使用 make 条件吗?

问题描述

我可以使用make 的条件进行简单的检查,如下所示:

var = yes
ifeq $(var) "yes"; then
    echo "yes"
else
    echo "no"
fi

但是文档对elif. 我可以这样做吗?

var = yes
ifeq $(var) "yes"; then
    echo "yes"
elifeq $(var) "no"; then
    echo "no"
else
    echo "invalid"
fi

如果没有,那有可能吗,还是我必须制作嵌套条件或使用test

标签: if-statementtestingmakefileconditional-statementscomparison

解决方案


我可以这样做吗?

不,您不能使用elifeq.

我必须制作嵌套条件还是使用 test ?

不,文档说:

复杂条件的语法如下: ... 或:

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

必要时可以有尽可能多的“其他条件指令”子句。

注意这里它说else conditional-directive-two。所以,你可以写:

var = yes
ifeq ($(var),yes)
    $(info "yes")
else ifeq ($(var),no)
    $(info "no")
else
    $(info "invalid")
endif

请注意,您的原始语法不是有效的 makefile 语法。看起来您正在尝试使用 shell 语法:makefile 不是 shell 脚本,并且不使用相同的语法。


推荐阅读