]> git.ipfire.org Git - thirdparty/make.git/commitdiff
* doc/make.texi: [SV 54116] Document whitespace removal trick.
authorPaul Smith <psmith@gnu.org>
Sun, 19 May 2019 17:02:06 +0000 (13:02 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 19 May 2019 23:25:50 +0000 (19:25 -0400)
Discovered and explained by Michael Henry <gnu@drmikehenry.com>
* tests/scripts/variables/flavors: Add a test to preserve the behavior.

doc/make.texi
tests/scripts/variables/flavors

index 441d7fdf00fe9f360f1674bc3a74ec74fdae3183..2d005fe680448716622303e780e51acf04c929cc 100644 (file)
@@ -1113,6 +1113,36 @@ handling is modified slightly to conform to POSIX.2: first, whitespace
 preceding a backslash is not removed and second, consecutive
 backslash/newlines are not condensed.
 
+@subsubheading Splitting Without Adding Whitespace
+@cindex whitespace, avoiding on line split
+@cindex removing whitespace from split lines
+
+If you need to split a line but do @emph{not} want any whitespace
+added, you can utilize a subtle trick: replace your backslash/newline
+pairs with the three characters dollar sign/backslash/newline:
+
+@example
+var := one$\
+       word
+@end example
+
+After @code{make} removes the backslash/newline and condenses the
+following line into a single space, this is equivalent to:
+
+@example
+var := one$ word
+@end example
+
+Then @code{make} will perform variable expansion.  The variable
+reference @samp{$ } refers to a variable with the one-character name
+`` '' (space) which does not exist, and so expands to the empty
+string, giving a final assignment which is the equivalent of:
+
+@example
+var := oneword
+@end example
+
+
 @node Makefile Names, Include, Makefile Contents, Makefiles
 @section What Name to Give Your Makefile
 @cindex makefile name
index ed060dcb70c9274539f029a0049623767334ea8a..831e5d81004de19dab3dc4c065f75337ec3a7423 100644 (file)
@@ -112,4 +112,45 @@ all: ; @: $(info recur=/$(recur)/ simple=/$(simple)/ recure=/$(recur_empty)/ sim
 !,
               '', "recur=/foo/ simple=/bar/ recure=/foo/ simplee=/bar/ erecur=// esimple=//\n");
 
+# TEST 9: Line continuation
+run_make_test(q!
+recur = $\
+  one$\
+  two$\
+  three
+simple := $\
+  four$\
+  five$\
+  six
+
+all: d$\
+     e$\
+     p; @:
+
+.PHONY: dep
+dep: ; @: $(info recur=/$(recur)/ simple=/$(simple)/)
+!,
+             '', "recur=/onetwothree/ simple=/fourfivesix/\n");
+
+# TEST 9: Line continuation
+run_make_test(q!
+.POSIX:
+recur = $\
+  one$\
+  two$\
+  three
+simple := $\
+  four$\
+  five$\
+  six
+
+all: d$\
+     e$\
+     p; @:
+
+.PHONY: dep
+dep: ; @: $(info recur=/$(recur)/ simple=/$(simple)/)
+!,
+             '', "recur=/onetwothree/ simple=/fourfivesix/\n");
+
 1;