NetBSD Problem Report #47888

From dholland@netbsd.org  Wed Jun  5 00:29:56 2013
Return-Path: <dholland@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 7605E71B1E
	for <gnats-bugs@gnats.NetBSD.org>; Wed,  5 Jun 2013 00:29:56 +0000 (UTC)
Message-Id: <20130605002956.05B8814A260@mail.netbsd.org>
Date: Wed,  5 Jun 2013 00:29:56 +0000 (UTC)
From: dholland@NetBSD.org
Reply-To: dholland@NetBSD.org
To: gnats-bugs@gnats.NetBSD.org
Subject: make(1) mishandles empty() inside loops
X-Send-Pr-Version: 3.95

>Number:         47888
>Category:       bin
>Synopsis:       make(1) mishandles empty() inside loops
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 05 00:30:00 +0000 2013
>Last-Modified:  Fri Jun 07 18:00:00 +0000 2013
>Originator:     David A. Holland
>Release:        NetBSD 6.99.19 (20130404)
>Organization:
>Environment:
System: NetBSD valkyrie 6.99.19 NetBSD 6.99.19 (VALKYRIE) #12: Thu Apr  4 02:19:36 EDT 2013  dholland@valkyrie:/usr/src/sys/arch/amd64/compile/VALKYRIE amd64
Architecture: x86_64
Machine: amd64
>Description:

make does not expand empty() correctly inside loops. It seems to be
taking the value of the loop variable from before/outside the loop.

>How-To-Repeat:

   ------
LIST=abc def ghi

X=xyz
foo:
.for X in $(LIST)
	@echo '$$(X) is: $(X)'
	@echo '$$(X:Mxyz) is: $(X:Mxyz)'
.if empty(X:Mxyz)
	@echo '...which is empty'
.else
	@echo '...which is NOT empty'
.endif
	@echo
.endfor
   ------

With the "X=xyz" line in place, it always prints "is NOT empty"; with
that commented out so X is empty prior to the loop initialization, it
always prints "is empty". This is true whether or not LIST contains
"xyz".

>Fix:

dunno yet

>Audit-Trail:
From: David Laight <david@l8s.co.uk>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/47888: make(1) mishandles empty() inside loops
Date: Fri, 7 Jun 2013 19:09:27 +0100

 On Wed, Jun 05, 2013 at 12:30:01AM +0000, dholland@NetBSD.org wrote:
 > >Number:         47888
 > >Category:       bin
 > >Synopsis:       make(1) mishandles empty() inside loops
 ...
 > make does not expand empty() correctly inside loops. It seems to be
 > taking the value of the loop variable from before/outside the loop.

 The problem is the way that make substitutes loop variables.
 In the 'old' days it used to substitute the loop varaiable and then
 parse the text.  This generated all sorts of issues.

 I changed if to transform $(loop_var) into $(:U<loop_var_data>)
 so that the loop variable text still comes from a variable substitution.

 However, and noted, this doesn't detect empty() or defined().

 A better solution might be to put the loop variable value into the
 symbol table for 'pass 1' substitutions and only do the $(:U<text>)
 fudge for all extant loop variables when command lines are saved.

 This probably isn't that hard - or wouldn't be it it wasn't make!

 	David

 -- 
 David Laight: david@l8s.co.uk

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.