From b3dc6c07e27f4bab5dfe4b4055af9a74e230d2a3 Mon Sep 17 00:00:00 2001 From: "David E. O'Brien" Date: Thu, 31 May 2012 00:36:56 +0000 Subject: [PATCH] Add "-V '${VAR}'" variable expansion from Portable Berkeley Make. Submitted by: Simon Gerraty --- usr.bin/make/make.1 | 5 +++++ usr.bin/make/var.c | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1 index fc91f3c95f7d..d15428b55454 100644 --- a/usr.bin/make/make.1 +++ b/usr.bin/make/make.1 @@ -320,6 +320,11 @@ Do not build any targets. Multiple instances of this option may be specified; the variables will be printed one per line, with a blank line for each null or undefined variable. +If +.Ar variable +contains a +.Sq Ic $ +then the value will be expanded before printing. .It Fl v Be extra verbose. Print any extra information. diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 341ee79b16b6..477c4a906bce 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -2593,7 +2593,7 @@ void Var_Print(Lst *vlist, Boolean expandVars) { LstNode *n; - const char *name; + char *name; LST_FOREACH(n, vlist) { name = Lst_Datum(n); @@ -2601,13 +2601,17 @@ Var_Print(Lst *vlist, Boolean expandVars) char *value; char *v; - v = emalloc(strlen(name) + 1 + 3); - sprintf(v, "${%s}", name); - + if (*name == '$') { + v = name; + } else { + v = emalloc(strlen(name) + 1 + 3); + sprintf(v, "${%s}", name); + } value = Buf_Peel(Var_Subst(v, VAR_GLOBAL, FALSE)); printf("%s\n", value); - free(v); + if (v != name) + free(v); free(value); } else { const char *value = Var_Value(name, VAR_GLOBAL);