From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 10 13:11:22 2006 Return-Path: X-Original-To: freebsd-hackers@FreeBSD.ORG Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EFDFA16A4DD for ; Thu, 10 Aug 2006 13:11:22 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [83.120.8.8]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2315843D45 for ; Thu, 10 Aug 2006 13:11:21 +0000 (GMT) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (pszcds@localhost [127.0.0.1]) by lurza.secnetix.de (8.13.4/8.13.4) with ESMTP id k7ADBD9c075287 for ; Thu, 10 Aug 2006 15:11:19 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.13.4/8.13.1/Submit) id k7ADBDWn075286; Thu, 10 Aug 2006 15:11:13 +0200 (CEST) (envelope-from olli) Date: Thu, 10 Aug 2006 15:11:13 +0200 (CEST) Message-Id: <200608101311.k7ADBDWn075286@lurza.secnetix.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG In-Reply-To: X-Newsgroups: list.freebsd-hackers User-Agent: tin/1.8.0-20051224 ("Ronay") (UNIX) (FreeBSD/4.11-STABLE (i386)) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Thu, 10 Aug 2006 15:11:19 +0200 (CEST) X-Mailman-Approved-At: Thu, 10 Aug 2006 16:02:52 +0000 Cc: Subject: Re: make(1) is broken? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-hackers@FreeBSD.ORG List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Aug 2006 13:11:23 -0000 Stanislav Sedov wrote: > Consider the following Makefile: > --------------------------------------------------------------- > COMPS=aa ab ac > AA=aa > > VAR1=${COMPS:Maa} > VAR2=${COMPS:M${AA}} > > .for COMP in ${AA} > VAR3=${COMPS:M${COMP}} > .endfor > --------------------------------------------------------------- > > Now, running make(1) gives: > % make -V VAR1 > aa > % make -V VAR2 > } > % make -V VAR3 > aa > > Results for VAR2 seems quite strange for me. It looks like > ${COMP}!=${AA} > > So, the question: is make(1) broken, or it's my misunderstanding? Nested variable expansion is _only_ documented to work for the ":S" modifier, see the make(1) manual page. When the VAR2 assignment is parsed, the second opening brace is ignored, and the first closing brace closes the first opening one. The second closing brace doesn't belong to anything and is just appended to the assignment. A bit simplified, the parser sees these tokens: <=> <$> <{> <:> <${AA> <}> <}> Of course, "${AA" doesn't match anything, so the whole expansion is empty. Then the closing brace is appended, so the value of VAR2 is just "}". Now, why does it work within the for loop? That's a side effect of the way how .for loops work. When such a loop is parsed, an expanded (duplicated) text is generated, and the control variable of the loop is expanded before _anything_ else, i.e. the expanded text of the .for loop is parsed a second time. I think it is better not to rely on that side effect. It isn't well documented and might change without notice in the future. Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd Any opinions expressed in this message may be personal to the author and may not necessarily reflect the opinions of secnetix in any way. 'Instead of asking why a piece of software is using "1970s technology," start asking why software is ignoring 30 years of accumulated wisdom.'