Here docs in makefile
Brian Fitzgerald
fitz at mml0.meche.rpi.edu
Fri May 10 04:15:30 AEST 1991
afsipmh at cidsv01.cid.aes.doe.CA writes:
>How can I use a here document within a makefile?
>Is this possible?
I posted the same question in January.
In <}7W^DZ_ at rpi.edu>, you write in comp.unix.shell:
>This shell script with an ed script splits my file into two new files:
>
>ed foo <<E_O_F
>1,/^ *References$/-1w foo.body
>/^ *References$/+1,$w foo.ref
>q
>E_O_F
>
>This makefile does the same thing for me:
>
>EDSCRIPT= 1,/^ *References$$/-1w $(DOC).body@\
>/^ *References$$/+1,$$w $(DOC).ref@\
>q
>
>ed: $(DOC)
> echo '$(EDSCRIPT)' | tr @ '\012' | ed $(DOC)
>
>My question: Can a makefile rule contain a "here" document like my
>first example? Please post tested solutions that use the standard
>"ed", "sh", and "make". Thanks!
By the way, in my original posting, I meant a "here" document embedded
within the Makefile itself.
I got a nice reply from a certain net guru (who spells his name with
four rows of the keyboard!) who said:
--
There isn't a way that is portable across all versions of make, no.
The problem is that some makes take the backslash-newline and delete
both. This is why /bin/sh scripts in Makefiles have all those semicolons,
as in:
@for I in $(LIST) ; do \
echo Creating $$I... ; \
sed -e s/foo/bar/ <template >$$I ; \
done
That way when the lines are merged the ; will terminate the commands
in the right place.
Other versions of make just delete the \, however, and keep the newline.
SysV "augmented" make was the first one to do this, I believe.
--
Brian
More information about the Comp.unix.questions
mailing list