aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/make.c14
-rwxr-xr-xtestsuite/make.tests9
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
463testing "make backslash-escaped hash isn't a comment" \
464 "make -f -" \
465 ": hash # hash\n" "" '
466hash = \#
467target:
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
463testing "make hash in command line isn't a comment" \ 472testing "make hash in command line isn't a comment" \
464 "make -f -" \ 473 "make -f -" \