Conditional OR in makefile
19,933
Solution 1
I do like this:
ifneq "$(or $(LINUX_TARGET),$(OSX_TARGET))" ""
endif
Similar to the $(strip approach, but using the more intuitive $(or keyword
Solution 2
VERBOSE := $(or $(VERBOSE),$(V))
...then...
ifeq ($(VERBOSE),1)
#Conditional stuff
endif
Solution 3
I like Neil Butterworth's approach, but if you really want to do it in the style you describe, this will give you OR:
ifneq "$(strip $(VERBOSE) $(V))" ""
[be verbose]
endif
Author by
Gui13
Updated on June 04, 2022Comments
-
Gui13 about 2 years
I'd like to enable a verbose compilation in my makefile, but I can't figure out how to make a conditional
OR
.Let me explain: I want to be able to specify a verbose compilation either by setting
V=1
orVERBOSE=1
. I want to keepVERBOSE=1
available because we have some scripts that make use of it (and use other makefiles only aware ofVERBOSE
)So the result must be that these two commands are the same:
make all VERBOSE=1 # pain to write make all V=1
Now, my makefile looks like this today:
ifdef VERBOSE [issue compilation commands with verbose mode] endif
What I'd like to achieve is close to the preprocessor in C:
if defined(VERBOSE) || defined(V) [issue compilation commands with verbose mode] endif
Do you know how to do that?
-
Gui13 over 11 yearsNiiiiice, this one's way clearer. I didn't know about the
or
. -
villapx about 8 yearsIt does "offer a lot of flexibility"--except that it limits you to using the specific shell that you code it to (in your case, BASH)
-
Gui13 over 7 yearsI switched to accept your answer, because it is semantically exactly solving my issue.