17

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

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

11

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.