summaryrefslogtreecommitdiff
path: root/usr.bin/make/parse.c
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2022-04-18 15:06:27 +0000
committerrillig <rillig@NetBSD.org>2022-04-18 15:06:27 +0000
commit686b9d31508b5cf03b7362f4e2f8a28d78bef7d8 (patch)
treecca4fc84a4c4f12425cdf1a45acd269d02d56b3b /usr.bin/make/parse.c
parent437e498c7a66a13ccb91525f7f4f49e68f107a3c (diff)
make: only switch to POSIX mode if '.POSIX:' is the first line
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html says that in order to make a makefile POSIX-conforming, its first non-comment line must be the special dependency line '.POSIX:' without any source dependencies. Previously, make switched to POSIX mode even if such a line occurred anywhere else, which was allowed by POSIX but was deep in the "unspecified behavior" area. For NetBSD make, there is no big difference since it doesn't ship any <posix.mk> file, this change mainly affects the bmake distribution. Previously, makefiles that contain '.POSIX:' somewhere in the middle could fail due to <posix.mk> resetting .SUFFIXES, among other things. Suggested by Simon J. Gerraty, who also reviewed an earlier version of this change.
Diffstat (limited to 'usr.bin/make/parse.c')
-rw-r--r--usr.bin/make/parse.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index 49dc2d0024b..c168aba4abe 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.668 2022/03/25 21:16:04 sjg Exp $ */
+/* $NetBSD: parse.c,v 1.669 2022/04/18 15:06:27 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -106,7 +106,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.668 2022/03/25 21:16:04 sjg Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.669 2022/04/18 15:06:27 rillig Exp $");
/*
* A file being read.
@@ -294,6 +294,7 @@ static const struct {
{ ".WAIT", SP_WAIT, OP_NONE },
};
+enum PosixState posix_state = PS_NOT_YET;
static IncludedFile *
GetInclude(size_t i)
@@ -1252,23 +1253,9 @@ HandleDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths)
break;
#ifdef POSIX
case SP_POSIX:
- Global_Set("%POSIX", "1003.2");
- {
- static bool first_posix = true;
-
- /*
- * Since .POSIX: should be the first
- * operative line in a makefile,
- * if '-r' flag is used, no default rules have
- * been read yet, in which case 'posix.mk' can
- * be a substiute for 'sys.mk'.
- * If '-r' is not used, then 'posix.mk' acts
- * as an extension of 'sys.mk'.
- */
- if (first_posix) {
- first_posix = false;
- IncludeFile("posix.mk", true, false, true);
- }
+ if (posix_state == PS_NOW_OR_NEVER) {
+ Global_Set("%POSIX", "1003.2");
+ IncludeFile("posix.mk", true, false, true);
}
break;
#endif
@@ -2590,6 +2577,10 @@ ReadHighLevelLine(void)
for (;;) {
line = ReadLowLevelLine(LK_NONEMPTY);
+ if (posix_state == PS_MAYBE_NEXT_LINE)
+ posix_state = PS_NOW_OR_NEVER;
+ else
+ posix_state = PS_TOO_LATE;
if (line == NULL)
return NULL;