Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile OR condition

Tags:

linux

makefile

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.

like image 326
Ruchi Gupta Avatar asked Sep 01 '15 12:09

Ruchi Gupta


2 Answers

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

like image 131
Prashant Shubham Avatar answered Oct 17 '22 09:10

Prashant Shubham


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.

like image 31
timdykes Avatar answered Oct 17 '22 09:10

timdykes