33

I have a Makefile target, in which I have to check the value of an environment variable. But, I don't get the exact syntax of it. Tried hard, but can't find it. Any help is appreciated.

Environment variable name: TEST, its value: "TRUE"

test_target: 
    ifeq ($(TEST),"TRUE")
            echo "Do something"
    endif

I get the following error:

/bin/sh: -c: line 0: syntax error near unexpected token `"TRUE","TRUE"'
/bin/sh: -c: line 0: `ifeq ("TRUE","TRUE")'
ATP
  • 635
  • 2
  • 7
  • 9

2 Answers2

45

The ifeq() directive has to be in column 1, remove any leading whitespace ie

test_target: 
ifeq ($(TEST),"TRUE")
        echo "Do something"
endif

^ no whitespace

gwillie
  • 1,141
  • 10
  • 8
30

You must not put ifeq after TAB. Spaces are allowed. Read GNU Make document.

test_target: 
ifeq ($(TEST),"TRUE")
    echo "Do something"
endif

Also note that it compares $(TEST) with "TRUE" as is:

$ make TEST=TRUE
make: Nothing to be done for 'test_target'.

$ make TEST='"TRUE"'
echo "Do something"
Do something
yaegashi
  • 12,108
  • 1
  • 36
  • 41
  • 4
    This bit was extra helpful - Also note that it compares $(TEST) with "TRUE" as is:. Thanks – kakoma Jan 17 '19 at 13:57