Reputation:
What are the rules in GNU make regarding quote characters? I had thought that in most cases they would simply be part of the text in the make file and usually have no special meaning to make. The following simple make file demonstrates that double quote characters appearing around an argument to $(if ...) are being stripped rather than passed out of the $(if) call. This seems wrong, and oddly the unescaped quotes do pass through in a more complex make file I've been using.
include gmsl
VAR1 ?= var1_value
VAR2 ?= var2_value1 var2_value2
failquote = $(if $(call ne,$(words $(1)),1),"$(1)",$(1))
passquote = $(if $(call ne,$(words $(1)),1),\"$(1)\",$(1))
TESTFAILQUOTE = $(call failquote,$(VAR2))
TESTPASSQUOTE = $(call passquote,$(VAR2))
quotetest :
@echo "--->Executing recipe for quotetest"
@echo VAR2 is $(VAR2)
@echo TESTFAILQUOTE = $(TESTFAILQUOTE)
@echo TESTPASSQUOTE = $(TESTPASSQUOTE)
The output is thus:
bash-4.1$ make -f test_quote.mk quotetest
--->Executing recipe for quotetest
TESTFAILQUOTE = var2_value1 var2_value2
TESTPASSQUOTE = "var2_value1 var2_value2"
Note: you'll need the Gnu Make Standard library for this make file to work, for the $(call ne,...). Find it here: http://gmsl.sourceforge.net/
Upvotes: 0
Views: 1014
Reputation: 100856
You're misunderstanding. Make never strips quotes. However, make invokes the shell and the shell will strip quotes.
If you remove the @
tokens at the beginning of your echo
lines you'll see how make is invoking the shell; you'll see:
echo TESTFAILQUOTE = "var2_value1 var2_value2"
var2_value1 var2_value2
echo TESTPASSQUOTE = \"var2_value1 var2_value2\"
"var2_value1 var2_value2"
If you run those same echo commands at your shell prompt you'll get the same results, showing that none of this is related to make.
Upvotes: 2