Search code examples
if-statementmakefileconditional-statementsstrip

makefile conditional - strip whitespace from variable


Following the syntax given in the documentation here.

# Makefile
S='    '

spam:
ifneq ($(strip $(S)),)
    @echo nonempty
else
    @echo empty
endif

But when executing make spam, it still goes into the nonempty block here, expected the empty block.

What am I doing wrong?


Solution

  • make variable assignments aren't like shell assignments. You don't need the quotes.

    You are setting the value of your variable to ' ' and not like you are expecting.

    So strip then converts it to ' ' which is not equal to the empty string.

    Remove the quotes on the assignment line.