Module Name:    src
Committed By:   sjg
Date:           Tue Jul 16 20:00:56 UTC 2013

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

Log Message:
When a var is set in the CMD context, it prevents the same name
being set in GLOBAL context.  We should also delete any such
variable in GLOBAL context, else make -V will show the wrong value.


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 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/var.c
diff -u src/usr.bin/make/var.c:1.182 src/usr.bin/make/var.c:1.183
--- src/usr.bin/make/var.c:1.182	Tue Jul 16 14:00:53 2013
+++ src/usr.bin/make/var.c	Tue Jul 16 20:00:56 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.182 2013/07/16 14:00:53 christos Exp $	*/
+/*	$NetBSD: var.c,v 1.183 2013/07/16 20:00:56 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.182 2013/07/16 14:00:53 christos Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.183 2013/07/16 20:00:56 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.182 2013/07/16 14:00:53 christos Exp $");
+__RCSID("$NetBSD: var.c,v 1.183 2013/07/16 20:00:56 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -929,6 +929,14 @@ Var_Set(const char *name, const char *va
     }
     v = VarFind(name, ctxt, 0);
     if (v == NULL) {
+	if (ctxt == VAR_CMD && (flags & VAR_NO_EXPORT) == 0) {
+	    /*
+	     * This var would normally prevent the same name being added
+	     * to VAR_GLOBAL, so delete it from there if needed.
+	     * Otherwise -V name may show the wrong value.
+	     */
+	    Var_Delete(name, VAR_GLOBAL);
+	}
 	VarAdd(name, val, ctxt);
     } else {
 	Buf_Empty(&v->val);

Reply via email to