[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Make trick for multi-line recipes:
From: |
Sam Liddicott |
Subject: |
Make trick for multi-line recipes: |
Date: |
Thu, 21 Jul 2011 07:52:00 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11 |
I came up with this cunning use of bash to remove the back-slash before
the newline, allowing true multi-line shell fragments as make recipes.
SHELL:=bash -c 'exec $(SHELL) "$${@//\\$$'\''\012'\''/$$'\''\012'\''}"' --
test:
if test 1 = 1 \
then echo yes \
else echo no \
fi
Or for those who prefer:
NEW_SHELL:=bash -c 'exec $(SHELL)
"$${@//\\$$'\''\012'\''/$$'\''\012'\''}"' --
test: SHELL=$(NEW_SHELL)
if test 1 = 1 \
then echo yes \
else echo no \
fi
with associated warnings about SHELL being set for dependencies (if any).
Why? Because my literate-programming tools which automatically quote
characters based on file type make it all too easy to include a
shell-script fragment in a makefile (with an $ automatically quoted to
$$) and I wanted a way to allow multi-line shell script - which might
only be multi-line because it includes a multi-line sed fragment (so the
old "; \" line continuation trick for makefiles won't work).
This change makes it hard to have a single shell line represented as 2
makefile lines (i.e. wrap a single statement in the makefile) but this
was difficult to do right anyway as the backslash and newline were both
passed through, and it depended on knowledge of the shell - and
generally to make sure you broke the line inside a shell double-quote.
Compared to that secret knowledge, I think this little hack is much more
straightforward.
Sam
--
[FSF Associate Member #2325]
<http://www.fsf.org/register_form?referrer=2325>
<http://www.openrightsgroup.org/>
- Make trick for multi-line recipes:,
Sam Liddicott <=