Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Include posix.mk when .POSIX: first encountered
details: https://anonhg.NetBSD.org/src/rev/e25f5542a1fe
branches: trunk
changeset: 364448:e25f5542a1fe
user: sjg <sjg%NetBSD.org@localhost>
date: Fri Mar 25 21:16:04 2022 +0000
description:
Include posix.mk when .POSIX: first encountered
Since .POSIX: is required to be the first non-comment line
in a Makefile, including ${MAKE_POSIX_MK} or whatever _PATH_POSIX_MK is
set to at this point is equivalent to an extension of sys.mk
This is a minimal change that can allow a better approximation of
POSIX compliance
Reviewed by: rillig
diffstat:
usr.bin/make/make.1 | 16 ++-
usr.bin/make/parse.c | 250 +++++++++++++++++++++++++++-----------------------
2 files changed, 148 insertions(+), 118 deletions(-)
diffs (truncated from 322 to 300 lines):
diff -r 6a4b4195a687 -r e25f5542a1fe usr.bin/make/make.1
--- a/usr.bin/make/make.1 Fri Mar 25 19:34:04 2022 +0000
+++ b/usr.bin/make/make.1 Fri Mar 25 21:16:04 2022 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: make.1,v 1.305 2022/02/09 21:09:24 rillig Exp $
+.\" $NetBSD: make.1,v 1.306 2022/03/25 21:16:04 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 January 28, 2022
+.Dd March 24, 2022
.Dt MAKE 1
.Os
.Sh NAME
@@ -2289,6 +2289,18 @@
Apply the
.Ic .PHONY
attribute to any specified sources.
+.It Ic .POSIX
+This should be the first non-comment line in a Makefile.
+It results in the variable
+.Va %POSIX
+being defined with the value
+.Ql 1003.2 .
+The first time
+.Ic .POSIX
+is encountered, the makefile
+.Ql posix.mk
+will be included if possible,
+to provide POSIX compatible default rules.
.It Ic .PRECIOUS
Apply the
.Ic .PRECIOUS
diff -r 6a4b4195a687 -r e25f5542a1fe usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Fri Mar 25 19:34:04 2022 +0000
+++ b/usr.bin/make/parse.c Fri Mar 25 21:16:04 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.667 2022/03/03 19:55:27 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.668 2022/03/25 21:16:04 sjg 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.667 2022/03/03 19:55:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.668 2022/03/25 21:16:04 sjg Exp $");
/*
* A file being read.
@@ -1115,6 +1115,121 @@
Dir_SetPATH();
}
+/*
+ * Handle one of the .[-ds]include directives by remembering the current file
+ * and pushing the included file on the stack. After the included file has
+ * finished, parsing continues with the including file; see Parse_PushInput
+ * and ParseEOF.
+ *
+ * System includes are looked up in sysIncPath, any other includes are looked
+ * up in the parsedir and then in the directories specified by the -I command
+ * line options.
+ */
+static void
+IncludeFile(const char *file, bool isSystem, bool depinc, bool silent)
+{
+ Buffer buf;
+ char *fullname; /* full pathname of file */
+ char *newName;
+ char *slash, *incdir;
+ int fd;
+ int i;
+
+ fullname = file[0] == '/' ? bmake_strdup(file) : NULL;
+
+ if (fullname == NULL && !isSystem) {
+ /*
+ * Include files contained in double-quotes are first searched
+ * relative to the including file's location. We don't want to
+ * cd there, of course, so we just tack on the old file's
+ * leading path components and call Dir_FindFile to see if
+ * we can locate the file.
+ */
+
+ incdir = bmake_strdup(CurFile()->name.str);
+ slash = strrchr(incdir, '/');
+ if (slash != NULL) {
+ *slash = '\0';
+ /*
+ * Now do lexical processing of leading "../" on the
+ * filename.
+ */
+ for (i = 0; strncmp(file + i, "../", 3) == 0; i += 3) {
+ slash = strrchr(incdir + 1, '/');
+ if (slash == NULL || strcmp(slash, "/..") == 0)
+ break;
+ *slash = '\0';
+ }
+ newName = str_concat3(incdir, "/", file + i);
+ fullname = Dir_FindFile(newName, parseIncPath);
+ if (fullname == NULL)
+ fullname = Dir_FindFile(newName,
+ &dirSearchPath);
+ free(newName);
+ }
+ free(incdir);
+
+ if (fullname == NULL) {
+ /*
+ * Makefile wasn't found in same directory as included
+ * makefile.
+ *
+ * Search for it first on the -I search path, then on
+ * the .PATH search path, if not found in a -I
+ * directory. If we have a suffix-specific path, we
+ * should use that.
+ */
+ const char *suff;
+ SearchPath *suffPath = NULL;
+
+ if ((suff = strrchr(file, '.')) != NULL) {
+ suffPath = Suff_GetPath(suff);
+ if (suffPath != NULL)
+ fullname = Dir_FindFile(file, suffPath);
+ }
+ if (fullname == NULL) {
+ fullname = Dir_FindFile(file, parseIncPath);
+ if (fullname == NULL)
+ fullname = Dir_FindFile(file,
+ &dirSearchPath);
+ }
+ }
+ }
+
+ /* Looking for a system file or file still not found */
+ if (fullname == NULL) {
+ /*
+ * Look for it on the system path
+ */
+ SearchPath *path = Lst_IsEmpty(&sysIncPath->dirs)
+ ? defSysIncPath : sysIncPath;
+ fullname = Dir_FindFile(file, path);
+ }
+
+ if (fullname == NULL) {
+ if (!silent)
+ Parse_Error(PARSE_FATAL, "Could not find %s", file);
+ return;
+ }
+
+ /* Actually open the file... */
+ fd = open(fullname, O_RDONLY);
+ if (fd == -1) {
+ if (!silent)
+ Parse_Error(PARSE_FATAL, "Cannot open %s", fullname);
+ free(fullname);
+ return;
+ }
+
+ buf = loadfile(fullname, fd);
+ (void)close(fd);
+
+ Parse_PushInput(fullname, 1, 0, buf, NULL);
+ if (depinc)
+ doing_depend = depinc; /* only turn it on */
+ free(fullname);
+}
+
/* Handle a "dependency" line like '.SPECIAL:' without any sources. */
static void
HandleDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths)
@@ -1138,6 +1253,23 @@
#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);
+ }
+ }
break;
#endif
default:
@@ -1823,120 +1955,6 @@
(void)SearchPath_Add(parseIncPath, dir);
}
-/*
- * Handle one of the .[-ds]include directives by remembering the current file
- * and pushing the included file on the stack. After the included file has
- * finished, parsing continues with the including file; see Parse_PushInput
- * and ParseEOF.
- *
- * System includes are looked up in sysIncPath, any other includes are looked
- * up in the parsedir and then in the directories specified by the -I command
- * line options.
- */
-static void
-IncludeFile(const char *file, bool isSystem, bool depinc, bool silent)
-{
- Buffer buf;
- char *fullname; /* full pathname of file */
- char *newName;
- char *slash, *incdir;
- int fd;
- int i;
-
- fullname = file[0] == '/' ? bmake_strdup(file) : NULL;
-
- if (fullname == NULL && !isSystem) {
- /*
- * Include files contained in double-quotes are first searched
- * relative to the including file's location. We don't want to
- * cd there, of course, so we just tack on the old file's
- * leading path components and call Dir_FindFile to see if
- * we can locate the file.
- */
-
- incdir = bmake_strdup(CurFile()->name.str);
- slash = strrchr(incdir, '/');
- if (slash != NULL) {
- *slash = '\0';
- /*
- * Now do lexical processing of leading "../" on the
- * filename.
- */
- for (i = 0; strncmp(file + i, "../", 3) == 0; i += 3) {
- slash = strrchr(incdir + 1, '/');
- if (slash == NULL || strcmp(slash, "/..") == 0)
- break;
- *slash = '\0';
- }
- newName = str_concat3(incdir, "/", file + i);
- fullname = Dir_FindFile(newName, parseIncPath);
- if (fullname == NULL)
- fullname = Dir_FindFile(newName,
- &dirSearchPath);
- free(newName);
- }
- free(incdir);
-
- if (fullname == NULL) {
- /*
- * Makefile wasn't found in same directory as included
- * makefile.
- *
- * Search for it first on the -I search path, then on
- * the .PATH search path, if not found in a -I
- * directory. If we have a suffix-specific path, we
- * should use that.
- */
- const char *suff;
- SearchPath *suffPath = NULL;
-
- if ((suff = strrchr(file, '.')) != NULL) {
- suffPath = Suff_GetPath(suff);
- if (suffPath != NULL)
- fullname = Dir_FindFile(file, suffPath);
- }
- if (fullname == NULL) {
- fullname = Dir_FindFile(file, parseIncPath);
- if (fullname == NULL)
- fullname = Dir_FindFile(file,
- &dirSearchPath);
- }
- }
- }
-
- /* Looking for a system file or file still not found */
- if (fullname == NULL) {
- /*
- * Look for it on the system path
- */
- SearchPath *path = Lst_IsEmpty(&sysIncPath->dirs)
- ? defSysIncPath : sysIncPath;
- fullname = Dir_FindFile(file, path);
- }
-
- if (fullname == NULL) {
- if (!silent)
- Parse_Error(PARSE_FATAL, "Could not find %s", file);
- return;
Home |
Main Index |
Thread Index |
Old Index