diff options
author | Ron Yorston <rmy@pobox.com> | 2024-10-20 12:52:42 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-10-20 12:52:42 +0100 |
commit | ef4756eb0994bc25de66cbb04e1752dda217ff5d (patch) | |
tree | b5e13e2148177d67993d50e547de3f8c5ad1e85a /miscutils/make.c | |
parent | 253bcde618f9f3f4b12015bcc62f59e8cddff45d (diff) | |
download | busybox-w32-ef4756eb0994bc25de66cbb04e1752dda217ff5d.tar.gz busybox-w32-ef4756eb0994bc25de66cbb04e1752dda217ff5d.tar.bz2 busybox-w32-ef4756eb0994bc25de66cbb04e1752dda217ff5d.zip |
make: changes to .DEFAULT/inference rules
The POSIX standard allows inference rules to be redefined but not
the .DEFAULT rule. There is no explicit exception for .DEFAULT to:
Only one target rule for any given target can contain commands.
Treat redefinition of a .DEFAULT rule as an error in POSIX mode
but allow it as an extension.
Also, the code didn't allow an inference rule with dependencies to
redefine an existing inference rule. This is no longer the case.
Adds 64-96 bytes.
Diffstat (limited to 'miscutils/make.c')
-rw-r--r-- | miscutils/make.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/miscutils/make.c b/miscutils/make.c index cc5e7ca92..df810677f 100644 --- a/miscutils/make.c +++ b/miscutils/make.c | |||
@@ -188,6 +188,7 @@ struct name { | |||
188 | #define N_SPECIAL 0x80 // Special target | 188 | #define N_SPECIAL 0x80 // Special target |
189 | #define N_MARK 0x100 // Mark for deduplication | 189 | #define N_MARK 0x100 // Mark for deduplication |
190 | #define N_PHONY 0x200 // Name is a phony target | 190 | #define N_PHONY 0x200 // Name is a phony target |
191 | #define N_INFERENCE 0x400 // Inference rule | ||
191 | 192 | ||
192 | // List of rules to build a target | 193 | // List of rules to build a target |
193 | struct rule { | 194 | struct rule { |
@@ -736,7 +737,10 @@ addrule(struct name *np, struct depend *dp, struct cmd *cp, int flag) | |||
736 | 737 | ||
737 | if (cp && !(np->n_flag & N_DOUBLE) && getcmd(np)) { | 738 | if (cp && !(np->n_flag & N_DOUBLE) && getcmd(np)) { |
738 | // Handle the inference rule redefinition case | 739 | // Handle the inference rule redefinition case |
739 | if ((np->n_flag & N_SPECIAL) && !dp) { | 740 | // .DEFAULT rule can also be redefined (as an extension). |
741 | if ((np->n_flag & N_INFERENCE) | ||
742 | && !(posix && (np->n_flag & N_SPECIAL)) | ||
743 | ) { | ||
740 | freerules(np->n_rule); | 744 | freerules(np->n_rule); |
741 | np->n_rule = NULL; | 745 | np->n_rule = NULL; |
742 | } else { | 746 | } else { |
@@ -2343,12 +2347,19 @@ input(FILE *fd, int ilevel) | |||
2343 | 2347 | ||
2344 | np = newname(files[i]); | 2348 | np = newname(files[i]); |
2345 | if (ttype != T_NORMAL) { | 2349 | if (ttype != T_NORMAL) { |
2346 | if (ttype == T_INFERENCE && posix) { | 2350 | if (ttype == T_INFERENCE) { |
2347 | if (semicolon_cmd) | 2351 | if (posix) { |
2348 | error_in_inference_rule("'; command'"); | 2352 | if (semicolon_cmd) |
2349 | seen_inference = TRUE; | 2353 | error_in_inference_rule("'; command'"); |
2354 | seen_inference = TRUE; | ||
2355 | } | ||
2356 | np->n_flag |= N_INFERENCE; | ||
2357 | } else if (strcmp(p, ".DEFAULT") == 0) { | ||
2358 | // .DEFAULT rule is a special case | ||
2359 | np->n_flag |= N_SPECIAL | N_INFERENCE; | ||
2360 | } else { | ||
2361 | np->n_flag |= N_SPECIAL; | ||
2350 | } | 2362 | } |
2351 | np->n_flag |= N_SPECIAL; | ||
2352 | } else if (!firstname) { | 2363 | } else if (!firstname) { |
2353 | firstname = np; | 2364 | firstname = np; |
2354 | } | 2365 | } |
@@ -2358,7 +2369,7 @@ input(FILE *fd, int ilevel) | |||
2358 | if (files != &p) | 2369 | if (files != &p) |
2359 | globfree(&gd); | 2370 | globfree(&gd); |
2360 | } | 2371 | } |
2361 | if (seen_inference && count != 1) | 2372 | if (posix && seen_inference && count != 1) |
2362 | error_in_inference_rule("multiple targets"); | 2373 | error_in_inference_rule("multiple targets"); |
2363 | 2374 | ||
2364 | // Prerequisites and commands will be unused if there were | 2375 | // Prerequisites and commands will be unused if there were |