help-make
[Top][All Lists]
Advanced

[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: Wed, 20 Jul 2011 16:48:59 +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 wit this cunning use of bash to remove the back-slash before the newline allows 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 "; \" trick for makefiles won't work).

Sam

--
[FSF Associate Member #2325] <http://www.fsf.org/register_form?referrer=2325>

<http://www.openrightsgroup.org/>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]