Subject: Re: printing expanded variables?
To: Alan Barrett <apb@cequrux.com>
From: Simon J. Gerraty <sjg@crufty.net>
List: tech-toolchain
Date: 09/04/2003 08:24:22
>I don't think it would be appropriate for a "verbose" flag to make the
>difference between printing the value inexpanded or expanded.  When I

That's ok, we've abandoned that idea.

>> I don't think they are that scarce and -E is reasonably mnemonic.

>Fair enough.  In that case, I like "-E" for "evaluate", and I think it
>should take arbitrarily complex strings, not just variable names.  For

That's a different beast entirely - ie. out of scope for now.
All I (and many others) want right now is the moral equiv of "make -V FOO"
and be able to get it expanded all the way.  Getting tansient
variables like .TARGET substituted correctly is a more complex thing too.

My current implementation (patch below) uses ':' or '$' at the start
of the variable to cause Var_Subst to be used in addition to Var_Value.

--sjg


Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/main.c,v
retrieving revision 1.91
diff -u -p -r1.91 main.c
--- main.c	2003/08/07 11:14:53	1.91
+++ main.c	2003/09/04 07:45:13
@@ -912,10 +912,20 @@ main(int argc, char **argv)
 
 		for (ln = Lst_First(variables); ln != NILLNODE;
 		    ln = Lst_Succ(ln)) {
-			char *value = Var_Value((char *)Lst_Datum(ln),
+			char *var = (char *)Lst_Datum(ln);
+			char *value;
+			int subst = (*var == '$' || *var == ':');
+
+			value = Var_Value(subst ? &var[1] : var,
 					  VAR_GLOBAL, &p1);
+
+			if (subst && value && strchr(value, '$')) {
+				char *s = Var_Subst(NULL, value, VAR_GLOBAL, 0);
 
-			printf("%s\n", value ? value : "");
+				printf("%s\n", s);
+				free(s);
+			} else
+				printf("%s\n", value ? value : "");
 			if (p1)
 				free(p1);
 		}
Index: make.1
===================================================================
RCS file: /cvsroot/src/usr.bin/make/make.1,v
retrieving revision 1.84
diff -u -p -r1.84 make.1
--- make.1	2003/08/07 11:14:54	1.84
+++ make.1	2003/09/04 07:45:14
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)make.1	8.4 (Berkeley) 3/19/94
 .\"
-.Dd July 31, 2003
+.Dd September 4, 2003
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -227,6 +227,13 @@ 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
+is prefixed with 
+.Ql \&$
+or
+.Ql \&: ,
+then the value will be expanded before printing.
 .It Fl W
 Treat any warnings during makefile parsing as errors.
 .It Fl X