- 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
This commit is contained in:
Ruslan Ermilov 2003-09-14 12:31:33 +00:00
parent 62c45ef40a
commit faf94801fd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=120053
4 changed files with 111 additions and 91 deletions

View File

@ -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"));
}

View File

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

View File

@ -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,7 +546,88 @@ main(int argc, char **argv)
else
machine_cpu = "unknown";
}
create = Lst_Init(FALSE);
makefiles = Lst_Init(FALSE);
envFirstVars = Lst_Init(FALSE);
expandVars = TRUE;
variables = Lst_Init(FALSE);
beSilent = FALSE; /* Print commands as executed */
ignoreErrors = FALSE; /* Pay attention to non-zero returns */
noExecute = FALSE; /* Execute all commands */
keepgoing = FALSE; /* Stop on error */
allPrecious = FALSE; /* Remove targets when interrupted */
queryFlag = FALSE; /* This is not just a check-run */
noBuiltins = FALSE; /* Read the built-in rules */
touchFlag = FALSE; /* Actually update targets */
usePipes = TRUE; /* Catch child output in pipes */
debug = 0; /* No debug verbosity, please. */
jobsRunning = FALSE;
maxLocal = DEFMAXLOCAL; /* Set default local max concurrency */
#ifdef REMOTE
maxJobs = DEFMAXJOBS; /* Set default max concurrency */
#else
maxJobs = maxLocal;
#endif
forceJobs = FALSE; /* No -j flag */
compatMake = FALSE; /* No compat mode */
/*
* Initialize the parsing, directory and variable modules to prepare
* for the reading of inclusion paths and variable settings on the
* command line
*/
Dir_Init(); /* Initialize directory structures so -I flags
* can be processed correctly */
Parse_Init(); /* Need to initialize the paths of #include
* directories */
Var_Init(); /* As well as the lists of variables for
* parsing arguments */
str_init();
/*
* Initialize various variables.
* MAKE also gets this name, for compatibility
* .MAKEFLAGS gets set to the empty string just in case.
* MFLAGS also gets initialized empty, for compatibility.
*/
Var_Set("MAKE", argv[0], VAR_GLOBAL);
Var_Set(MAKEFLAGS, "", VAR_GLOBAL);
Var_Set("MFLAGS", "", VAR_GLOBAL);
Var_Set("MACHINE", machine, VAR_GLOBAL);
Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL);
Var_Set("MACHINE_CPU", machine_cpu, VAR_GLOBAL);
#ifdef MAKE_VERSION
Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL);
#endif
/*
* First snag any flags out of the MAKE environment variable.
* (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
* in a different format).
*/
#ifdef POSIX
Main_ParseArgLine(getenv("MAKEFLAGS"));
#else
Main_ParseArgLine(getenv("MAKE"));
#endif
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:
@ -599,80 +669,12 @@ main(int argc, char **argv)
if (!(objdir = chdir_verify_path(mdpath, obpath)))
objdir = curdir;
}
create = Lst_Init(FALSE);
makefiles = Lst_Init(FALSE);
envFirstVars = Lst_Init(FALSE);
expandVars = TRUE;
variables = Lst_Init(FALSE);
beSilent = FALSE; /* Print commands as executed */
ignoreErrors = FALSE; /* Pay attention to non-zero returns */
noExecute = FALSE; /* Execute all commands */
keepgoing = FALSE; /* Stop on error */
allPrecious = FALSE; /* Remove targets when interrupted */
queryFlag = FALSE; /* This is not just a check-run */
noBuiltins = FALSE; /* Read the built-in rules */
touchFlag = FALSE; /* Actually update targets */
usePipes = TRUE; /* Catch child output in pipes */
debug = 0; /* No debug verbosity, please. */
jobsRunning = FALSE;
maxLocal = DEFMAXLOCAL; /* Set default local max concurrency */
#ifdef REMOTE
maxJobs = DEFMAXJOBS; /* Set default max concurrency */
#else
maxJobs = maxLocal;
#endif
forceJobs = FALSE; /* No -j flag */
compatMake = FALSE; /* No compat mode */
/*
* Initialize the parsing, directory and variable modules to prepare
* for the reading of inclusion paths and variable settings on the
* command line
*/
Dir_Init(); /* Initialize directory structures so -I flags
* can be processed correctly */
Parse_Init(); /* Need to initialize the paths of #include
* directories */
Var_Init(); /* As well as the lists of variables for
* parsing arguments */
str_init();
Dir_InitDot(); /* Initialize the "." directory */
if (objdir != curdir)
Dir_AddDir(dirSearchPath, curdir);
Var_Set(".CURDIR", curdir, VAR_GLOBAL);
Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
/*
* Initialize various variables.
* MAKE also gets this name, for compatibility
* .MAKEFLAGS gets set to the empty string just in case.
* MFLAGS also gets initialized empty, for compatibility.
*/
Var_Set("MAKE", argv[0], VAR_GLOBAL);
Var_Set(MAKEFLAGS, "", VAR_GLOBAL);
Var_Set("MFLAGS", "", VAR_GLOBAL);
Var_Set("MACHINE", machine, VAR_GLOBAL);
Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL);
Var_Set("MACHINE_CPU", machine_cpu, VAR_GLOBAL);
#ifdef MAKE_VERSION
Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL);
#endif
/*
* First snag any flags out of the MAKE environment variable.
* (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
* in a different format).
*/
#ifdef POSIX
Main_ParseArgLine(getenv("MAKEFLAGS"));
#else
Main_ParseArgLine(getenv("MAKE"));
#endif
MainParseArgs(argc, argv);
/*
* Be compatible if user did not specify -j and did not explicitly
* turned compatibility on

View File

@ -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