diff options
| author | sjg <sjg@NetBSD.org> | 2001-06-10 02:31:00 +0000 |
|---|---|---|
| committer | sjg <sjg@NetBSD.org> | 2001-06-10 02:31:00 +0000 |
| commit | fc0df160d89195b37f5832075656d06bd0a024af (patch) | |
| tree | 9fbca62fb8f65f8a8656ebf184fa9ec5e84b096e /usr.bin/make/var.c | |
| parent | a2b115fa4cb9b51c7e0f8a242a9bd644ff6eabe6 (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/var.c')
| -rw-r--r-- | usr.bin/make/var.c | 63 |
1 files changed, 16 insertions, 47 deletions
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; } |
