From 48f5ecaf27d900ffea77dbda762202d73223ec32 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 4 Jun 2024 13:55:25 +0100 Subject: make: explicitly verify order of arguments POSIX requires macro assignments to precede targets on the command line. This requirement has been relaxed as a non-POSIX extension. Verify the constraint has been applied in POSIX mode. This ensures that the command: make --posix target A=1 fails before it tries to update the target. It also catches the case where POSIX mode had not been set with the --posix option or PDPMAKE_POSIXLY_CORRECT environment but was then set by the .POSIX special target in the makefile. In this case the command line was scanned for macro assignments without enforcing POSIX mode while targets were processed with POSIX mode enabled. Adds 96 bytes. --- miscutils/make.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index f44de5df6..0235d9877 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -3156,16 +3156,25 @@ int make_main(int argc UNUSED_PARAM, char **argv) if (!POSIX_2017) mark_special(".PHONY", OPT_phony, N_PHONY); + if (posix) { + // In POSIX mode only targets should now be in argv. + found_target = FALSE; + for (char **a = argv; *a; a++) { + if (!strchr(*a, '=')) + found_target = TRUE; + else if (found_target) + error("macro assignments must precede targets"); + } + } + estat = 0; found_target = FALSE; for (; *argv; argv++) { - // In POSIX mode only targets should now be in argv. - // As an extension macros may still be present: skip them. - if (posix || !strchr(*argv, '=')) - { - found_target = TRUE; - estat |= make(newname(*argv), 0); - } + // Skip macro assignments. + if (strchr(*argv, '=')) + continue; + found_target = TRUE; + estat |= make(newname(*argv), 0); } if (!found_target) { if (!firstname) -- cgit v1.2.3-55-g6feb