7

I want to have multiple if condition and want to combine.

ifeq ($(TAG1), on)
LD_FLAGS += -ltestlibrary
endif
ifeq ($(TAG2), on)
LD_FLAGS += -ltestlibrary
endif

I want to do some thing like:

ifeq ($(TAG1) || $(TAG2), on)
LD_FLAGS += -ltestlibrary
endif

How can I do it? The answers in SO Makefile ifeq logical or or How to Use of Multiple condition in 'ifeq' statement gives otherway of doing.

1
  • The second link you provided seems to be specific to an AND condition. But the first example you linked, using a filter, should work for you. Did you try it?
    – lurker
    Sep 1, 2015 at 13:06

4 Answers 4

3

One can use filter for OR operator use in MakeFile. For your case the condition will be like: ifneq ($(filter on,$(TAG1) $(TAG2)),) LD_FLAGS += -ltestlibrary endif Please refer this link for GNU make functions for transforming text

2

You cant use a logical OR operator, there simply isnt one, hence having to use another way of doing it - like those suggested in the posts you've already found. The way I prefer to do it is with filter, as suggested in the first link you gave.

In your case it would look like this

ifneq (,$(filter on,$(TAG1)$(TAG2)))
LD_FLAGS += -ltestlibrary
endif    

This concatenates both your tags, filters them for 'on', and compares them to an empty string, so if either tag is on then the comparison would be false and the LD_FLAGS += -ltestlibrary code would run.

0
0

see my answer, here

if you want to check if x=4 or 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
0

Note that ifeq ($(x),$(filter $(x),4 6)) will catch the case where x is not defined at all.

If you want to catch x==4 || x==6 this will do trick:

ifneq ($(filter $(GCC_MINOR),4 6),)
   # do stuff
endif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.