Module Name:    src
Committed By:   pooka
Date:           Fri Feb  7 17:23:35 UTC 2014

Modified Files:
        src/usr.bin/make: main.c

Log Message:
Use Var_Value() instead of getenv() to obtain MAKEOBJDIR{,PREFIX}.

Fixes "make -X MAKEOBJDIR=foo".  Purely uncoincidentally, build.sh
creates the nbmake wrapper with MAKEFLAGS -X on FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/make/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.225 src/usr.bin/make/main.c:1.226
--- src/usr.bin/make/main.c:1.225	Sat Sep 14 15:09:34 2013
+++ src/usr.bin/make/main.c	Fri Feb  7 17:23:35 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.225 2013/09/14 15:09:34 matt Exp $	*/
+/*	$NetBSD: main.c,v 1.226 2014/02/07 17:23:35 pooka Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.225 2013/09/14 15:09:34 matt Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.226 2014/02/07 17:23:35 pooka Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.225 2013/09/14 15:09:34 matt Exp $");
+__RCSID("$NetBSD: main.c,v 1.226 2014/02/07 17:23:35 pooka Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1067,11 +1067,12 @@ main(int argc, char **argv)
 	 */
 #ifndef NO_PWD_OVERRIDE
 	if (!ignorePWD) {
-		char *pwd;
+		char *pwd, *ptmp1 = NULL, *ptmp2 = NULL;
 
 		if ((pwd = getenv("PWD")) != NULL &&
-		    getenv("MAKEOBJDIRPREFIX") == NULL) {
-			const char *makeobjdir = getenv("MAKEOBJDIR");
+		    Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &ptmp1) == NULL) {
+			const char *makeobjdir = Var_Value("MAKEOBJDIR",
+			    VAR_CMD, &ptmp2);
 
 			if (makeobjdir == NULL || !strchr(makeobjdir, '$')) {
 				if (stat(pwd, &sb) == 0 &&
@@ -1080,6 +1081,8 @@ main(int argc, char **argv)
 					(void)strncpy(curdir, pwd, MAXPATHLEN);
 			}
 		}
+		free(ptmp1);
+		free(ptmp2);
 	}
 #endif
 	Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0);
@@ -1096,11 +1099,13 @@ main(int argc, char **argv)
 	Dir_Init(curdir);
 	(void)Main_SetObjdir(curdir);
 
-	if ((path = getenv("MAKEOBJDIRPREFIX")) != NULL) {
+	if ((path = Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &p1)) != NULL) {
 		(void)snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir);
 		(void)Main_SetObjdir(mdpath);
-	} else if ((path = getenv("MAKEOBJDIR")) != NULL) {
+		free(p1);
+	} else if ((path = Var_Value("MAKEOBJDIR", VAR_CMD, &p1)) != NULL) {
 		(void)Main_SetObjdir(path);
+		free(p1);
 	} else {
 		(void)snprintf(mdpath, MAXPATHLEN, "%s.%s", _PATH_OBJDIR, machine);
 		if (!Main_SetObjdir(mdpath) && !Main_SetObjdir(_PATH_OBJDIR)) {

Reply via email to