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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With