Subject: printing expanded variables?
To: None <tech-toolchain@netbsd.org>
From: Simon J. Gerraty <sjg@crufty.net>
List: tech-toolchain
Date: 09/02/2003 16:44:42
Anyone find it frustrating when make -V FOO shows you just ${FU}?
Sometimes you want, that, but often you just want to know what it
expands to. Changing the behavior of -V would of course break the
world, so how about -v for the expanded version? (ok I'm lousy at
naming things ;-)
Given:
FOO=fu
BAR=bar
FUBAR=${FOO} ${BAR}
$ make -V FUBAR
${FOO} ${BAR}
$ make -v FUBAR
fu bar
$
--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/02 23:42:47
@@ -154,6 +154,7 @@ Boolean allPrecious; /* .PRECIOUS give
static Boolean noBuiltins; /* -r flag */
static Lst makefiles; /* ordered list of makefiles to read */
static Boolean printVars; /* print value of one or more vars */
+static Boolean printVarSubst; /* print expanded value of one or more vars */
static Lst variables; /* list of variables to print */
int maxJobs; /* -j argument */
static int maxLocal; /* -L argument */
@@ -209,9 +210,9 @@ MainParseArgs(int argc, char **argv)
optind = 1; /* since we're called more than once */
#ifdef REMOTE
-# define OPTFLAGS "BD:I:J:L:NPST:V:WXd:ef:ij:km:nqrst"
+# define OPTFLAGS "BD:I:J:L:NPST:V:v:WXd:ef:ij:km:nqrst"
#else
-# define OPTFLAGS "BD:I:J:NPST:V:WXd:ef:ij:km:nqrst"
+# define OPTFLAGS "BD:I:J:NPST:V:v:WXd:ef:ij:km:nqrst"
#endif
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
switch(c) {
@@ -249,6 +250,13 @@ rearg: while((c = getopt(argc, argv, OPT
jobServer = TRUE;
}
break;
+ case 'v':
+ printVarSubst = TRUE;
+ printVars = TRUE;
+ (void)Lst_AtEnd(variables, (ClientData)optarg);
+ Var_Append(MAKEFLAGS, "-v", VAR_GLOBAL);
+ Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
+ break;
case 'V':
printVars = TRUE;
(void)Lst_AtEnd(variables, (ClientData)optarg);
@@ -913,9 +921,15 @@ main(int argc, char **argv)
for (ln = Lst_First(variables); ln != NILLNODE;
ln = Lst_Succ(ln)) {
char *value = Var_Value((char *)Lst_Datum(ln),
- VAR_GLOBAL, &p1);
+ VAR_GLOBAL, &p1);
+
+ if (printVarSubst && 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);
}