]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Document how to use literal newlines in makefile rules.
authorBruno Haible <bruno@clisp.org>
Fri, 18 Jun 2010 22:49:48 +0000 (00:49 +0200)
committerEric Blake <eblake@redhat.com>
Wed, 23 Jun 2010 02:42:47 +0000 (20:42 -0600)
* doc/autoconf.texi (Newlines in Make Rules): New section.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
doc/autoconf.texi

index 855324bb550c60d918cc8383817e853aa9e3f52e..024a83559e5b61bac49877cbe5f0236689a29415 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2010-06-22  Bruno Haible  <bruno@clisp.org>
 
+       Document how to use literal newlines in makefile rules.
+       * doc/autoconf.texi (Newlines in Make Rules): New section.
+
        Document how to write comments in makefile rules.
        * doc/autoconf.texi (Comments in Make Rules): Mention a workaround
        syntax.
index a7ccb68932b4aafa69a86ae0513ba05f566841d8..10609554ea00254021d76fec14aa149061b3e5b8 100644 (file)
@@ -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
@@ -18561,6 +18562,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
@@ -18973,6 +18975,34 @@ all:
         : "foo"
 @end example
 
+@node Newlines in Make Rules
+@section Newlines in Make Rules
+@cindex Newlines in @file{Makefile} rules
+@cindex @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
+@command{make} 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:
+
+@example
+nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"
+@end 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:
+
+@example
+nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \
+sed -e "s/\$$/\\$$@{nl@}/" < input > output
+@end example
+
 @node obj/ and Make
 @section The @file{obj/} Subdirectory and Make
 @cindex @file{obj/}, subdirectory