Module Name:    src
Committed By:   sjg
Date:           Tue Jan 24 00:24:02 UTC 2023

Modified Files:
        src/usr.bin/make: dir.c dir.h main.c make.1 parse.c
        src/usr.bin/make/unit-tests: Makefile dir.mk opt-debug-graph1.exp
            opt-debug-graph2.exp opt-debug-graph3.exp suff-main-several.exp
            suff-transform-debug.exp

Log Message:
make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig


To generate a diff of this commit:
cvs rdiff -u -r1.279 -r1.280 src/usr.bin/make/dir.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/make/dir.h
cvs rdiff -u -r1.587 -r1.588 src/usr.bin/make/main.c
cvs rdiff -u -r1.358 -r1.359 src/usr.bin/make/make.1
cvs rdiff -u -r1.691 -r1.692 src/usr.bin/make/parse.c
cvs rdiff -u -r1.330 -r1.331 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/dir.mk
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/opt-debug-graph1.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/opt-debug-graph2.exp \
    src/usr.bin/make/unit-tests/opt-debug-graph3.exp \
    src/usr.bin/make/unit-tests/suff-transform-debug.exp
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/suff-main-several.exp

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/dir.c
diff -u src/usr.bin/make/dir.c:1.279 src/usr.bin/make/dir.c:1.280
--- src/usr.bin/make/dir.c:1.279	Sat May  7 21:19:43 2022
+++ src/usr.bin/make/dir.c	Tue Jan 24 00:24:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.279 2022/05/07 21:19:43 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.280 2023/01/24 00:24:02 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -138,7 +138,7 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.279 2022/05/07 21:19:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.280 2023/01/24 00:24:02 sjg Exp $");
 
 /*
  * A search path is a list of CachedDir structures. A CachedDir has in it the
@@ -577,6 +577,21 @@ Dir_SetPATH(void)
 	}
 }
 
+
+void
+Dir_SetSYSPATH(void)
+{
+	CachedDirListNode *ln;
+
+	Var_ReadOnly(".SYSPATH", false);
+	Global_Delete(".SYSPATH");
+	for (ln = sysIncPath->dirs.first; ln != NULL; ln = ln->next) {
+		CachedDir *dir = ln->datum;
+		Global_Append(".SYSPATH", dir->name);
+	}
+	Var_ReadOnly(".SYSPATH", true);
+}
+
 /*
  * See if the given name has any wildcard characters in it and all braces and
  * brackets are properly balanced.

Index: src/usr.bin/make/dir.h
diff -u src/usr.bin/make/dir.h:1.46 src/usr.bin/make/dir.h:1.47
--- src/usr.bin/make/dir.h:1.46	Wed Dec 15 12:08:25 2021
+++ src/usr.bin/make/dir.h	Tue Jan 24 00:24:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.h,v 1.46 2021/12/15 12:08:25 rillig Exp $	*/
+/*	$NetBSD: dir.h,v 1.47 2023/01/24 00:24:02 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -82,6 +82,7 @@ void Dir_InitCur(const char *);
 void Dir_InitDot(void);
 void Dir_End(void);
 void Dir_SetPATH(void);
+void Dir_SetSYSPATH(void);
 bool Dir_HasWildcards(const char *) MAKE_ATTR_USE;
 void SearchPath_Expand(SearchPath *, const char *, StringList *);
 char *Dir_FindFile(const char *, SearchPath *) MAKE_ATTR_USE;

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.587 src/usr.bin/make/main.c:1.588
--- src/usr.bin/make/main.c:1.587	Thu Jan 19 21:33:06 2023
+++ src/usr.bin/make/main.c	Tue Jan 24 00:24:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.587 2023/01/19 21:33:06 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.588 2023/01/24 00:24:02 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.587 2023/01/19 21:33:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.588 2023/01/24 00:24:02 sjg Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -428,6 +428,7 @@ MainParseArgSysInc(const char *argvalue)
 	}
 	Global_Append(MAKEFLAGS, "-m");
 	Global_Append(MAKEFLAGS, argvalue);
+	Dir_SetSYSPATH();
 }
 
 static bool
@@ -1477,6 +1478,10 @@ static void
 main_ReadFiles(void)
 {
 
+	if (Lst_IsEmpty(&sysIncPath->dirs))
+		SearchPath_AddAll(sysIncPath, defSysIncPath);
+
+	Dir_SetSYSPATH();
 	if (!opts.noBuiltins)
 		ReadBuiltinRules();
 

Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.358 src/usr.bin/make/make.1:1.359
--- src/usr.bin/make/make.1:1.358	Mon Jan 23 23:01:52 2023
+++ src/usr.bin/make/make.1	Tue Jan 24 00:24:02 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.358 2023/01/23 23:01:52 sjg Exp $
+.\"	$NetBSD: make.1,v 1.359 2023/01/24 00:24:02 sjg Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -299,6 +299,8 @@ Furthermore, the system include path is 
 include statements (see the
 .Fl I
 option).
+The system include path can be referenced via the read-only variable
+.Va .SYSPATH .
 .Pp
 If a directory name in the
 .Fl m
@@ -1326,6 +1328,13 @@ It is read-only.
 .It Va .SUFFIXES
 The list of known suffixes.
 It is read-only.
+.It Va .SYSPATH
+The space-separated list of directories that
+.Nm
+searches for makefiles, referred to as the system include path.
+To update this search list, use the special target
+.Sq Ic .SYSPATH
+rather than modifying the variable which is read-only.
 .It Va .TARGETS
 The list of targets explicitly specified on the command line, if any.
 .It Va VPATH
@@ -2534,6 +2543,14 @@ Example:
 \&.c.o:
 	cc \-o ${.TARGET} \-c ${.IMPSRC}
 .Ed
+.It Ic .SYSPATH
+The sources are directories which are to be added to the system
+include path which
+.Nm
+searches for makefiles.
+If no sources are specified,
+any previously specified directories are removed from the system
+include path.
 .El
 .Sh ENVIRONMENT
 .Nm

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.691 src/usr.bin/make/parse.c:1.692
--- src/usr.bin/make/parse.c:1.691	Mon Jan 23 23:01:52 2023
+++ src/usr.bin/make/parse.c	Tue Jan 24 00:24:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.691 2023/01/23 23:01:52 sjg Exp $	*/
+/*	$NetBSD: parse.c,v 1.692 2023/01/24 00:24:02 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.691 2023/01/23 23:01:52 sjg Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.692 2023/01/24 00:24:02 sjg Exp $");
 
 /*
  * A file being read.
@@ -168,6 +168,7 @@ typedef enum ParseSpecial {
 	SP_SINGLESHELL,	/* .SINGLESHELL; not mentioned in the manual page */
 	SP_STALE,	/* .STALE */
 	SP_SUFFIXES,	/* .SUFFIXES */
+	SP_SYSPATH,	/* .SYSPATH */
 	SP_WAIT		/* .WAIT */
 } ParseSpecial;
 
@@ -293,6 +294,7 @@ static const struct {
     { ".SINGLESHELL",	SP_SINGLESHELL,	OP_NONE },
     { ".STALE",		SP_STALE,	OP_NONE },
     { ".SUFFIXES",	SP_SUFFIXES,	OP_NONE },
+    { ".SYSPATH",	SP_SYSPATH,	OP_NONE },
     { ".USE",		SP_ATTRIBUTE,	OP_USE },
     { ".USEBEFORE",	SP_ATTRIBUTE,	OP_USEBEFORE },
     { ".WAIT",		SP_WAIT,	OP_NONE },
@@ -923,6 +925,11 @@ HandleDependencyTargetSpecial(const char
 			*inout_paths = Lst_New();
 		Lst_Append(*inout_paths, &dirSearchPath);
 		break;
+	case SP_SYSPATH:
+		if (*inout_paths == NULL)
+			*inout_paths = Lst_New();
+		Lst_Append(*inout_paths, sysIncPath);
+		break;
 	case SP_MAIN:
 		/*
 		 * Allow targets from the command line to override the
@@ -1129,15 +1136,17 @@ ParseDependencyOp(char **pp)
 }
 
 static void
-ClearPaths(SearchPathList *paths)
+ClearPaths(ParseSpecial special, SearchPathList *paths)
 {
 	if (paths != NULL) {
 		SearchPathListNode *ln;
 		for (ln = paths->first; ln != NULL; ln = ln->next)
 			SearchPath_Clear(ln->datum);
 	}
-
-	Dir_SetPATH();
+	if (special == SP_SYSPATH)
+		Dir_SetSYSPATH();
+	else
+		Dir_SetPATH();
 }
 
 static char *
@@ -1258,7 +1267,8 @@ HandleDependencySourcesEmpty(ParseSpecia
 		opts.silent = true;
 		break;
 	case SP_PATH:
-		ClearPaths(paths);
+	case SP_SYSPATH:
+		ClearPaths(special, paths);
 		break;
 #ifdef POSIX
 	case SP_POSIX:
@@ -1322,6 +1332,9 @@ ParseDependencySourceSpecial(ParseSpecia
 	case SP_READONLY:
 		Var_ReadOnly(word, true);
 		break;
+	case SP_SYSPATH:
+		AddToPaths(word, paths);
+		break;
 	default:
 		break;
 	}
@@ -1543,6 +1556,7 @@ ParseDependencySources(char *p, GNodeTyp
 	case SP_PATH:
 	case SP_READONLY:
 	case SP_SUFFIXES:
+	case SP_SYSPATH:
 		ParseDependencySourcesSpecial(p, special, *inout_paths);
 		if (*inout_paths != NULL) {
 			Lst_Free(*inout_paths);
@@ -1550,6 +1564,8 @@ ParseDependencySources(char *p, GNodeTyp
 		}
 		if (special == SP_PATH)
 			Dir_SetPATH();
+		if (special == SP_SYSPATH)
+			Dir_SetSYSPATH();
 		break;
 	default:
 		assert(*inout_paths == NULL);

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.330 src/usr.bin/make/unit-tests/Makefile:1.331
--- src/usr.bin/make/unit-tests/Makefile:1.330	Mon Jan 23 23:01:52 2023
+++ src/usr.bin/make/unit-tests/Makefile	Tue Jan 24 00:24:02 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.330 2023/01/23 23:01:52 sjg Exp $
+# $NetBSD: Makefile,v 1.331 2023/01/24 00:24:02 sjg Exp $
 #
 # Unit tests for make(1)
 #
@@ -538,7 +538,7 @@ SED_CMDS.varname-dot-parsefile=	-e '/in 
 SED_CMDS.varname-dot-shell=	-e 's, = /[^ ]*, = (details omitted),g'
 SED_CMDS.varname-dot-shell+=	-e 's,"/[^" ]*","(details omitted)",g'
 SED_CMDS.varname-dot-shell+=	-e 's,\[/[^] ]*\],[(details omitted)],g'
-SED_CMDS.varname-empty=		${.OBJDIR .PARSEDIR .PATH .SHELL:L:@v@-e '/\\$v/d'@}
+SED_CMDS.varname-empty=		${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@}
 
 # Some tests need an additional round of postprocessing.
 POSTPROC.depsrc-wait=		sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,'
@@ -568,6 +568,7 @@ STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE\.[A-Z
 STD_SED_CMDS.dg1+=	-e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
 STD_SED_CMDS.dg1+=	-e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
 STD_SED_CMDS.dg1+=	-e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,'
+STD_SED_CMDS.dg1+=	-e '/\.SYSPATH/d'
 
 STD_SED_CMDS.dg2=	${STD_SED_CMDS.dg1}
 STD_SED_CMDS.dg2+=	-e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,'

Index: src/usr.bin/make/unit-tests/dir.mk
diff -u src/usr.bin/make/unit-tests/dir.mk:1.9 src/usr.bin/make/unit-tests/dir.mk:1.10
--- src/usr.bin/make/unit-tests/dir.mk:1.9	Sat Jan 23 10:48:49 2021
+++ src/usr.bin/make/unit-tests/dir.mk	Tue Jan 24 00:24:02 2023
@@ -1,8 +1,10 @@
-# $NetBSD: dir.mk,v 1.9 2021/01/23 10:48:49 rillig Exp $
+# $NetBSD: dir.mk,v 1.10 2023/01/24 00:24:02 sjg Exp $
 #
 # Tests for dir.c.
 
-.MAKEFLAGS: -m /		# hide /usr/share/mk from the debug log
+# hide /usr/share/mk from the debug log
+.SYSPATH:
+.SYSPATH: /
 
 # Dependency lines may use braces for expansion.
 # See DirExpandCurly for the implementation.

Index: src/usr.bin/make/unit-tests/opt-debug-graph1.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-graph1.exp:1.10 src/usr.bin/make/unit-tests/opt-debug-graph1.exp:1.11
--- src/usr.bin/make/unit-tests/opt-debug-graph1.exp:1.10	Sat Mar 26 14:34:07 2022
+++ src/usr.bin/make/unit-tests/opt-debug-graph1.exp	Tue Jan 24 00:24:02 2023
@@ -48,7 +48,7 @@ MFLAGS           =   -r -k -d g1
 #  refs  hits  directory
 #     1     0  <curdir>
 #     1     0  .
-#     1     0  <defsyspath>
+#     2     0  <defsyspath>
 
 #*** Suffixes:
 #*** Transformations:

Index: src/usr.bin/make/unit-tests/opt-debug-graph2.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-graph2.exp:1.5 src/usr.bin/make/unit-tests/opt-debug-graph2.exp:1.6
--- src/usr.bin/make/unit-tests/opt-debug-graph2.exp:1.5	Sat Mar 26 14:34:07 2022
+++ src/usr.bin/make/unit-tests/opt-debug-graph2.exp	Tue Jan 24 00:24:02 2023
@@ -83,7 +83,7 @@ MFLAGS           =   -r -k -d g2
 #  refs  hits  directory
 #     1     0  <curdir>
 #     1     0  .
-#     1     0  <defsyspath>
+#     2     0  <defsyspath>
 
 #*** Suffixes:
 #*** Transformations:
Index: src/usr.bin/make/unit-tests/opt-debug-graph3.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-graph3.exp:1.5 src/usr.bin/make/unit-tests/opt-debug-graph3.exp:1.6
--- src/usr.bin/make/unit-tests/opt-debug-graph3.exp:1.5	Sat Mar 26 14:34:07 2022
+++ src/usr.bin/make/unit-tests/opt-debug-graph3.exp	Tue Jan 24 00:24:02 2023
@@ -83,7 +83,7 @@ MFLAGS           =   -r -k -d g3
 #  refs  hits  directory
 #     1     0  <curdir>
 #     1     0  .
-#     1     0  <defsyspath>
+#     2     0  <defsyspath>
 
 #*** Suffixes:
 #*** Transformations:
Index: src/usr.bin/make/unit-tests/suff-transform-debug.exp
diff -u src/usr.bin/make/unit-tests/suff-transform-debug.exp:1.5 src/usr.bin/make/unit-tests/suff-transform-debug.exp:1.6
--- src/usr.bin/make/unit-tests/suff-transform-debug.exp:1.5	Sat Mar 26 14:34:07 2022
+++ src/usr.bin/make/unit-tests/suff-transform-debug.exp	Tue Jan 24 00:24:02 2023
@@ -39,7 +39,7 @@ MFLAGS           =   -r -k -d g1
 #  refs  hits  directory
 #     1     0  <curdir>
 #     1     0  .
-#     1     0  <defsyspath>
+#     2     0  <defsyspath>
 
 #*** Suffixes:
 # ".a" (num 1, ref 2)

Index: src/usr.bin/make/unit-tests/suff-main-several.exp
diff -u src/usr.bin/make/unit-tests/suff-main-several.exp:1.8 src/usr.bin/make/unit-tests/suff-main-several.exp:1.9
--- src/usr.bin/make/unit-tests/suff-main-several.exp:1.8	Sat Mar 26 14:34:07 2022
+++ src/usr.bin/make/unit-tests/suff-main-several.exp	Tue Jan 24 00:24:02 2023
@@ -113,7 +113,7 @@ MFLAGS           =   -r -k -d mps -d 0 -
 #  refs  hits  directory
 #     1     0  <curdir>
 #     1     0  .
-#     1     0  <defsyspath>
+#     2     0  <defsyspath>
 
 #*** Suffixes:
 # ".4" (num 1, ref 1)

Reply via email to