From 693df6904d863e6c86cdfb708652ca2a30f690d2 Mon Sep 17 00:00:00 2001 From: sjg Date: Wed, 1 Feb 2017 18:39:27 +0000 Subject: [PATCH] Since we are avoiding VAR_INTERNAL, allow the variable :_ stores to to be specified, also allows for multiple stages of modification to be stashed. --- usr.bin/make/make.1 | 16 +++++++--------- usr.bin/make/var.c | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1 index 8d6bf431977c..e749e5dd162c 100644 --- a/usr.bin/make/make.1 +++ b/usr.bin/make/make.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.265 2017/01/30 02:46:20 sjg Exp $ +.\" $NetBSD: make.1,v 1.266 2017/02/01 18:39:27 sjg Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd January 29, 2017 +.Dd February 1, 2017 .Dt MAKE 1 .Os .Sh NAME @@ -1425,24 +1425,22 @@ For example. .Pp However a single character variable is often more readable: .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} -.It Cm \&:_ +.It Cm \&:_[=var] Save the current variable value in .Ql $_ +or the named +.Va var for later reference. -This -.Ql $_ -is internal to the variable modifier processing and -will not conflict with any set in a makefile. Example usage: .Bd -literal -offset indent -M_cmpv.units = 1 100 10000 +M_cmpv.units = 1 1000 1000000 M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \&\\ \\* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh .Dv .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}} .Ed -Here the +Here .Ql $_ is used to save the result of the .Ql :S diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 10ec35a61fbb..482366abb11c 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.212 2017/02/01 18:00:14 sjg Exp $ */ +/* $NetBSD: var.c,v 1.213 2017/02/01 18:39:27 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.212 2017/02/01 18:00:14 sjg Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.213 2017/02/01 18:39:27 sjg Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: var.c,v 1.212 2017/02/01 18:00:14 sjg Exp $"); +__RCSID("$NetBSD: var.c,v 1.213 2017/02/01 18:39:27 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -2742,11 +2742,24 @@ ApplyModifiers(char *nstr, const char *tstr, break; } case '_': /* remember current value */ - if CHARMOD_MATCH(tstr[1]) { - Var_Set("_", nstr, ctxt, 0); + cp = tstr + 1; /* make sure it is set */ + if (STRMOD_MATCHX(tstr, "_", 1)) { + if (tstr[1] == '=') { + char *np; + int n; + + cp++; + n = strcspn(cp, ":)}"); + np = bmake_strndup(cp, n+1); + np[n] = '\0'; + cp = tstr + 2 + n; + Var_Set(np, nstr, ctxt, 0); + free(np); + } else { + Var_Set("_", nstr, ctxt, 0); + } newStr = nstr; - cp = ++tstr; - termc = *tstr; + termc = *cp; break; } goto default_case;