Makefile such that the default step is to print out a help document for the other options. It would be great if I could add an
EOF section instead of multiple
echos. Is it possible to use
EOF in a
Makefile like you can do it a bash script?
If you're using GNU make, you can use the
define syntax for multi-line variables:
define message = You can also include make macros like $$@ = $@ in a multi-line variable endef help:; @ $(info $(message)) :
By playing with the
value function and the
export directive, you can also include a whole script in your Makefile, which will allow you to use a multi-line command without turning on
define _script echo SHELL is $SHELL, PID is $$ cat <<'EOF' literally $SHELL and $$ EOF endef export script = $(value _script) run:; @ eval "$$script"
SHELL is /bin/sh, PID is 12434 literally $SHELL and $$
The simple answer is "not by default". But you can configure GNU make to allow it using
Normally each line from a recipe is executed in its own shell. To make matters worse, there is a way to make multi-line commands in make, using a
\ at the end of the line to continue it. Unfortunately, this
\ is also passed to the shell which is less of a problem for other commands, but for heredoc it really messes up the syntax.
However if you enable
.ONESHELL:, this logic changes and commands are executed in a single shell allowing it to work:
.ONESHELL: all: cat << EOF aaa bbb EOF
Be aware that this will have other implications to the way Make functions. Most notably Make may not notice if one build line fails if it is followed by others. Normally the result of each line would be checked but with
.ONESHELL: make can only see the result of all lines.