makefile - 我可以在任何条件下使用 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
但是我看到的所有示例每个“conditional-directive-n”都在测试与第一个 conditional-directive-one 中相同的 $var。实际上,它就像一个 case 语句针对多个可能值测试一个变量。像这样:
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
推荐阅读
- sql - DD/MON/YY 中的年份在具有相同数据的 2 个不同表中转换为 1943 和 2043
- c# - WPF 在按 Tab 键时保持文本框的焦点
- go - `go list` 没有显示最新版本的包怎么办?
- c++ - 函数签名中未扩展的参数包
- python-3.x - Handling exception in pytest fixture and pytest.fail vs assert in general
- google-apps-script - 将 Stripe API 语法转换为 Google Apps 脚本
- javascript - useCallback:什么时候使用?有什么缺点/性能问题吗?
- python - 尝试使用python多线程excel宏时出错
- react-native - 表单使用 web 但不是 iOS,event.target 返回“未定义”
- java - Java 流 groupingBy 条件