Search code examples
makefileescapinggnu-makebackslash

How to escape a backslash in the end to mean literal backslash in Makefile?


Here is my Makefile:

SLASH = \

all:
    echo '$(SLASH)'

This is the output:

$ make all
echo ''

$

The \ in the end means line continuation in Makefile, so it ends up assigning an empty string into SLASH.

How can I assign a literal backslash into SLASH?


Solution

  • You can probably use a dummy `blank' to fool make...

    BLANK :=
    SLASH = \$(BLANK)
    
    all:
        echo '$(SLASH)'
    

    The above gives me...

    G.M> make -f how-to-escape-a-backslash-in-the-end-to-mean-literal-backslash-in-makefile.mk
    echo '\'
    \
    G.M>