diff --git a/doc/make.texi b/doc/make.texi index 441d7fdf..2d005fe6 100644 --- a/doc/make.texi +++ b/doc/make.texi @@ -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 diff --git a/tests/scripts/variables/flavors b/tests/scripts/variables/flavors index ed060dcb..831e5d81 100644 --- a/tests/scripts/variables/flavors +++ b/tests/scripts/variables/flavors @@ -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;