Module Name: src Committed By: sjg Date: Sun Mar 30 21:24:57 UTC 2025
Modified Files: src/usr.bin/make: main.c make.1 make.h parse.c var.c Log Message: make: POSIX mode, check for sysV style modifiers first A POSIX compatible makefile should not be using any of our native modifiers, so give preference to the sysV style modifier and only check the others as a fallback. Reviewed by: rillig To generate a diff of this commit: cvs rdiff -u -r1.639 -r1.640 src/usr.bin/make/main.c cvs rdiff -u -r1.381 -r1.382 src/usr.bin/make/make.1 cvs rdiff -u -r1.351 -r1.352 src/usr.bin/make/make.h cvs rdiff -u -r1.740 -r1.741 src/usr.bin/make/parse.c cvs rdiff -u -r1.1157 -r1.1158 src/usr.bin/make/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/main.c diff -u src/usr.bin/make/main.c:1.639 src/usr.bin/make/main.c:1.640 --- src/usr.bin/make/main.c:1.639 Fri Mar 7 06:50:34 2025 +++ src/usr.bin/make/main.c Sun Mar 30 21:24:57 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.639 2025/03/07 06:50:34 rillig Exp $ */ +/* $NetBSD: main.c,v 1.640 2025/03/30 21:24:57 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -108,7 +108,7 @@ #include "trace.h" /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: main.c,v 1.639 2025/03/07 06:50:34 rillig Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.640 2025/03/30 21:24:57 sjg Exp $"); #if defined(MAKE_NATIVE) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -2114,12 +2114,17 @@ PrintOnError(GNode *gn, const char *msg) SetErrorVars(gn); { - char *errorVarsValues = Var_Subst( + char *errorVarsValues; + enum PosixState p_s = posix_state; + + posix_state = PS_TOO_LATE; + errorVarsValues = Var_Subst( "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}", SCOPE_GLOBAL, VARE_EVAL); /* TODO: handle errors */ printf("%s", errorVarsValues); free(errorVarsValues); + posix_state = p_s; } fflush(stdout); @@ -2138,12 +2143,15 @@ void Main_ExportMAKEFLAGS(bool first) { static bool once = true; + enum PosixState p_s; char *flags; if (once != first) return; once = false; + p_s = posix_state; + posix_state = PS_TOO_LATE; flags = Var_Subst( "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}", SCOPE_CMDLINE, VARE_EVAL); @@ -2151,6 +2159,7 @@ Main_ExportMAKEFLAGS(bool first) if (flags[0] != '\0') setenv("MAKEFLAGS", flags, 1); free(flags); + posix_state = p_s; } char * Index: src/usr.bin/make/make.1 diff -u src/usr.bin/make/make.1:1.381 src/usr.bin/make/make.1:1.382 --- src/usr.bin/make/make.1:1.381 Thu Nov 14 19:30:13 2024 +++ src/usr.bin/make/make.1 Sun Mar 30 21:24:57 2025 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.381 2024/11/14 19:30:13 sjg Exp $ +.\" $NetBSD: make.1,v 1.382 2025/03/30 21:24:57 sjg Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd November 14, 2024 +.Dd March 30, 2025 .Dt MAKE 1 .Os .Sh NAME @@ -2535,6 +2535,8 @@ is run with the flag, only .Ql posix.mk contributes to the default rules. +In POSIX-compatible mode, the AT&T System V UNIX style substitution +modifier is checked first rather than as a fallback. .It Ic .PRECIOUS Apply the .Ic .PRECIOUS Index: src/usr.bin/make/make.h diff -u src/usr.bin/make/make.h:1.351 src/usr.bin/make/make.h:1.352 --- src/usr.bin/make/make.h:1.351 Sat Mar 29 21:30:47 2025 +++ src/usr.bin/make/make.h Sun Mar 30 21:24:57 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.351 2025/03/29 21:30:47 rillig Exp $ */ +/* $NetBSD: make.h,v 1.352 2025/03/30 21:24:57 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -530,6 +530,7 @@ extern enum PosixState { PS_NOT_YET, PS_MAYBE_NEXT_LINE, PS_NOW_OR_NEVER, + PS_SET, PS_TOO_LATE } posix_state; Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.740 src/usr.bin/make/parse.c:1.741 --- src/usr.bin/make/parse.c:1.740 Sun Mar 30 09:51:49 2025 +++ src/usr.bin/make/parse.c Sun Mar 30 21:24:57 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.740 2025/03/30 09:51:49 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.741 2025/03/30 21:24:57 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -105,7 +105,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.740 2025/03/30 09:51:49 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.741 2025/03/30 21:24:57 sjg Exp $"); /* Detects a multiple-inclusion guard in a makefile. */ typedef enum { @@ -1313,6 +1313,7 @@ HandleDependencySourcesEmpty(ParseSpecia * otherwise it is an extension. */ Global_Set("%POSIX", "1003.2"); + posix_state = PS_SET; IncludeFile("posix.mk", true, false, true); } break; Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1157 src/usr.bin/make/var.c:1.1158 --- src/usr.bin/make/var.c:1.1157 Sun Mar 30 01:27:12 2025 +++ src/usr.bin/make/var.c Sun Mar 30 21:24:57 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1157 2025/03/30 01:27:12 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1158 2025/03/30 21:24:57 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -128,7 +128,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1157 2025/03/30 01:27:12 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1158 2025/03/30 21:24:57 sjg Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -3987,9 +3987,14 @@ ApplySingleModifier(const char **pp, Mod if (DEBUG(VAR)) LogBeforeApply(ch, mod); - res = ApplyModifier(&p, ch); + if (posix_state == PS_SET) + res = ApplyModifier_SysV(&p, ch); + else + res = AMR_UNKNOWN; + if (res == AMR_UNKNOWN) + res = ApplyModifier(&p, ch); - if (res == AMR_UNKNOWN) { + if (res == AMR_UNKNOWN && posix_state != PS_SET) { assert(p == mod); res = ApplyModifier_SysV(&p, ch); }