How do you perform a logical OR using make's ifeq
operator?
e.g., I have (simplified):
ifeq ($(GCC_MINOR), 4)
CFLAGS += -fno-strict-overflow
endif
ifeq ($(GCC_MINOR), 5)
CFLAGS += -fno-strict-overflow
endif
but would like to consolidate these lines.
(yes, yes, autotools, configure, etc etc; too heavy-handed for the current situation, would like to keep everything within the Makefile here)
[logical opposite of this question: How to Use of Multiple condition in 'ifeq' statement ]
Best Answer
As found on the mailing list archive,
one can use the
filter
function.For example
filter X, A B
will return those of A,B that are equal to X. Note, while this is not relevant in the above example, this is a XOR operation. I.e. if you instead have something like:And then do e.g.
make VAR1=4 VAR2=4
, the filter will return4 4
, which is not equal to4
.A variation that performs an OR operation instead is:
where a negative comparison against an empty string is used instead (
filter
will return en empty string ifGCC_MINOR
doesn't match the arguments). Using theVAR1
/VAR2
example it would look like this:The downside to those methods is that you have to be sure that these arguments will always be single words. For example, if
VAR1
is4 foo
, the filter result is still4
, and theifneq
expression is still true. IfVAR1
is4 5
, the filter result is4 5
and theifneq
expression is true.One easy alternative is to just put the same operation in both the
ifeq
andelse ifeq
branch, e.g. like this: