diff options
| author | Ron Yorston <rmy@pobox.com> | 2022-11-01 14:18:00 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2022-11-01 14:24:31 +0000 |
| commit | 0aceca8673c1d9a8bc34faa460389768efa08eb7 (patch) | |
| tree | a484dc09b97a4137de053dc3243029880d7600e5 | |
| parent | 93cb545c1a380724b7cf4528eabe6da3ea8ba964 (diff) | |
| download | busybox-w32-0aceca8673c1d9a8bc34faa460389768efa08eb7.tar.gz busybox-w32-0aceca8673c1d9a8bc34faa460389768efa08eb7.tar.bz2 busybox-w32-0aceca8673c1d9a8bc34faa460389768efa08eb7.zip | |
make: comments in macro expansions and command lines
The POSIX specification says:
There are three kinds of comments: blank lines, empty lines, and
a <number-sign> ('#') and all following characters up to the first
unescaped <newline> character.
Most implementations don't treat '#' in a macro expansion or a command
line as the start of a comment. POSIX doesn't mention either of these
exceptions.
Permit the exceptions as a non-POSIX extension.
| -rw-r--r-- | miscutils/make.c | 19 | ||||
| -rwxr-xr-x | testsuite/make.tests | 18 |
2 files changed, 34 insertions, 3 deletions
diff --git a/miscutils/make.c b/miscutils/make.c index 111ab2914..daad75f5c 100644 --- a/miscutils/make.c +++ b/miscutils/make.c | |||
| @@ -1120,7 +1120,11 @@ process_line(char *s) | |||
| 1120 | r = s; | 1120 | r = s; |
| 1121 | 1121 | ||
| 1122 | // Strip comment | 1122 | // Strip comment |
| 1123 | t = strchr(s, '#'); | 1123 | // don't treat '#' in macro expansion as a comment |
| 1124 | if (!posix) | ||
| 1125 | t = find_char(s, '#'); | ||
| 1126 | else | ||
| 1127 | t = strchr(s, '#'); | ||
| 1124 | if (t) | 1128 | if (t) |
| 1125 | *t = '\0'; | 1129 | *t = '\0'; |
| 1126 | 1130 | ||
| @@ -1401,9 +1405,18 @@ static char * | |||
| 1401 | process_command(char *s) | 1405 | process_command(char *s) |
| 1402 | { | 1406 | { |
| 1403 | char *t, *u; | 1407 | char *t, *u; |
| 1404 | int len = strlen(s) + 1; | 1408 | int len; |
| 1405 | char *outside = xzalloc(len); | 1409 | char *outside; |
| 1410 | |||
| 1411 | if (posix) { | ||
| 1412 | // POSIX strips comments from command lines | ||
| 1413 | t = strchr(s, '#'); | ||
| 1414 | if (t) | ||
| 1415 | *t = '\0'; | ||
| 1416 | } | ||
| 1406 | 1417 | ||
| 1418 | len = strlen(s) + 1; | ||
| 1419 | outside = xzalloc(len); | ||
| 1407 | for (t = skip_macro(s); *t; t = skip_macro(t + 1)) { | 1420 | for (t = skip_macro(s); *t; t = skip_macro(t + 1)) { |
| 1408 | outside[t - s] = 1; | 1421 | outside[t - s] = 1; |
| 1409 | } | 1422 | } |
diff --git a/testsuite/make.tests b/testsuite/make.tests index a0ca9778b..f52770438 100755 --- a/testsuite/make.tests +++ b/testsuite/make.tests | |||
| @@ -379,6 +379,24 @@ t1? t2* t3[abc]: s1? s2* s3[abc] | |||
| 379 | ' | 379 | ' |
| 380 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | 380 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null |
| 381 | 381 | ||
| 382 | # A '#' character in a macro expansion doesn't start a comment | ||
| 383 | testing "make hash in macro expansion isn't a comment" \ | ||
| 384 | "make -f -" \ | ||
| 385 | ": hash # hash\n" "" ' | ||
| 386 | HASH = hash | ||
| 387 | hash = $(HASH:hash=#) | ||
| 388 | target: | ||
| 389 | : hash $(hash) hash | ||
| 390 | ' | ||
| 391 | |||
| 392 | # A '#' character in a command line doesn't start a comment | ||
| 393 | testing "make hash in command line isn't a comment" \ | ||
| 394 | "make -f -" \ | ||
| 395 | ": hash # hash\n" "" ' | ||
| 396 | target: | ||
| 397 | : hash # hash | ||
| 398 | ' | ||
| 399 | |||
| 382 | # Skip duplicate entries in $? and $^ | 400 | # Skip duplicate entries in $? and $^ |
| 383 | mkdir make.tempdir && cd make.tempdir || exit 1 | 401 | mkdir make.tempdir && cd make.tempdir || exit 1 |
| 384 | touch -t 202206171200 file1 file3 | 402 | touch -t 202206171200 file1 file3 |
