version 1.52, 2001/06/03 16:33:48 |
version 1.53, 2001/06/05 11:59:11 |
|
|
#include "memory.h" |
#include "memory.h" |
#include "make.h" |
#include "make.h" |
|
|
|
#ifndef PATH_MAX |
|
# ifdef MAXPATHLEN |
|
# define PATH_MAX (MAXPATHLEN+1) |
|
# else |
|
# define PATH_MAX 1024 |
|
# endif |
|
#endif |
|
|
#ifndef DEFMAXLOCAL |
#ifndef DEFMAXLOCAL |
#define DEFMAXLOCAL DEFMAXJOBS |
#define DEFMAXLOCAL DEFMAXJOBS |
#endif /* DEFMAXLOCAL */ |
#endif /* DEFMAXLOCAL */ |
|
|
bool checkEnvFirst; /* -e flag */ |
bool checkEnvFirst; /* -e flag */ |
|
|
static void MainParseArgs(int, char **); |
static void MainParseArgs(int, char **); |
static char * chdir_verify_path(char *, char *); |
static char * chdir_verify_path(char *); |
static int ReadMakefile(void *, void *); |
static int ReadMakefile(void *, void *); |
static void add_dirpath(Lst, const char *); |
static void add_dirpath(Lst, const char *); |
static void usage(void); |
static void usage(void); |
|
|
} |
} |
|
|
char * |
char * |
chdir_verify_path(path, obpath) |
chdir_verify_path(path) |
char *path; |
char *path; |
char *obpath; |
|
{ |
{ |
struct stat sb; |
struct stat sb; |
|
|
|
|
path, strerror(errno)); |
path, strerror(errno)); |
return NULL; |
return NULL; |
} else { |
} else { |
if (path[0] != '/') { |
if (path[0] != '/') |
(void)snprintf(obpath, MAXPATHLEN, "%s/%s", curdir, path); |
return Str_concat(curdir, path, '/'); |
return obpath; |
|
} |
|
else |
else |
return path; |
return estrdup(path); |
} |
} |
} |
} |
|
|
|
|
bool outOfDate = true; /* false if all targets up to date */ |
bool outOfDate = true; /* false if all targets up to date */ |
struct stat sb, sa; |
struct stat sb, sa; |
char *p, *path, *pathp, *pwd; |
char *p, *path, *pathp, *pwd; |
char mdpath[MAXPATHLEN + 1]; |
char *mdpath; |
char obpath[MAXPATHLEN + 1]; |
|
char cdpath[MAXPATHLEN + 1]; |
|
char *machine = getenv("MACHINE"); |
char *machine = getenv("MACHINE"); |
char *machine_arch = getenv("MACHINE_ARCH"); |
char *machine_arch = getenv("MACHINE_ARCH"); |
const char *syspath = _PATH_DEFSYSPATH; |
const char *syspath = _PATH_DEFSYSPATH; |
|
|
* All this code is so that we know where we are when we start up |
* All this code is so that we know where we are when we start up |
* on a different machine with pmake. |
* on a different machine with pmake. |
*/ |
*/ |
curdir = cdpath; |
if ((curdir = dogetcwd()) == NULL) { |
if (getcwd(curdir, MAXPATHLEN) == NULL) { |
|
(void)fprintf(stderr, "make: %s.\n", strerror(errno)); |
(void)fprintf(stderr, "make: %s.\n", strerror(errno)); |
exit(2); |
exit(2); |
} |
} |
|
|
|
|
if ((pwd = getenv("PWD")) != NULL) { |
if ((pwd = getenv("PWD")) != NULL) { |
if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino && |
if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino && |
sa.st_dev == sb.st_dev && strlen(pwd) <= MAXPATHLEN) |
sa.st_dev == sb.st_dev) { |
(void)strcpy(curdir, pwd); |
free(curdir); |
|
curdir = estrdup(pwd); |
|
} |
} |
} |
|
|
/* |
/* |
|
|
* and modify the paths for the Makefiles apropriately. The |
* and modify the paths for the Makefiles apropriately. The |
* current directory is also placed as a variable for make scripts. |
* current directory is also placed as a variable for make scripts. |
*/ |
*/ |
|
mdpath = NULL; |
if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) { |
if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) { |
if (!(path = getenv("MAKEOBJDIR"))) { |
if (!(path = getenv("MAKEOBJDIR"))) { |
path = _PATH_OBJDIR; |
path = _PATH_OBJDIR; |
pathp = _PATH_OBJDIRPREFIX; |
pathp = _PATH_OBJDIRPREFIX; |
(void)snprintf(mdpath, MAXPATHLEN, "%s.%s", |
mdpath = Str_concat(path, machine, '.'); |
path, machine); |
if (!(objdir = chdir_verify_path(mdpath))) |
if (!(objdir = chdir_verify_path(mdpath, obpath))) |
if (!(objdir=chdir_verify_path(path))) { |
if (!(objdir=chdir_verify_path(path, obpath))) { |
free(mdpath); |
(void)snprintf(mdpath, MAXPATHLEN, |
mdpath = Str_concat(pathp, curdir, 0); |
"%s%s", pathp, curdir); |
if (!(objdir=chdir_verify_path(mdpath))) |
if (!(objdir=chdir_verify_path(mdpath, |
|
obpath))) |
|
objdir = curdir; |
objdir = curdir; |
} |
} |
} |
} |
else if (!(objdir = chdir_verify_path(path, obpath))) |
else if (!(objdir = chdir_verify_path(path))) |
objdir = curdir; |
objdir = curdir; |
} |
} |
else { |
else { |
(void)snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir); |
mdpath = Str_concat(pathp, curdir, 0); |
if (!(objdir = chdir_verify_path(mdpath, obpath))) |
if (!(objdir = chdir_verify_path(mdpath))) |
objdir = curdir; |
objdir = curdir; |
} |
} |
|
free(mdpath); |
|
|
esetenv("PWD", objdir); |
esetenv("PWD", objdir); |
unsetenv("CDPATH"); |
unsetenv("CDPATH"); |
|
|
if (DEBUG(GRAPH2)) |
if (DEBUG(GRAPH2)) |
Targ_PrintGraph(2); |
Targ_PrintGraph(2); |
|
|
|
#ifdef CLEANUP |
|
if (objdir != curdir) |
|
free(objdir); |
|
free(curdir); |
|
#endif |
if (queryFlag && outOfDate) |
if (queryFlag && outOfDate) |
return 1; |
return 1; |
else |
else |
|
|
{ |
{ |
char *fname = p; /* makefile to read */ |
char *fname = p; /* makefile to read */ |
FILE *stream; |
FILE *stream; |
char *name, path[MAXPATHLEN + 1]; |
char *name; |
|
|
if (!strcmp(fname, "-")) { |
if (!strcmp(fname, "-")) { |
Var_Set("MAKEFILE", "", VAR_GLOBAL); |
Var_Set("MAKEFILE", "", VAR_GLOBAL); |
|
|
goto found; |
goto found; |
/* if we've chdir'd, rebuild the path name */ |
/* if we've chdir'd, rebuild the path name */ |
if (curdir != objdir && *fname != '/') { |
if (curdir != objdir && *fname != '/') { |
(void)snprintf(path, sizeof path, "%s/%s", curdir, |
char *path; |
fname); |
|
if ((stream = fopen(path, "r")) != NULL) { |
path = Str_concat(curdir, fname, '/'); |
fname = estrdup(path); |
if ((stream = fopen(path, "r")) == NULL) |
goto found; |
free(path); |
|
else { |
|
fname = path; |
|
goto found; |
} |
} |
} |
} |
/* look in -I and system include directories. */ |
/* look in -I and system include directories. */ |