summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorsjg <sjg@NetBSD.org>2001-06-10 02:31:00 +0000
committersjg <sjg@NetBSD.org>2001-06-10 02:31:00 +0000
commitfc0df160d89195b37f5832075656d06bd0a024af (patch)
tree9fbca62fb8f65f8a8656ebf184fa9ec5e84b096e /usr.bin/make
parenta2b115fa4cb9b51c7e0f8a242a9bd644ff6eabe6 (diff)
Simplify the exporting of VAR_CMD's via MAKEFLAGS.
We now just list the names of such variables in .MAKEOVERRIDES. When we come to export MAKEFLAGS we quote the value of each exported variable using :Q, using: ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@} The :O:u suppresses duplicate names. Also modifed Parse_DoVar to re-export MAKEFLAGS whenever .MAKEOVERRIDES is assigned to so .MAKEOVERRIDES+= PATH will export PATH=${PATH:Q} to the environment, while .MAKEOVERRIDES= will disable export of VAR_CMD's.
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/main.c11
-rw-r--r--usr.bin/make/make.114
-rw-r--r--usr.bin/make/parse.c10
-rw-r--r--usr.bin/make/var.c63
4 files changed, 37 insertions, 61 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index bd7ba945ee2..8d911efdd37 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.69 2001/06/09 05:57:31 sjg Exp $ */
+/* $NetBSD: main.c,v 1.70 2001/06/10 02:31:00 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -39,7 +39,7 @@
*/
#ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: main.c,v 1.69 2001/06/09 05:57:31 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.70 2001/06/10 02:31:00 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@@ -51,7 +51,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: main.c,v 1.69 2001/06/09 05:57:31 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.70 2001/06/10 02:31:00 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -1665,8 +1665,9 @@ ExportMAKEFLAGS(first)
return;
once = 0;
- strncpy(tmp, "${.MAKEFLAGS} ${.MAKEOVERRIDES}", sizeof(tmp));
- s = Var_Subst(NULL, tmp, VAR_GLOBAL, 0);
+ strncpy(tmp, "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
+ sizeof(tmp));
+ s = Var_Subst(NULL, tmp, VAR_CMD, 0);
if (s && *s) {
#ifdef POSIX
setenv("MAKEFLAGS", s, 1);
diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1
index 0951b5cfda0..530d43f27ed 100644
--- a/usr.bin/make/make.1
+++ b/usr.bin/make/make.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: make.1,v 1.50 2001/06/09 07:00:37 sjg Exp $
+.\" $NetBSD: make.1,v 1.51 2001/06/10 02:31:00 sjg Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -489,12 +489,18 @@ entered into the environment for all programs which
.Nm
executes.
.It Va .MAKEOVERRIDES
-This variable is used to record command line variable assignments
-so that they may be exported as part of
+This variable is used to record the names of variables assigned to
+on the command line, so that they may be exported as part of
.Ql Ev MAKEFLAGS .
This behaviour can be disabled by assigning an empty value to
.Ql Va .MAKEOVERRIDES
-within a makefile.
+within a makefile. Extra variables can be exported from a makefile
+by appending their names to
+.Ql Va .MAKEOVERRIDES .
+.Ql Ev MAKEFLAGS
+is re-exported whenever
+.Ql Va .MAKEOVERRIDES
+is modified.
.It Ev PWD
Alternate path to the current directory.
.Nm
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index c58e841a86d..3ae0e886ded 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.68 2001/06/09 05:22:47 sjg Exp $ */
+/* $NetBSD: parse.c,v 1.69 2001/06/10 02:31:00 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: parse.c,v 1.68 2001/06/09 05:22:47 sjg Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.69 2001/06/10 02:31:00 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: parse.c,v 1.68 2001/06/09 05:22:47 sjg Exp $");
+__RCSID("$NetBSD: parse.c,v 1.69 2001/06/10 02:31:00 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -1585,9 +1585,9 @@ Parse_DoVar (line, ctxt)
* Normal assignment -- just do it.
*/
Var_Set(line, cp, ctxt);
- if (strcmp(line, MAKEOVERRIDES) == 0)
- ExportMAKEFLAGS(0); /* re-export MAKEFLAGS */
}
+ if (strcmp(line, MAKEOVERRIDES) == 0)
+ ExportMAKEFLAGS(0); /* re-export MAKEFLAGS */
}
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index 8559a6ec5d7..8bb79c1a39b 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.63 2001/06/09 05:57:31 sjg Exp $ */
+/* $NetBSD: var.c,v 1.64 2001/06/10 02:31:01 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: var.c,v 1.63 2001/06/09 05:57:31 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.64 2001/06/10 02:31:01 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.63 2001/06/09 05:57:31 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.64 2001/06/10 02:31:01 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -468,43 +468,10 @@ Var_Set (name, val, ctxt)
* to the environment (as per POSIX standard)
*/
if (ctxt == VAR_CMD) {
- char tmp[256];
- char *exp;
- char *s;
- int nbytes;
-
+
setenv(name, val, 1);
- /*
- * Add name='val' to .MAKEOVERRIDES
- * We actually want the equivalent of:
- * .MAKEOVERRIDES:= ${.MAKEOVERRIDES:Nname=*} name='val'
- * clearing the previous value for name is important, since
- * doing simple duplicate suppression does not handle:
- * $ make FOO=goo
- * which might run a sub-make with FOO=boo
- * the commands from that sub-make should see just FOO=boo.
- */
- exp = 0;
- if ((nbytes = snprintf(tmp, sizeof(tmp), "${%s:N%s=*} %s='%s'",
- MAKEOVERRIDES, name, name, val))
- < sizeof(tmp)) {
- exp = tmp;
- } else {
- /* alloca is handy, but not everyone has it. */
- if ((exp = malloc(nbytes + 1)))
- snprintf(exp, nbytes + 1, "${%s:N%s=*} %s='%s'",
- MAKEOVERRIDES, name, name, val);
- }
- if (exp) {
- s = Var_Subst(NULL, exp, VAR_GLOBAL, 0);
- if (s) {
- Var_Set(MAKEOVERRIDES, s, VAR_GLOBAL);
- free(s);
- }
- if (exp != tmp)
- free(exp);
- }
+ Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL);
}
if (name != cp)
free(name);
@@ -1299,15 +1266,17 @@ VarLoopExpand (ctx, word, addSpace, buf, loopp)
VarLoop_t *loop = (VarLoop_t *) loopp;
char *s;
int slen;
-
- Var_Set(loop->tvar, word, loop->ctxt);
- s = Var_Subst(NULL, loop->str, loop->ctxt, loop->err);
- if (s != NULL && *s != '\0') {
- if (addSpace && *s != '\n')
- Buf_AddByte(buf, ' ');
- Buf_AddBytes(buf, (slen = strlen(s)), (Byte *)s);
- addSpace = (slen > 0 && s[slen - 1] != '\n');
- free(s);
+
+ if (word && *word) {
+ Var_Set(loop->tvar, word, loop->ctxt);
+ s = Var_Subst(NULL, loop->str, loop->ctxt, loop->err);
+ if (s != NULL && *s != '\0') {
+ if (addSpace && *s != '\n')
+ Buf_AddByte(buf, ' ');
+ Buf_AddBytes(buf, (slen = strlen(s)), (Byte *)s);
+ addSpace = (slen > 0 && s[slen - 1] != '\n');
+ free(s);
+ }
}
return addSpace;
}