34

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")'

2 Answers 2

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

1
  • 1
    when i do this I get "missing seperator" because of missing intendation Commented Jun 2, 2020 at 14:15
31

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
1
  • 4
    This bit was extra helpful - Also note that it compares $(TEST) with "TRUE" as is:. Thanks
    – kakoma
    Commented Jan 17, 2019 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .