Module Name:    src
Committed By:   sjg
Date:           Wed Sep  4 15:38:26 UTC 2013

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

Log Message:
Add VAR_INTERNAL as a context for variables set by make itself,
which should not override those set by makefiles.
Currently MAKEFILE is the only variable affected.

Reviewed by: christos


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 src/usr.bin/make/main.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/make/make.h
cvs rdiff -u -r1.183 -r1.184 src/usr.bin/make/var.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.223 src/usr.bin/make/main.c:1.224
--- src/usr.bin/make/main.c:1.223	Sun Aug  4 16:48:15 2013
+++ src/usr.bin/make/main.c	Wed Sep  4 15:38:26 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.223 2013/08/04 16:48:15 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.224 2013/09/04 15:38:26 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.223 2013/08/04 16:48:15 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.224 2013/09/04 15:38:26 sjg 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.223 2013/08/04 16:48:15 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.224 2013/09/04 15:38:26 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1384,7 +1384,7 @@ ReadMakefile(const void *p, const void *
 
 	if (!strcmp(fname, "-")) {
 		Parse_File(NULL /*stdin*/, -1);
-		Var_Set("MAKEFILE", "", VAR_GLOBAL, 0);
+		Var_Set("MAKEFILE", "", VAR_INTERNAL, 0);
 	} else {
 		/* if we've chdir'd, rebuild the path name */
 		if (strcmp(curdir, objdir) && *fname != '/') {
@@ -1433,7 +1433,7 @@ ReadMakefile(const void *p, const void *
 		 */
 found:
 		if (!doing_depend)
-			Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0);
+			Var_Set("MAKEFILE", fname, VAR_INTERNAL, 0);
 		Parse_File(fname, fd);
 	}
 	free(path);

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.91 src/usr.bin/make/make.h:1.92
--- src/usr.bin/make/make.h:1.91	Tue Jun 18 20:06:09 2013
+++ src/usr.bin/make/make.h	Wed Sep  4 15:38:26 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.91 2013/06/18 20:06:09 sjg Exp $	*/
+/*	$NetBSD: make.h,v 1.92 2013/09/04 15:38:26 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -388,6 +388,10 @@ extern Boolean	varNoExportEnv;	/* TRUE i
 
 extern GNode    *DEFAULT;    	/* .DEFAULT rule */
 
+extern GNode	*VAR_INTERNAL;	/* Variables defined internally by make
+				 * which should not override those set by
+				 * makefiles.
+				 */
 extern GNode    *VAR_GLOBAL;   	/* Variables defined in a global context, e.g
 				 * in the Makefile itself */
 extern GNode    *VAR_CMD;    	/* Variables defined on the command line */

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.183 src/usr.bin/make/var.c:1.184
--- src/usr.bin/make/var.c:1.183	Tue Jul 16 20:00:56 2013
+++ src/usr.bin/make/var.c	Wed Sep  4 15:38:26 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.183 2013/07/16 20:00:56 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.184 2013/09/04 15:38:26 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.183 2013/07/16 20:00:56 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.184 2013/09/04 15:38:26 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.183 2013/07/16 20:00:56 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.184 2013/09/04 15:38:26 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -176,6 +176,7 @@ static char	varNoError[] = "";
  * The four contexts are searched in the reverse order from which they are
  * listed.
  */
+GNode          *VAR_INTERNAL; /* variables from make itself */
 GNode          *VAR_GLOBAL;   /* variables from the makefile */
 GNode          *VAR_CMD;      /* variables defined on the command-line */
 
@@ -408,6 +409,10 @@ VarFind(const char *name, GNode *ctxt, i
 	(ctxt != VAR_GLOBAL))
     {
 	var = Hash_FindEntry(&VAR_GLOBAL->context, name);
+	if ((var == NULL) && (ctxt != VAR_INTERNAL)) {
+	    /* VAR_INTERNAL is subordinate to VAR_GLOBAL */
+	    var = Hash_FindEntry(&VAR_INTERNAL->context, name);
+	}
     }
     if ((var == NULL) && (flags & FIND_ENV)) {
 	char *env;
@@ -429,6 +434,9 @@ VarFind(const char *name, GNode *ctxt, i
 		   (ctxt != VAR_GLOBAL))
 	{
 	    var = Hash_FindEntry(&VAR_GLOBAL->context, name);
+	    if ((var == NULL) && (ctxt != VAR_INTERNAL)) {
+		var = Hash_FindEntry(&VAR_INTERNAL->context, name);
+	    }
 	    if (var == NULL) {
 		return NULL;
 	    } else {
@@ -4137,6 +4145,7 @@ Var_GetHead(char *file)
 void
 Var_Init(void)
 {
+    VAR_INTERNAL = Targ_NewGN("Internal");
     VAR_GLOBAL = Targ_NewGN("Global");
     VAR_CMD = Targ_NewGN("Command");
 

Reply via email to