From owner-freebsd-bugs@FreeBSD.ORG Tue Mar 16 05:50:23 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B920A16A4CE for ; Tue, 16 Mar 2004 05:50:23 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 998E643D45 for ; Tue, 16 Mar 2004 05:50:23 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i2GDoNbv004454 for ; Tue, 16 Mar 2004 05:50:23 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i2GDoMXg004452; Tue, 16 Mar 2004 05:50:22 -0800 (PST) (envelope-from gnats) Date: Tue, 16 Mar 2004 05:50:22 -0800 (PST) Message-Id: <200403161350.i2GDoMXg004452@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Ruslan Ermilov Subject: Re: bin/64327: [PATCH] make(1): document surprising behaviour of assign with expansion X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Ruslan Ermilov List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Mar 2004 13:50:24 -0000 The following reply was made to PR bin/64327; it has been noted by GNATS. From: Ruslan Ermilov To: Oliver Eikemeier Cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: bin/64327: [PATCH] make(1): document surprising behaviour of assign with expansion Date: Tue, 16 Mar 2004 15:41:50 +0200 On Tue, Mar 16, 2004 at 12:49:27PM +0100, Oliver Eikemeier wrote: > > Try the Makefile from the patch: > > VAR1:= Assigned with${OUT} expansion > VAR2!= echo Assigned with${OUT} expansion > OUT= out > all: > @echo := - ${VAR1} > @echo != - ${VAR2} > > >Fix: > > diff -u -r1.29.2.15 make.1 > --- make.1 17 Dec 2002 19:01:18 -0000 1.29.2.15 > +++ make.1 16 Mar 2004 11:12:09 -0000 > @@ -1266,6 +1266,17 @@ > \&.endfor > .Ed > won't work, and should be rewritten the other way around. > +.Pp > +Undefined variables are not expanded when assigned with expansion. > +This is intentional, but may lead to surprising results: > +.Bd -literal > +VAR1:= Assigned with${OUT} expansion > +VAR2!= echo Assigned with${OUT} expansion > +OUT= out > +all: > + @echo := - ${VAR1} > + @echo != - ${VAR2} > +.Ed > .Sh SEE ALSO > .Xr mkdep 1 , > .Xr make.conf 5 > So, expanding "Assigned with${OUT} expansion" with := when OUT is undefined gives you the same string (have a look at the ``make -r -dv'' output), and it becomes a value of VAR1, and when later you print it, it's expanded again (as it still has the `$' character). This time OUT is defined, and its value is substituted. Expanding "echo Assigned with${OUT} expansion" through != gives you "Assigned with expansion", and that's what gets printed later. Whatever, "undefined variables are not expanded" sounds like a non-sense to me. ;) The following code fragment in make(1) is responsible for this, and has more correct wording: : } else if (type == VAR_SUBST) { : /* : * Allow variables in the old value to be undefined, but leave their : * invocation alone -- this is done by forcing oldVars to be false. : * XXX: This can cause recursive variables, but that's not hard to do, : * and this allows someone to do something like : * : * CFLAGS = $(.INCLUDES) : * CFLAGS := -I.. $(CFLAGS) : * : * And not get an error. : */ : Boolean oldOldVars = oldVars; : : oldVars = FALSE; Perhaps you could convert it to fit the manpage? Definitely we shouldn't put it in the BUGS section. Cheers, -- Ruslan Ermilov FreeBSD committer ru@FreeBSD.org