Module Name:    src
Committed By:   sjg
Date:           Sun May 19 20:09:40 UTC 2024

Modified Files:
        src/usr.bin/make: dir.c dir.h parse.c

Log Message:
make: use separate function to include makefiles.

Have Dir_FindFile and Dir_FindInclude call FindFile with a
bool flag to indicate whether .CURDIR should be be searched at all.


To generate a diff of this commit:
cvs rdiff -u -r1.287 -r1.288 src/usr.bin/make/dir.c
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/make/dir.h
cvs rdiff -u -r1.722 -r1.723 src/usr.bin/make/parse.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/dir.c
diff -u src/usr.bin/make/dir.c:1.287 src/usr.bin/make/dir.c:1.288
--- src/usr.bin/make/dir.c:1.287	Sun May 19 17:55:54 2024
+++ src/usr.bin/make/dir.c	Sun May 19 20:09:40 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.287 2024/05/19 17:55:54 sjg Exp $	*/
+/*	$NetBSD: dir.c,v 1.288 2024/05/19 20:09:40 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -132,7 +132,7 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.287 2024/05/19 17:55:54 sjg Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.288 2024/05/19 20:09:40 sjg Exp $");
 
 /*
  * A search path is a list of CachedDir structures. A CachedDir has in it the
@@ -1144,15 +1144,16 @@ found:
  * Input:
  *	name		the file to find
  *	path		the directories to search, or NULL
+ *	isinclude	if true, do not search .CURDIR at all
  *
  * Results:
  *	The freshly allocated path to the file, or NULL.
  */
-char *
-Dir_FindFile(const char *name, SearchPath *path)
+static char *
+FindFile(const char *name, SearchPath *path, bool isinclude)
 {
 	char *file;		/* the current filename to check */
-	bool seenDotLast = false; /* true if we should search dot last */
+	bool seenDotLast = isinclude; /* true if we should search dot last */
 	struct cached_stat cst;
 	const char *trailing_dot = ".";
 	const char *base = str_basename(name);
@@ -1165,9 +1166,7 @@ Dir_FindFile(const char *name, SearchPat
 		return NULL;
 	}
 
-	if (path == sysIncPath || path == defSysIncPath)
-		seenDotLast = true;
-	else if (path->dirs.first != NULL) {
+	if (!seenDotLast && path->dirs.first != NULL) {
 		CachedDir *dir = path->dirs.first->datum;
 		if (dir == dotLast) {
 			seenDotLast = true;
@@ -1207,7 +1206,8 @@ Dir_FindFile(const char *name, SearchPat
 				return file;
 		}
 
-		if (seenDotLast && (file = DirFindDot(name, base)) != NULL)
+		if (!isinclude && seenDotLast
+		    && (file = DirFindDot(name, base)) != NULL)
 			return file;
 	}
 
@@ -1248,6 +1248,38 @@ Dir_FindFile(const char *name, SearchPat
 	return NULL;
 }
 
+/*
+ * Find the file with the given name along the given search path.
+ *
+ * Input:
+ *	name		the file to find
+ *	path		the directories to search, or NULL
+ *
+ * Results:
+ *	The freshly allocated path to the file, or NULL.
+ */
+char *
+Dir_FindFile(const char *name, SearchPath *path)
+{
+	return FindFile(name, path, false);
+}
+
+/*
+ * Find the include file with the given name along the given search path.
+ *
+ * Input:
+ *	name		the file to find
+ *	path		the directories to search, or NULL
+ *
+ * Results:
+ *	The freshly allocated path to the file, or NULL.
+ */
+char *
+Dir_FindInclude(const char *name, SearchPath *path)
+{
+	return FindFile(name, path, true);
+}
+
 
 /*
  * Search for 'needle' starting at the directory 'here' and then working our

Index: src/usr.bin/make/dir.h
diff -u src/usr.bin/make/dir.h:1.47 src/usr.bin/make/dir.h:1.48
--- src/usr.bin/make/dir.h:1.47	Tue Jan 24 00:24:02 2023
+++ src/usr.bin/make/dir.h	Sun May 19 20:09:40 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.h,v 1.47 2023/01/24 00:24:02 sjg Exp $	*/
+/*	$NetBSD: dir.h,v 1.48 2024/05/19 20:09:40 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -86,6 +86,7 @@ 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;
+char *Dir_FindInclude(const char *, SearchPath *) MAKE_ATTR_USE;
 char *Dir_FindHereOrAbove(const char *, const char *) MAKE_ATTR_USE;
 void Dir_UpdateMTime(GNode *, bool);
 CachedDir *SearchPath_Add(SearchPath *, const char *);

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.722 src/usr.bin/make/parse.c:1.723
--- src/usr.bin/make/parse.c:1.722	Sat Apr 27 17:33:46 2024
+++ src/usr.bin/make/parse.c	Sun May 19 20:09:40 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.722 2024/04/27 17:33:46 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.723 2024/05/19 20:09:40 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.722 2024/04/27 17:33:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.723 2024/05/19 20:09:40 sjg Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -1253,7 +1253,7 @@ IncludeFile(const char *file, bool isSys
 	if (fullname == NULL) {
 		SearchPath *path = Lst_IsEmpty(&sysIncPath->dirs)
 		    ? defSysIncPath : sysIncPath;
-		fullname = Dir_FindFile(file, path);
+		fullname = Dir_FindInclude(file, path);
 	}
 
 	if (fullname == NULL) {

Reply via email to