diff options
-rw-r--r-- | usr.bin/make/dir.c | 29 | ||||
-rw-r--r-- | usr.bin/make/dir.h | 1 | ||||
-rw-r--r-- | usr.bin/make/main.c | 116 | ||||
-rw-r--r-- | usr.bin/make/make.1 | 8 |
4 files changed, 87 insertions, 67 deletions
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c index 49a3cf99e652..57d168799b27 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 ec706432a24b..549d531e6fc7 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 203b2b5fdcac..4b510117f1ef 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 54defed37dac..2523b0b763bb 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 |