Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 4 Mar 2000 21:01:21 GMT
From:      Mark Valentine <mark@thuvia.demon.co.uk>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/17188: make(1) option to reproduce original -V behaviour
Message-ID:  <200003042101.VAA46006@thuvia.demon.co.uk>

next in thread | raw e-mail | index | archive | help

>Number:         17188
>Category:       bin
>Synopsis:       make(1) option to reproduce original -V behaviour
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar  4 13:10:02 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Mark Valentine
>Release:        FreeBSD 4.0-CURRENT i386
>Organization:
>Environment:

	

>Description:

I originally submitted the make -V option as a result of trying to
debug a modular build system where it wasn't clear where the final
effective assignment to a variable was taking place.

I could trivially see the _expanded_ value of a variable (on many
make(1) implementations) using something like:

    show::
	@echo $(VAR) = $($(VAR))

However, what I wanted to see was the actual textual assignment (because
my head hurt tracing through layers of included makefile segments), in
order to determine which part of my build system was responsible for the
final value of the variable.

The change of behaviour in 1.24 removes my ability to find what I wanted,
and instead I have a second way to achieve what I could already do!  :-(

Since several releases have gone out with the new behaviour, it would be
wrong to revert the default behaviour of -V.  The patch below adds a new
-X (don't expand) flag to give -V its original behaviour.

  $ make -V CFLAGS
  -O -pipe -I/usr/src/usr.bin/make  
  $ make -X -V CFLAGS
  -O -pipe -I${.CURDIR} ${COPTS} ${DEBUG_FLAGS}

>How-To-Repeat:

	

>Fix:

Index: main.c
===================================================================
RCS file: /usr/cvs/src/usr.bin/make/main.c,v
retrieving revision 1.35
diff -u -r1.35 main.c
--- main.c	1999/11/23 10:35:24	1.35
+++ main.c	2000/03/04 20:32:17
@@ -122,6 +122,7 @@
 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		expandVars;	/* fully expand printed variables */
 static Lst		variables;	/* list of variables to print */
 int			maxJobs;	/* -j argument */
 static Boolean          forceJobs;      /* -j argument given */
@@ -175,9 +176,9 @@
 
 	optind = 1;	/* since we're called more than once */
 #ifdef REMOTE
-# define OPTFLAGS "BD:E:I:L:PSV:d:ef:ij:km:nqrstv"
+# define OPTFLAGS "BD:E:I:L:PSV:Xd:ef:ij:km:nqrstv"
 #else
-# define OPTFLAGS "BD:E:I:PSV:d:ef:ij:km:nqrstv"
+# define OPTFLAGS "BD:E:I:PSV:Xd:ef:ij:km:nqrstv"
 #endif
 rearg:	while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
 		switch(c) {
@@ -193,15 +194,13 @@
 			break;
 		case 'V':
 			printVars = TRUE;
-			p = malloc(strlen(optarg) + 1 + 3);
-			if (!p)
-				Punt("make: cannot allocate memory.");
-                        /* This sprintf is safe, because of the malloc above */
-			(void)sprintf(p, "${%s}", optarg);
-			(void)Lst_AtEnd(variables, (ClientData)p);
+			(void)Lst_AtEnd(variables, (ClientData)optarg);
 			Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
 			Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
 			break;
+		case 'X':
+			expandVars = FALSE;
+			break;
 		case 'B':
 			compatMake = TRUE;
 			Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL);
@@ -619,6 +618,7 @@
 	makefiles = Lst_Init(FALSE);
 	envFirstVars = Lst_Init(FALSE);
 	printVars = FALSE;
+	expandVars = TRUE;
 	variables = Lst_Init(FALSE);
 	beSilent = FALSE;		/* Print commands as executed */
 	ignoreErrors = FALSE;		/* Pay attention to non-zero returns */
@@ -826,10 +826,21 @@
 
 		for (ln = Lst_First(variables); ln != NILLNODE;
 		    ln = Lst_Succ(ln)) {
-			char *value = Var_Subst(NULL, (char *)Lst_Datum(ln),
-					  VAR_GLOBAL, FALSE);
-
+			char *value;
+			if (expandVars) {
+				p1 = malloc(strlen((char *)Lst_Datum(ln)) + 1 + 3);
+				if (!p1)
+					Punt("make: cannot allocate memory.");
+				/* This sprintf is safe, because of the malloc above */
+				(void)sprintf(p1, "${%s}", (char *)Lst_Datum(ln));
+				value = Var_Subst(NULL, p1, VAR_GLOBAL, FALSE);
+			} else {
+				value = Var_Value((char *)Lst_Datum(ln),
+						  VAR_GLOBAL, &p1);
+			}
 			printf("%s\n", value ? value : "");
+			if (p1)
+				free(p1);
 		}
 	}
 
Index: make.1
===================================================================
RCS file: /usr/cvs/src/usr.bin/make/make.1,v
retrieving revision 1.27
diff -u -r1.27 make.1
--- make.1	2000/01/19 10:44:28	1.27
+++ make.1	2000/03/04 20:38:03
@@ -40,7 +40,7 @@
 .Nd maintain program dependencies
 .Sh SYNOPSIS
 .Nm make
-.Op Fl BPSeiknqrstv
+.Op Fl BPSXeiknqrstv
 .Op Fl D Ar variable
 .Op Fl d Ar flags
 .Op Fl E Ar variable
@@ -212,6 +212,11 @@
 .It Fl v
 Be extra verbose.
 For multi-job makes, this will cause file banners to be generated.
+.It Fl X
+When using the
+.Fl V
+option to print the values of variables,
+do not recursively expand the values.
 .It Ar variable Ns No = Ns Ar value
 Set the value of the variable
 .Ar variable


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003042101.VAA46006>