Shell – Checking environment variables’ value in Makefile

makeshell

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

Best Answer

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

Related Question