我想有多个if条件并想组合。
ifeq ($(TAG1), on)
LD_FLAGS += -ltestlibrary
endif
ifeq ($(TAG2), on)
LD_FLAGS += -ltestlibrary
endif
我想做一些类似的事情:
ifeq ($(TAG1) || $(TAG2), on)
LD_FLAGS += -ltestlibrary
endif
我该怎么做? SO Makefile ifeq 逻辑或 或 How to Use of Multiple condition in 'ifeq' statements 中的答案给出了其他做法。
可以在 MakeFile 中使用 OR 运算符的过滤器。 对于您的情况,条件如下:
ifneq ($(filter on,$(TAG1) $(TAG2)),)
LD_FLAGS += -ltestlibrary
endif
请参阅此链接了解用于转换文本的 GNU make 函数
请参阅我的回答,这里
如果你想检查 x=4 或 x=6
ifeq ($(x),$(filter $(x),4 6))
x is either 4 or 6. do whatever you like with it
else
x is neither 4 nor 6
endif
请注意,
ifeq ($(x),$(filter $(x),4 6))
将捕获 x 根本未定义的情况。
如果你想抓住
x==4 || x==6
,这会起作用:
ifneq ($(filter $(GCC_MINOR),4 6),)
# do stuff
endif
使用shell,可以构造任何复杂的条件。
例如:
target:
ifneq "" "$(shell [ ! -e aaa.txt ] && [ -e bbb.txt ] && echo 123)"
@echo aaa.txt not exist and bbb.txt exist
endif
这不应该是“ifeq”而不是“ifneq”吗?像下面这样吗?
ifeq ($(过滤器 $(GCC_MINOR),4 6),)
结束