summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2003-09-14 12:31:33 +0000
committerru <ru@FreeBSD.org>2003-09-14 12:31:33 +0000
commit7ad89d9544793f73cd7d3d7d7f44562f89a49bcd (patch)
tree1cea0f2344264c01652889b9f3cbc0119cb30b33
parent50888524cab7543731fcbf46443bd1644d900523 (diff)
downloadFreeBSD-src-7ad89d9544793f73cd7d3d7d7f44562f89a49bcd.zip
FreeBSD-src-7ad89d9544793f73cd7d3d7d7f44562f89a49bcd.tar.gz
- Cut out the code that caches the "." directory out of Dir_Init()
into a separate function, Dir_InitDot(). - Postpone the current and object directories detection (and caching of the "." directory) until after all command line arguments are parsed. This makes the -C option DTRT. PR: bin/47149
-rw-r--r--usr.bin/make/dir.c29
-rw-r--r--usr.bin/make/dir.h1
-rw-r--r--usr.bin/make/main.c116
-rw-r--r--usr.bin/make/make.18
4 files changed, 87 insertions, 67 deletions
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c
index 49a3cf9..57d1687 100644
--- a/usr.bin/make/dir.c
+++ b/usr.bin/make/dir.c
@@ -205,7 +205,7 @@ static int DirPrintDir(void *, void *);
* none
*
* Side Effects:
- * some directories may be opened.
+ * none
*-----------------------------------------------------------------------
*/
void
@@ -214,15 +214,25 @@ Dir_Init (void)
dirSearchPath = Lst_Init (FALSE);
openDirectories = Lst_Init (FALSE);
Hash_InitTable(&mtimes, 0);
+}
- /*
- * Since the Path structure is placed on both openDirectories and
- * the path we give Dir_AddDir (which in this case is openDirectories),
- * we need to remove "." from openDirectories and what better time to
- * do it than when we have to fetch the thing anyway?
- */
+/*-
+ *-----------------------------------------------------------------------
+ * Dir_InitDot --
+ * initialize the "." directory
+ *
+ * Results:
+ * none
+ *
+ * Side Effects:
+ * some directories may be opened.
+ *-----------------------------------------------------------------------
+ */
+void
+Dir_InitDot (void)
+{
Dir_AddDir (openDirectories, ".");
- dot = (Path *) Lst_DeQueue (openDirectories);
+ dot = (Path *)Lst_Datum(Lst_Last(openDirectories));
if (dot == (Path *) NULL)
err(1, "cannot open current directory");
@@ -1031,7 +1041,8 @@ Dir_AddDir (Lst path, char *name)
}
(void) closedir (d);
(void)Lst_AtEnd (openDirectories, (void *)p);
- (void)Lst_AtEnd (path, (void *)p);
+ if (path != openDirectories)
+ (void)Lst_AtEnd (path, (void *)p);
}
DEBUGF(DIR, ("done\n"));
}
diff --git a/usr.bin/make/dir.h b/usr.bin/make/dir.h
index ec70643..549d531 100644
--- a/usr.bin/make/dir.h
+++ b/usr.bin/make/dir.h
@@ -55,6 +55,7 @@ typedef struct Path {
} Path;
void Dir_Init(void);
+void Dir_InitDot(void);
void Dir_End(void);
Boolean Dir_HasWildcards(char *);
void Dir_Expand(char *, Lst, Lst);
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 203b2b5..4b51011 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -485,17 +485,6 @@ main(int argc, char **argv)
}
}
#endif
- /*
- * Find where we are...
- * All this code is so that we know where we are when we start up
- * on a different machine with pmake.
- */
- curdir = cdpath;
- if (getcwd(curdir, MAXPATHLEN) == NULL)
- err(2, NULL);
-
- if (stat(curdir, &sa) == -1)
- err(2, "%s", curdir);
/*
* PC-98 kernel sets the `i386' string to the utsname.machine and
@@ -557,48 +546,6 @@ main(int argc, char **argv)
else
machine_cpu = "unknown";
}
-
- /*
- * The object directory location is determined using the
- * following order of preference:
- *
- * 1. MAKEOBJDIRPREFIX`cwd`
- * 2. MAKEOBJDIR
- * 3. _PATH_OBJDIR.${MACHINE}
- * 4. _PATH_OBJDIR
- * 5. _PATH_OBJDIRPREFIX`cwd`
- *
- * If one of the first two fails, use the current directory.
- * If the remaining three all fail, use the current directory.
- *
- * Once things are initted,
- * have to add the original directory to the search path,
- * and modify the paths for the Makefiles apropriately. The
- * current directory is also placed as a variable for make scripts.
- */
- if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) {
- if (!(path = getenv("MAKEOBJDIR"))) {
- path = _PATH_OBJDIR;
- pathp = _PATH_OBJDIRPREFIX;
- (void) snprintf(mdpath, MAXPATHLEN, "%s.%s",
- path, machine);
- if (!(objdir = chdir_verify_path(mdpath, obpath)))
- if (!(objdir=chdir_verify_path(path, obpath))) {
- (void) snprintf(mdpath, MAXPATHLEN,
- "%s%s", pathp, curdir);
- if (!(objdir=chdir_verify_path(mdpath,
- obpath)))
- objdir = curdir;
- }
- }
- else if (!(objdir = chdir_verify_path(path, obpath)))
- objdir = curdir;
- }
- else {
- (void) snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir);
- if (!(objdir = chdir_verify_path(mdpath, obpath)))
- objdir = curdir;
- }
create = Lst_Init(FALSE);
makefiles = Lst_Init(FALSE);
@@ -639,10 +586,6 @@ main(int argc, char **argv)
Var_Init(); /* As well as the lists of variables for
* parsing arguments */
str_init();
- if (objdir != curdir)
- Dir_AddDir(dirSearchPath, curdir);
- Var_Set(".CURDIR", curdir, VAR_GLOBAL);
- Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
/*
* Initialize various variables.
@@ -674,6 +617,65 @@ main(int argc, char **argv)
MainParseArgs(argc, argv);
/*
+ * Find where we are...
+ * All this code is so that we know where we are when we start up
+ * on a different machine with pmake.
+ */
+ curdir = cdpath;
+ if (getcwd(curdir, MAXPATHLEN) == NULL)
+ err(2, NULL);
+
+ if (stat(curdir, &sa) == -1)
+ err(2, "%s", curdir);
+
+ /*
+ * The object directory location is determined using the
+ * following order of preference:
+ *
+ * 1. MAKEOBJDIRPREFIX`cwd`
+ * 2. MAKEOBJDIR
+ * 3. _PATH_OBJDIR.${MACHINE}
+ * 4. _PATH_OBJDIR
+ * 5. _PATH_OBJDIRPREFIX`cwd`
+ *
+ * If one of the first two fails, use the current directory.
+ * If the remaining three all fail, use the current directory.
+ *
+ * Once things are initted,
+ * have to add the original directory to the search path,
+ * and modify the paths for the Makefiles apropriately. The
+ * current directory is also placed as a variable for make scripts.
+ */
+ if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) {
+ if (!(path = getenv("MAKEOBJDIR"))) {
+ path = _PATH_OBJDIR;
+ pathp = _PATH_OBJDIRPREFIX;
+ (void) snprintf(mdpath, MAXPATHLEN, "%s.%s",
+ path, machine);
+ if (!(objdir = chdir_verify_path(mdpath, obpath)))
+ if (!(objdir=chdir_verify_path(path, obpath))) {
+ (void) snprintf(mdpath, MAXPATHLEN,
+ "%s%s", pathp, curdir);
+ if (!(objdir=chdir_verify_path(mdpath,
+ obpath)))
+ objdir = curdir;
+ }
+ }
+ else if (!(objdir = chdir_verify_path(path, obpath)))
+ objdir = curdir;
+ }
+ else {
+ (void) snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir);
+ if (!(objdir = chdir_verify_path(mdpath, obpath)))
+ objdir = curdir;
+ }
+ Dir_InitDot(); /* Initialize the "." directory */
+ if (objdir != curdir)
+ Dir_AddDir(dirSearchPath, curdir);
+ Var_Set(".CURDIR", curdir, VAR_GLOBAL);
+ Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
+
+ /*
* Be compatible if user did not specify -j and did not explicitly
* turned compatibility on
*/
diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1
index 54defed..2523b0b 100644
--- a/usr.bin/make/make.1
+++ b/usr.bin/make/make.1
@@ -92,7 +92,13 @@ is used.
.It Fl C Ar directory
Change to
.Ar directory
-while running.
+before reading the makefiles or doing anything else.
+If multiple
+.Fl C
+options are specified, each is interpreted relative to the previous one:
+.Fl C Pa / Fl C Pa etc
+is equivalent to
+.Fl C Pa /etc .
.It Fl D Ar variable
Define
.Ar variable
OpenPOWER on IntegriCloud