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 ]
As found on the mailing list archive,
one can use the
filterfunction.For example
filter X, A Bwill 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 (
filterwill return en empty string ifGCC_MINORdoesn’t match the arguments). Using theVAR1/VAR2example 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
VAR1is4 foo, the filter result is still4, and theifneqexpression is still true. IfVAR1is4 5, the filter result is4 5and theifneqexpression is true.One easy alternative is to just put the same operation in both the
ifeqandelse ifeqbranch, e.g. like this: