diff options
author | Ron Yorston <rmy@pobox.com> | 2024-03-11 09:12:47 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-03-11 09:20:47 +0000 |
commit | 1eee84b800408e53e659ff303eaa08ee09d67c3b (patch) | |
tree | 052da978f08edf8915e10fafe9d9813a9b57d6f1 | |
parent | 912d65cba97db3d27a747decb1c1635aece8bb90 (diff) | |
download | busybox-w32-1eee84b800408e53e659ff303eaa08ee09d67c3b.tar.gz busybox-w32-1eee84b800408e53e659ff303eaa08ee09d67c3b.tar.bz2 busybox-w32-1eee84b800408e53e659ff303eaa08ee09d67c3b.zip |
make: allow '#' to be escaped with a backslash
POSIX doesn't allow the '#' comment marker to be escaped, though
some implementations do.
As a non-POSIX extension allow '#' to be escaped with a preceding
backslash.
It isn't necessary to escape '#' in macro expansions or command
lines: these cases are covered by an existing extension. Commit
0aceca867 (make: comments in macro expansions and command lines)
Adds 16-32 bytes.
(pdpmake GitHub issue 38)
-rw-r--r-- | miscutils/make.c | 14 | ||||
-rwxr-xr-x | testsuite/make.tests | 9 |
2 files changed, 20 insertions, 3 deletions
diff --git a/miscutils/make.c b/miscutils/make.c index 841daa93e..87f17aad7 100644 --- a/miscutils/make.c +++ b/miscutils/make.c | |||
@@ -1373,9 +1373,17 @@ process_line(char *s) | |||
1373 | 1373 | ||
1374 | // Strip comment | 1374 | // Strip comment |
1375 | // don't treat '#' in macro expansion as a comment | 1375 | // don't treat '#' in macro expansion as a comment |
1376 | if (!posix) | 1376 | // nor '#' outside macro expansion preceded by backslash |
1377 | t = find_char(s, '#'); | 1377 | if (!posix) { |
1378 | else | 1378 | char *u = s; |
1379 | while ((t = find_char(u, '#')) && t > u && t[-1] == '\\') { | ||
1380 | for (u = t; *u; ++u) { | ||
1381 | u[-1] = u[0]; | ||
1382 | } | ||
1383 | *u = '\0'; | ||
1384 | u = t; | ||
1385 | } | ||
1386 | } else | ||
1379 | t = strchr(s, '#'); | 1387 | t = strchr(s, '#'); |
1380 | if (t) | 1388 | if (t) |
1381 | *t = '\0'; | 1389 | *t = '\0'; |
diff --git a/testsuite/make.tests b/testsuite/make.tests index 745a840f3..1fc95a8d2 100755 --- a/testsuite/make.tests +++ b/testsuite/make.tests | |||
@@ -459,6 +459,15 @@ target: | |||
459 | : hash $(hash) hash | 459 | : hash $(hash) hash |
460 | ' | 460 | ' |
461 | 461 | ||
462 | # A '#' character can be escaped with a backslash | ||
463 | testing "make backslash-escaped hash isn't a comment" \ | ||
464 | "make -f -" \ | ||
465 | ": hash # hash\n" "" ' | ||
466 | hash = \# | ||
467 | target: | ||
468 | : hash $(hash) hash | ||
469 | ' | ||
470 | |||
462 | # A '#' character in a command line doesn't start a comment | 471 | # A '#' character in a command line doesn't start a comment |
463 | testing "make hash in command line isn't a comment" \ | 472 | testing "make hash in command line isn't a comment" \ |
464 | "make -f -" \ | 473 | "make -f -" \ |