summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-01-18 17:49:52 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-01-18 17:49:52 +0000
commitfd195763a509f35d44781e1d3a886e7d7b548b3d (patch)
treef6f07bda1ef9975c2a2bc0f6574350c97024c386
parent1d2bf3c06fb24ab6e3c6d60346f8d9e6359384fc (diff)
* add an extra argument to the dir lookup functions to say whether we
should look in the current directory. * refactor include files treatment to have a separate function to look for an include. * use both pieces to make sure system includes do not get looked up in the current directory unless everything else fails. This is != from the netbsd solution to the same problem, which stuffs `magic' entries into filepaths to say whether dot should be looked at first or last. feature requested by matthieu@. okay matthieu@
-rw-r--r--usr.bin/make/dir.c13
-rw-r--r--usr.bin/make/dir.h14
-rw-r--r--usr.bin/make/parse.c69
3 files changed, 59 insertions, 37 deletions
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c
index 7efba0a230a..9b0afd2ae26 100644
--- a/usr.bin/make/dir.c
+++ b/usr.bin/make/dir.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: dir.c,v 1.44 2006/01/20 23:10:19 espie Exp $ */
+/* $OpenBSD: dir.c,v 1.45 2007/01/18 17:49:51 espie Exp $ */
/* $NetBSD: dir.c,v 1.14 1997/03/29 16:51:26 christos Exp $ */
/*
@@ -634,7 +634,8 @@ Dir_Expandi(const char *word, const char *eword, Lst path, Lst expansions)
* that directory later on.
*/
char *
-Dir_FindFilei(const char *name, const char *ename, Lst path)
+Dir_FindFileComplexi(const char *name, const char *ename, Lst path,
+ bool checkCurdirFirst)
{
Path *p; /* current path member */
char *p1; /* pointer into p->name */
@@ -664,10 +665,10 @@ Dir_FindFilei(const char *name, const char *ename, Lst path)
if (DEBUG(DIR))
printf("Searching for %s...", name);
- /* No matter what, we always look for the file in the current directory
- * before anywhere else and we always return exactly what the caller
- * specified. */
- if ((!hasSlash || (cp - name == 2 && *name == '.')) &&
+ /* Unless checkCurDirFirst is false, we always look for
+ * the file in the current directory before anywhere else
+ * and we always return exactly what the caller specified. */
+ if (checkCurdirFirst && (!hasSlash || (cp - name == 2 && *name == '.')) &&
find_file_hashi(dot, cp, ename, hv) != NULL) {
if (DEBUG(DIR))
printf("in '.'\n");
diff --git a/usr.bin/make/dir.h b/usr.bin/make/dir.h
index d4eb5976eb8..58bfdf73ced 100644
--- a/usr.bin/make/dir.h
+++ b/usr.bin/make/dir.h
@@ -2,7 +2,7 @@
#define DIR_H
/* $OpenPackages$ */
-/* $OpenBSD: dir.h,v 1.16 2003/06/03 02:56:11 millert Exp $ */
+/* $OpenBSD: dir.h,v 1.17 2007/01/18 17:49:51 espie Exp $ */
/* $NetBSD: dir.h,v 1.4 1996/11/06 17:59:05 christos Exp $ */
/*
@@ -115,17 +115,21 @@ extern bool Dir_HasWildcardsi(const char *, const char *);
extern void Dir_Expandi(const char *, const char *, Lst, Lst);
#define Dir_Expand(n, l1, l2) Dir_Expandi(n, strchr(n, '\0'), l1, l2)
-/* fullname = Dir_FindFilei(name, end, path)
+/* fullname = Dir_FindFileComplexi(name, end, path, checkCurdirFirst)
* Searches for a file (name, end) on a given search path. If it exists,
* return the fullname of the file, otherwise NULL.
* The fullname is always a copy, and the caller is responsible for
* free()ing it.
- * Looking for a simple name always looks in the current directory.
+ * Looking for a simple name always looks in the current directory,
+ * unless checkCurdirFirst is false.
* For complex names, the current directory search only occurs for
* paths with dot in them.
*/
-extern char *Dir_FindFilei(const char *, const char *, Lst);
-#define Dir_FindFile(n, e) Dir_FindFilei(n, strchr(n, '\0'), e)
+extern char *Dir_FindFileComplexi(const char *, const char *, Lst, bool);
+#define Dir_FindFilei(n, e, p) Dir_FindFileComplexi(n, e, p, true)
+#define Dir_FindFileNoDoti(n, e, p) Dir_FindFileComplexi(n, e, p, false)
+#define Dir_FindFile(n, p) Dir_FindFilei(n, strchr(n, '\0'), p)
+#define Dir_FindFileNoDot(n, p) Dir_FindFileNoDoti(n, strchr(n, '\0'), p)
/* stamp = Dir_MTime(gn);
* Return the modification time of node gn, searching along
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index 8b3be5f39b9..5d6aacb9dd2 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: parse.c,v 1.69 2004/04/07 13:11:36 espie Exp $ */
+/* $OpenBSD: parse.c,v 1.70 2007/01/18 17:49:51 espie Exp $ */
/* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */
/*
@@ -220,6 +220,7 @@ static void ParseLookupIncludeFile(char *, char *, bool, bool);
static void ParseFinishDependency(void);
static bool ParseIsCond(Buffer, Buffer, char *);
static char *strip_comments(Buffer, const char *);
+static char *find_include(const char *, bool);
static void ParseDoCommands(const char *);
@@ -1240,26 +1241,18 @@ ParseConditionalInclude(char *file)/* file specification */
ParseLookupIncludeFile(file, cp, true, false);
}
-/* Common part to lookup and read an include file. */
-static void
-ParseLookupIncludeFile(char *spec, char *endSpec, bool isSystem,
- bool errIfNotFound)
+/* helper function for ParseLookupIncludeFile */
+static char *
+find_include(const char *file, bool isSystem)
{
- char *file;
char *fullname;
- char endc;
-
- /* Substitute for any variables in the file name before trying to
- * find the thing. */
- endc = *endSpec;
- *endSpec = '\0';
- file = Var_Subst(spec, NULL, false);
- *endSpec = endc;
-
- /* Now that we know the file name and its search path, we attempt to
- * find the durn thing. NULL indicates the file still hasn't been
- * found. */
- fullname = NULL;
+
+ /* Look up system files on the system path first */
+ if (isSystem) {
+ fullname = Dir_FindFileNoDot(file, sysIncPath);
+ if (fullname)
+ return fullname;
+ }
/* Handle non-system non-absolute files... */
if (!isSystem && file[0] != '/') {
@@ -1281,24 +1274,48 @@ ParseLookupIncludeFile(char *spec, char *endSpec, bool isSystem,
if (fullname == NULL)
fullname = Dir_FindFile(newName, dirSearchPath);
free(newName);
+ if (fullname)
+ return fullname;
}
}
/* Now look first on the -I search path, then on the .PATH
* search path, if not found in a -I directory.
* XXX: Suffix specific? */
- if (fullname == NULL)
- fullname = Dir_FindFile(file, parseIncPath);
- if (fullname == NULL)
- fullname = Dir_FindFile(file, dirSearchPath);
+ fullname = Dir_FindFile(file, parseIncPath);
+ if (fullname)
+ return fullname;
+ fullname = Dir_FindFile(file, dirSearchPath);
+ if (fullname)
+ return fullname;
/* Still haven't found the makefile. Look for it on the system
* path as a last resort. */
- if (fullname == NULL)
- fullname = Dir_FindFile(file, sysIncPath);
+ if (isSystem)
+ return NULL;
+ else
+ return Dir_FindFile(file, sysIncPath);
+}
+
+/* Common part to lookup and read an include file. */
+static void
+ParseLookupIncludeFile(char *spec, char *endSpec, bool isSystem,
+ bool errIfNotFound)
+{
+ char *file;
+ char *fullname;
+ char endc;
+
+ /* Substitute for any variables in the file name before trying to
+ * find the thing. */
+ endc = *endSpec;
+ *endSpec = '\0';
+ file = Var_Subst(spec, NULL, false);
+ *endSpec = endc;
+ fullname = find_include(file, isSystem);
if (fullname == NULL && errIfNotFound)
- Parse_Error(PARSE_FATAL, "Could not find %s", file);
+ Parse_Error(PARSE_FATAL, "Could not find %s", file);
free(file);