=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/make/main.c,v retrieving revision 1.52 retrieving revision 1.53 diff -c -r1.52 -r1.53 *** src/usr.bin/make/main.c 2001/06/03 16:33:48 1.52 --- src/usr.bin/make/main.c 2001/06/05 11:59:11 1.53 *************** *** 1,5 **** /* $OpenPackages$ */ ! /* $OpenBSD: main.c,v 1.52 2001/06/03 16:33:48 espie Exp $ */ /* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */ /* --- 1,5 ---- /* $OpenPackages$ */ ! /* $OpenBSD: main.c,v 1.53 2001/06/05 11:59:11 espie Exp $ */ /* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */ /* *************** *** 70,75 **** --- 70,83 ---- #include "memory.h" #include "make.h" + #ifndef PATH_MAX + # ifdef MAXPATHLEN + # define PATH_MAX (MAXPATHLEN+1) + # else + # define PATH_MAX 1024 + # endif + #endif + #ifndef DEFMAXLOCAL #define DEFMAXLOCAL DEFMAXJOBS #endif /* DEFMAXLOCAL */ *************** *** 99,105 **** bool checkEnvFirst; /* -e flag */ static void MainParseArgs(int, char **); ! static char * chdir_verify_path(char *, char *); static int ReadMakefile(void *, void *); static void add_dirpath(Lst, const char *); static void usage(void); --- 107,113 ---- bool checkEnvFirst; /* -e flag */ static void MainParseArgs(int, char **); ! static char * chdir_verify_path(char *); static int ReadMakefile(void *, void *); static void add_dirpath(Lst, const char *); static void usage(void); *************** *** 398,406 **** } char * ! chdir_verify_path(path, obpath) char *path; - char *obpath; { struct stat sb; --- 406,413 ---- } char * ! chdir_verify_path(path) char *path; { struct stat sb; *************** *** 410,421 **** path, strerror(errno)); return NULL; } else { ! if (path[0] != '/') { ! (void)snprintf(obpath, MAXPATHLEN, "%s/%s", curdir, path); ! return obpath; ! } else ! return path; } } --- 417,426 ---- path, strerror(errno)); return NULL; } else { ! if (path[0] != '/') ! return Str_concat(curdir, path, '/'); else ! return estrdup(path); } } *************** *** 470,478 **** bool outOfDate = true; /* false if all targets up to date */ struct stat sb, sa; char *p, *path, *pathp, *pwd; ! char mdpath[MAXPATHLEN + 1]; ! char obpath[MAXPATHLEN + 1]; ! char cdpath[MAXPATHLEN + 1]; char *machine = getenv("MACHINE"); char *machine_arch = getenv("MACHINE_ARCH"); const char *syspath = _PATH_DEFSYSPATH; --- 475,481 ---- bool outOfDate = true; /* false if all targets up to date */ struct stat sb, sa; char *p, *path, *pathp, *pwd; ! char *mdpath; char *machine = getenv("MACHINE"); char *machine_arch = getenv("MACHINE_ARCH"); const char *syspath = _PATH_DEFSYSPATH; *************** *** 495,502 **** * 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) { (void)fprintf(stderr, "make: %s.\n", strerror(errno)); exit(2); } --- 498,504 ---- * All this code is so that we know where we are when we start up * on a different machine with pmake. */ ! if ((curdir = dogetcwd()) == NULL) { (void)fprintf(stderr, "make: %s.\n", strerror(errno)); exit(2); } *************** *** 509,516 **** if ((pwd = getenv("PWD")) != NULL) { if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino && ! sa.st_dev == sb.st_dev && strlen(pwd) <= MAXPATHLEN) ! (void)strcpy(curdir, pwd); } /* --- 511,520 ---- if ((pwd = getenv("PWD")) != NULL) { if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino && ! sa.st_dev == sb.st_dev) { ! free(curdir); ! curdir = estrdup(pwd); ! } } /* *************** *** 556,584 **** * 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; } esetenv("PWD", objdir); unsetenv("CDPATH"); --- 560,588 ---- * and modify the paths for the Makefiles apropriately. The * current directory is also placed as a variable for make scripts. */ + mdpath = NULL; if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) { if (!(path = getenv("MAKEOBJDIR"))) { path = _PATH_OBJDIR; pathp = _PATH_OBJDIRPREFIX; ! mdpath = Str_concat(path, machine, '.'); ! if (!(objdir = chdir_verify_path(mdpath))) ! if (!(objdir=chdir_verify_path(path))) { ! free(mdpath); ! mdpath = Str_concat(pathp, curdir, 0); ! if (!(objdir=chdir_verify_path(mdpath))) objdir = curdir; } } ! else if (!(objdir = chdir_verify_path(path))) objdir = curdir; } else { ! mdpath = Str_concat(pathp, curdir, 0); ! if (!(objdir = chdir_verify_path(mdpath))) objdir = curdir; } + free(mdpath); esetenv("PWD", objdir); unsetenv("CDPATH"); *************** *** 781,786 **** --- 785,795 ---- if (DEBUG(GRAPH2)) Targ_PrintGraph(2); + #ifdef CLEANUP + if (objdir != curdir) + free(objdir); + free(curdir); + #endif if (queryFlag && outOfDate) return 1; else *************** *** 804,810 **** { char *fname = p; /* makefile to read */ FILE *stream; ! char *name, path[MAXPATHLEN + 1]; if (!strcmp(fname, "-")) { Var_Set("MAKEFILE", "", VAR_GLOBAL); --- 813,819 ---- { char *fname = p; /* makefile to read */ FILE *stream; ! char *name; if (!strcmp(fname, "-")) { Var_Set("MAKEFILE", "", VAR_GLOBAL); *************** *** 814,824 **** goto found; /* if we've chdir'd, rebuild the path name */ if (curdir != objdir && *fname != '/') { ! (void)snprintf(path, sizeof path, "%s/%s", curdir, ! fname); ! if ((stream = fopen(path, "r")) != NULL) { ! fname = estrdup(path); ! goto found; } } /* look in -I and system include directories. */ --- 823,836 ---- goto found; /* if we've chdir'd, rebuild the path name */ if (curdir != objdir && *fname != '/') { ! char *path; ! ! path = Str_concat(curdir, fname, '/'); ! if ((stream = fopen(path, "r")) == NULL) ! free(path); ! else { ! fname = path; ! goto found; } } /* look in -I and system include directories. */