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.
This commit is contained in:
sjg 2024-05-19 20:09:40 +00:00
parent 8853c17bba
commit c86b32d1f8
3 changed files with 46 additions and 13 deletions

View File

@ -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, SearchPath *path)
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, SearchPath *path)
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, SearchPath *path)
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

View File

@ -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 *);

View File

@ -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 isSystem, bool depinc, bool silent)
if (fullname == NULL) {
SearchPath *path = Lst_IsEmpty(&sysIncPath->dirs)
? defSysIncPath : sysIncPath;
fullname = Dir_FindFile(file, path);
fullname = Dir_FindInclude(file, path);
}
if (fullname == NULL) {