summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2023-02-26 17:30:15 -0500
committerPaul Smith <psmith@gnu.org>2023-02-26 17:30:15 -0500
commitbf7f690202a78bc4e1588302f9ba6a10a4c273af (patch)
tree8fed826e8801230018d3deb2a0086e5422b79fed /src
parent5d1fe2b16db49f15fb8611e70221687cecb411bc (diff)
downloadmake-git-bf7f690202a78bc4e1588302f9ba6a10a4c273af.tar.gz
Directly handle $\ line endings
Previously we used the fact that this line ending expanded to "$ " which would then expand to the empty string. This has problems if you enable warnings for undefined variables, so directly implement this special (but documented) trick in the GNU Make parser. As a side-effect this also removes all previous whitespace when in GNU Make mode (not in POSIX mode) just as it would without "$". * src/misc.c (collapse_continuations): Check for "$\" and remove it. * tests/scripts/variables/flavors: Add regression tests including with previous whitespace, and escaped/unescaped "$"
Diffstat (limited to 'src')
-rw-r--r--src/misc.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/misc.c b/src/misc.c
index c362e87e..80fd63ac 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -131,7 +131,7 @@ collapse_continuations (char *line)
char *q;
q = strchr(in, '\n');
- if (q == 0)
+ if (!q)
return;
do
@@ -162,17 +162,33 @@ collapse_continuations (char *line)
if (i & 1)
{
- /* Backslash/newline handling:
- In traditional GNU Make all trailing whitespace, consecutive
- backslash/newlines, and any leading non-newline whitespace on the
- next line is reduced to a single space.
- In POSIX, each backslash/newline and is replaced by a space. */
+ unsigned int dollar;
+
+ /* Backslash/newline handling: out points to the final "\".
+ In POSIX, each backslash/newline is replaced by a space.
+ In GNU Make all trailing whitespace, consecutive backslash +
+ newlines, and any leading non-newline whitespace on the next line
+ is reduced to a single space.
+ As a special case, replace "$\" with the empty string. */
while (ISBLANK (*in))
++in;
- if (! posix_pedantic)
+
+ {
+ const char *dp = out;
+ while (dp > line && dp[-1] == '$')
+ --dp;
+ dollar = (out - dp) % 2;
+ }
+
+ if (dollar)
+ --out;
+
+ if (!posix_pedantic)
while (out > line && ISBLANK (out[-1]))
--out;
- *out++ = ' ';
+
+ if (!dollar)
+ *out++ = ' ';
}
else
{