From b173990ea5f1351882cc286d5d6dc479ca9ac927 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 19 Jun 2010 00:49:48 +0200 Subject: [PATCH 2/2] Document how to use literal newlines in makefile rules. --- ChangeLog | 5 +++++ doc/autoconf.texi | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2dbf4ca..471d70d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-06-21 Bruno Haible + + Document how to use literal newlines in makefile rules. + * doc/autoconf.texi (Newlines in Make Rules): New section. + 2010-06-18 Bruno Haible Document how to write comments in makefile rules. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 90457f1..6f51277 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -529,6 +529,7 @@ Portable Make Programming * The Make Macro SHELL:: @code{$(SHELL)} portability issues * Parallel Make:: Parallel @command{make} quirks * Comments in Make Rules:: Other problems with Make comments +* Newlines in Make Rules:: Using literal newlines in rules * obj/ and Make:: Don't name a subdirectory @file{obj} * make -k Status:: Exit status of @samp{make -k} * VPATH and Make:: @code{VPATH} woes @@ -18546,6 +18547,7 @@ itself. * The Make Macro SHELL:: @code{$(SHELL)} portability issues * Parallel Make:: Parallel @command{make} quirks * Comments in Make Rules:: Other problems with Make comments +* Newlines in Make Rules:: Using literal newlines in rules * obj/ and Make:: Don't name a subdirectory @file{obj} * make -k Status:: Exit status of @samp{make -k} * VPATH and Make:: @code{VPATH} woes @@ -18945,6 +18947,34 @@ all: : "foo" @end example address@hidden Newlines in Make Rules address@hidden Newlines in Make Rules address@hidden Newlines in @file{Makefile} rules address@hidden @file{Makefile} rules and newlines + +In shell scripts, newlines can be used inside string literals. But in +the shell statements of @file{Makefile} rules, this is not possible: +A newline not preceded by a backslash is a separator between shell +statements. Whereas a newline that is preceded by a backslash becomes +part of the shell statement according to POSIX, but gets replaced, +together with the backslash that precedes it, by a space in GNU address@hidden 3.80 and older. So, how can a newline be used in a string +literal? + +The trick is to set up a shell variable that contains a newline: + address@hidden +nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit" address@hidden example + +For example, in order to create a multiline @samp{sed} expression that +inserts a blank line after every line of a file, this code can be used: + address@hidden +nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \ +sed -e "s/\$$/address@hidden@}/" < input > output address@hidden example + @node obj/ and Make @section The @file{obj/} Subdirectory and Make @cindex @file{obj/}, subdirectory -- 1.6.3.2