44

I would like to check multiple conditions in an if loop of GNU make file. Here's an example:

ifeq ($(TEST_FLAG),TRUE && ($(DEBUG_FLAG),FALSE))
true statement 
else 
false statement
endif

What's the right way to do it?

pevik
  • 4,523
  • 3
  • 33
  • 44
Arun Kumar
  • 441
  • 1
  • 4
  • 6

2 Answers2

40

Although Hasturkun's solution will work, I think the idiomatic way to write this is:

ifeq ($(TEST_FLAG),TRUE)
ifeq ($(DEBUG_FLAG),FALSE)
# Stuff
endif
endif
Matthew Simoneau
  • 6,199
  • 6
  • 35
  • 46
Jack Kelly
  • 18,264
  • 2
  • 56
  • 81
36

You can use ifeq with a concatenation of your values, eg.

ifeq ($(TEST_FLAG)$(DEBUG_FLAG),TRUEFALSE)
   do something
endif

It's also possible to use the Conditional functions, which are more likely to be useful in a loop (as ifeq will probably not do what you expect in a loop, it will be tested exactly once).

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
  • 1
    I think the leading space before `TRUEFALSE` _breaks_ the check and it never will work because `ifeq` is very sensitive regarding a leading space. Can you check it and if I am right edit your answer? – Peter VARGA Jun 22 '17 at 19:11
  • 1
    This would give false positives: `make TEST_FLAG=TR DEBUG_FLAG=UEFALSE`, `make DEBUG_FLAG=TRUEFALSE` – xtofl Jun 04 '19 at 11:57
  • @xtofl: It will, but it's assumed the values are either `TRUE` or `FALSE` and not some mix of the two. – Hasturkun Jun 04 '19 at 14:50