Note: This is not a duplicate of Is it possible to create a multi-line string variable in a Makefile and other such questions. This question requests POSIX compliant solutions that do not depend Bash-only or GNU Make-only features. The other question on Stack Overflow does not have this requirement.
Take this shell script using the BSD sed
on macOS High Sierra:
printf 'foo\nbaz\n' | sed '/foo/a\
bar
'
The output is:
foo
bar
baz
How can I put the same thing in a Makefile
? Here is what I tried but it does not seem to work:
all:
printf 'foo\nbaz\n' | sed '/foo/a\\
bar\
'
This leads to errors:
$ make
printf 'foo\nbaz\n' | sed '/foo/a\\
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [all] Error 2
How can I write the above sed
invocation correctly in a Makefile such that when make
executes the all
target it feeds the trailing slash and the newlines correctly to the shell?
Note: I would like the Makefile
to be POSIX compliant and use only features from http://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html.