If you export the variable to the shell and reference it as a shell variable, rather than a make variable, you will have better luck:
define VAR1
/dev d 755 - - - - -
endef
define VAR2
/test d 777 - - - - -
/test2 d 777 - - - - -
endef
define VARS
$(VAR1)
$(VAR2)
endef
export VARS
all:
echo "$$VARS" > test
Note the following adjustments to your makefile:
- I used
define
to createVARS
, rather than a series of+=
assignments, which makes it easier to get a newline between the value ofVAR1
andVAR2
. - I added
export VARS
to your makefile, to get the variable pushed into the environment for the shell invocation. - I used
$$VARS
rather than$(VARS)
to dereference it — that leaves the expansion to the shell, rather than to make, which will avoid the “Unterminated quoted string” error.