From stephen@wilberforce.math.missouri.edu  Sun Jan 22 03:23:44 2012
Return-Path: <stephen@wilberforce.math.missouri.edu>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 318511065670
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 22 Jan 2012 03:23:44 +0000 (UTC)
	(envelope-from stephen@wilberforce.math.missouri.edu)
Received: from wilberforce.math.missouri.edu (wilberforce.math.missouri.edu [128.206.184.213])
	by mx1.freebsd.org (Postfix) with ESMTP id ECDF28FC1A
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 22 Jan 2012 03:23:43 +0000 (UTC)
Received: from wilberforce.math.missouri.edu (localhost [127.0.0.1])
	by wilberforce.math.missouri.edu (8.14.5/8.14.5) with ESMTP id q0M3NhoT025122
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 21 Jan 2012 21:23:43 -0600 (CST)
	(envelope-from stephen@wilberforce.math.missouri.edu)
Received: (from stephen@localhost)
	by wilberforce.math.missouri.edu (8.14.5/8.14.5/Submit) id q0M3Nh1b025121;
	Sat, 21 Jan 2012 21:23:43 -0600 (CST)
	(envelope-from stephen)
Message-Id: <201201220323.q0M3Nh1b025121@wilberforce.math.missouri.edu>
Date: Sat, 21 Jan 2012 21:23:43 -0600 (CST)
From: Stephen Montgomery-Smith <stephen@FreeBSD.org>
Reply-To: Stephen Montgomery-Smith <stephen@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: make handles "+=" incorrectly when the variable has zero length
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         164361
>Category:       bin
>Synopsis:       make(1) handles "+=" incorrectly when the variable has zero length
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jan 22 03:30:14 UTC 2012
>Closed-Date:    Sun Jan 22 15:30:51 UTC 2012
>Last-Modified:  Sun Jan 22 15:50:10 UTC 2012
>Originator:     Stephen Montgomery-Smith
>Release:        FreeBSD 8.2-STABLE amd64
>Organization:
>Environment:
System: FreeBSD wilberforce 8.2-STABLE FreeBSD 8.2-STABLE #0: Sat Dec 24 10:10:36 CST 2011 stephen@wilberforce:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:

make handles "+=" incorrectly when the variable has zero length.

This creates a mystery space if one does something like

cd /usr/ports/math/lapack
make -V LDFLAGS

because of many lines in /usr/share/mk/sys.mk like
LDFLAGS		?=

>How-To-Repeat:
Create a Makefile containing
XXX=
XXX+=	xxx

all:
	echo +${XXX}+


make produces the output
echo + xxx+
+ xxx+

>Fix:

	

diff -ur usr.bin/make/var.c-orig usr.bin/make/var.c
--- usr.bin/make/var.c-orig	2012-01-21 21:10:50.000000000 -0600
+++ usr.bin/make/var.c	2012-01-21 21:12:05.000000000 -0600
@@ -1101,7 +1101,8 @@
 	if (v == NULL) {
 		VarAdd(n, val, ctxt);
 	} else {
-		Buf_AddByte(v->val, (Byte)' ');
+		if (Buf_Size(v->val) != 0)
+			Buf_AddByte(v->val, (Byte)' ');
 		Buf_Append(v->val, val);
 		DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, Buf_Data(v->val)));
 	}

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sun Jan 22 03:49:54 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164361 
State-Changed-From-To: open->closed 
State-Changed-By: eadler 
State-Changed-When: Sun Jan 22 15:30:49 UTC 2012 
State-Changed-Why:  
it seeems that you will have to work around this behavior. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164361 

From: Eitan Adler <eadler@freebsd.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/164361: make handles "+=" incorrectly when the variable has
 zero length
Date: Sun, 22 Jan 2012 10:48:09 -0500

 ---------- Forwarded message ----------
 From: Jilles Tjoelker <jilles@stack.nl>
 Date: Sun, Jan 22, 2012 at 8:24 AM
 Subject: Re: bin/164361 quick question about make
 To: Eitan Adler <lists@eitanadler.com>
 
 On Sun, Jan 22, 2012 at 12:48:49AM -0500, Eitan Adler wrote:
 > Is the behavior reported in bin/164361 actually a bug?
 > http://pubs.opengroup.org/onlinepubs/009695399/utilities/make.html
 > appears to have comment on +=
 > The patch provided seems to fix the issue for me, but is it correct?
 
 I cannot find mention of += in the POSIX specification for make, but
 there is a proposal to add it at
 http://austingroupbugs.net/view.php?id=330 .
 
 This proposal appears to describe exactly what we do: if the variable
 already exists, a space is inserted between the old and the new value,
 even if the old value is null.
 
 The same happens in gmake and bmake (with the example).
 
 Because an extraneous space is unlikely to cause problems (sh treats two
 unquoted spaces the same as a single unquoted space), it seems unwise to
 change this.
 
 
 --
 Eitan Adler
 Source & Ports committer
 X11, Bugbusting teams
>Unformatted:
