1 # $Id: escape.mk,v 1.1.1.2 2014/11/06 01:40:37 sjg Exp $
3 # Test backslash escaping.
5 # Extracts from the POSIX 2008 specification
6 # <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html>:
8 # Comments start with a <number-sign> ( '#' ) and continue until an
9 # unescaped <newline> is reached.
11 # When an escaped <newline> (one preceded by a <backslash>) is found
12 # anywhere in the makefile except in a command line, an include
13 # line, or a line immediately preceding an include line, it shall
14 # be replaced, along with any leading white space on the following
15 # line, with a single <space>.
17 # When an escaped <newline> is found in a command line in a
18 # makefile, the command line shall contain the <backslash>, the
19 # <newline>, and the next line, except that the first character of
20 # the next line shall not be included if it is a <tab>.
22 # When an escaped <newline> is found in an include line or in a
23 # line immediately preceding an include line, the behavior is
26 # Notice that the behaviour of <backslash><backslash> or
27 # <backslash><anything other than newline> is not mentioned. I think
28 # this implies that <backslash> should be taken literally everywhere
29 # except before <newline>.
31 # Our practice, despite what POSIX might say, is that "\#"
32 # in a variable assignment stores "#" as part of the value.
33 # The "\" is not taken literally, and the "#" does not begin a comment.
35 # Also, our practice is that an even number of backslashes before a
36 # newline in a variable assignment simply stores the backslashes as part
37 # of the value, and treats the newline as though it was not escaped.
38 # Similarly, ann even number of backslashes before a newline in a
39 # command simply uses the backslashes as part of the command test, but
40 # does not escape the newline. This is compatible with GNU make.
43 # We will add dependencies like "all: yet-another-test" later.
45 # Some variables to be expanded in tests
50 # Backslash at end of line in a comment\
51 should continue the comment. \
52 # This is also tested in comment.mk.
54 __printvars
: .USE .MADE
56 ${.ALLSRC
:@v@ printf
"%s=:%s:\n" ${v
:Q
} ${${v}:Q
}; @
}
58 # Embedded backslash in variable should be taken literally.
65 VAR1BSc
= 111\
# backslash escapes comment char, so this is part of the value
66 VAR1BSsc
= 111\
# This is a comment. Value ends with <backslash><space>
69 var-1bs
: .PHONY __printvars VAR1BS VAR1BSa VAR1BSA VAR1BSda VAR1BSdA \
72 # Double backslash in variable should be taken as two literal backslashes.
79 VAR2BSc
= 222\\# backslash does not escape comment char, so this is a comment
80 VAR2BSsc
= 222\\ # This is a comment. Value ends with <backslash><backslash>
83 var-2bs
: .PHONY __printvars VAR2BS VAR2BSa VAR2BSA VAR2BSda VAR2BSdA \
86 # Backslash-newline in a variable setting is replaced by a single space.
99 # this should be processed as a comment
101 # this should be processed as a comment
105 var-1bsnl
: .PHONY __printvars \
106 VAR1BSNL VAR1BSNLa VAR1BSNLA VAR1BSNLda VAR1BSNLdA \
109 # Double-backslash-newline in a variable setting.
110 # Both backslashes should be taken literally, and the newline is NOT escaped.
112 # The second lines below each end with '=' so that they will not
113 # generate syntax errors regardless of whether or not they are
114 # treated as part of the value.
127 # this should be processed as a comment
129 # this should be processed as a comment
132 var-2bsnl
: .PHONY __printvars \
133 VAR2BSNL VAR2BSNLa VAR2BSNLA VAR2BSNLda VAR2BSNLdA \
136 # Triple-backslash-newline in a variable setting.
137 # First two should be taken literally, and last should escape the newline.
139 # The second lines below each end with '=' so that they will not
140 # generate syntax errors regardless of whether or not they are
141 # treated as part of the value.
154 # this should be processed as a comment
156 # this should be processed as a comment
159 var-3bsnl
: .PHONY __printvars \
160 VAR3BSNL VAR3BSNLa VAR3BSNLA VAR3BSNLda VAR3BSNLdA \
163 # Backslash-newline in a variable setting, plus any amount of white space
164 # on the next line, is replaced by a single space.
166 VAR1BSNL00
= first line\
168 # above line is entirely empty, and this is a comment
169 VAR1BSNL0
= first line\
170 no space on second line
171 VAR1BSNLs
= first line\
172 one space on second line
173 VAR1BSNLss
= first line\
174 two spaces on second line
175 VAR1BSNLt
= first line\
176 one tab on second line
177 VAR1BSNLtt
= first line\
178 two tabs on second line
179 VAR1BSNLxx
= first line\
180 many spaces and tabs
[ ] on second line
183 var-1bsnl-space
: .PHONY __printvars \
184 VAR1BSNL00 VAR1BSNL0 VAR1BSNLs VAR1BSNLss VAR1BSNLt VAR1BSNLtt \
187 # Backslash-newline in a command is retained.
189 # The "#" in "# second line without space" makes it a comment instead
190 # of a syntax error if the preceding line is parsed incorretly.
191 # The ":" in "third line':" makes it look like the start of a
192 # target instead of a syntax error if the first line is parsed incorrectly.
198 #second line without space\
201 second line spaces should be retained':
203 second line tab should be elided':
205 only one tab should be elided, second tab remains'
207 # When backslash-newline appears at the end of a command script,
208 # both the backslash and the newline should be passed to the shell.
209 # The shell should elide the backslash-newline.
214 echo
:'command ending with backslash-newline'; \
216 # above line must be blank
218 # Double-backslash-newline in a command.
219 # Both backslashes are retained, but the newline is not escaped.
220 # XXX: This may differ from POSIX, but matches gmake.
222 # When make passes two backslashes to the shell, the shell will pass one
223 # backslash to the echo commant.
229 # this should be a comment
233 # Triple-backslash-newline in a command is retained.
239 #second line without space\\\
242 second line spaces should be retained':
244 second line tab should be elided':
246 only one tab should be elided, second tab remains'