From mark@thuvia.demon.co.uk  Sat Mar  4 13:01:27 2000
Return-Path: <mark@thuvia.demon.co.uk>
Received: from thuvia.demon.co.uk (thuvia.demon.co.uk [193.237.34.248])
	by hub.freebsd.org (Postfix) with ESMTP id 7F83137B79D
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  4 Mar 2000 13:01:23 -0800 (PST)
	(envelope-from mark@thuvia.demon.co.uk)
Received: (from mark@localhost)
	by thuvia.demon.co.uk (8.9.3/8.9.3) id VAA46006;
	Sat, 4 Mar 2000 21:01:21 GMT
	(envelope-from mark)
Message-Id: <200003042101.VAA46006@thuvia.demon.co.uk>
Date: Sat, 4 Mar 2000 21:01:21 GMT
From: Mark Valentine <mark@thuvia.demon.co.uk>
Reply-To: mark@thuvia.demon.co.uk
To: FreeBSD-gnats-submit@freebsd.org
Subject: make(1) option to reproduce original -V behaviour
X-Send-Pr-Version: 3.2

>Number:         17188
>Category:       bin
>Synopsis:       make(1) option to reproduce original -V behaviour
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    peter
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar  4 13:10:02 PST 2000
>Closed-Date:    Mon Sep 25 11:47:26 PDT 2000
>Last-Modified:  Mon Sep 25 11:47:45 PDT 2000
>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:
Responsible-Changed-From-To: freebsd-bugs->peter 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Mon Aug 7 07:38:38 PDT 2000 
Responsible-Changed-Why:  
Johan Karlsson says that Peter committed rev 1.24. 
Peter, this one contains a well-motivated patch. :-) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=17188 
State-Changed-From-To: open->closed 
State-Changed-By: peter 
State-Changed-When: Mon Sep 25 11:47:26 PDT 2000 
State-Changed-Why:  
Patch applied to -current and RELENG_4. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=17188 
>Unformatted:
