Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Mar 2003 11:21:41 -0800
From:      Marcel Moolenaar <marcel@xcllnt.net>
To:        Alexander Leidinger <Alexander@Leidinger.net>
Cc:        arch@FreeBSD.ORG
Subject:   Re: Bug in our make or undocumented feature?
Message-ID:  <20030315192141.GA564@dhcp01.pn.xcllnt.net>
In-Reply-To: <20030315165221.27d3d424.Alexander@Leidinger.net>
References:  <20030315165221.27d3d424.Alexander@Leidinger.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sat, Mar 15, 2003 at 04:52:21PM +0100, Alexander Leidinger wrote:
> this part of a makefile doesn't work for me:
> ---snip---
> WANTED_PORTS=	shells/zsh lang/perl5
> 
> mytarget:
> .for i in ${WANTED_PORTS}
> 	@echo "${i}"
> .if ${i} == lang/perl5  
> 	@echo "Yep, perl5."
> .endif
> .endfor
> ---snip---

Bug. A simpler case:

	.if "shells/zsh" == "lang/perl5"
	.endif

dhcp01% make -f mf
"mf", line 1: Malformed conditional ("shells/zsh" == "lang/perl5")
"mf", line 1: Need an operator
"mf", line 2: if-less endif
"mf", line 2: Need an operator
make: fatal errors encountered -- cannot continue

The problem is that our make needs a variable on the left in order
to parse this correctly as a comparison. Now we end up evaluating this
like:
	.if defined("shells/zsh") ...

The attached patches partly fixes it by allowing string comparisons
(ie make sure you have the lhs and rhs quoted)

Try it out,

-- 
 Marcel Moolenaar	  USPA: A-39004		 marcel@xcllnt.net

--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="make.diff"

Index: cond.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/cond.c,v
retrieving revision 1.25
diff -u -r1.25 cond.c
--- cond.c	23 Oct 2002 23:16:42 -0000	1.25
+++ cond.c	15 Mar 2003 19:17:24 -0000
@@ -500,6 +500,7 @@
 	    case '\0':
 		t = EndOfFile;
 		break;
+	    case '"':
 	    case '$': {
 		char	*lhs;
 		char	*rhs;
@@ -511,16 +512,21 @@
 		 * Parse the variable spec and skip over it, saving its
 		 * value in lhs.
 		 */
-		t = Err;
-		lhs = Var_Parse(condExpr, VAR_CMD, doEval,&varSpecLen,&doFree);
-		if (lhs == var_Error) {
-		    /*
-		     * Even if !doEval, we still report syntax errors, which
-		     * is what getting var_Error back with !doEval means.
-		     */
-		    return(Err);
-		}
-		condExpr += varSpecLen;
+		if (*condExpr == '$') {
+		    t = Err;
+		    lhs = Var_Parse(condExpr, VAR_CMD, doEval, &varSpecLen,
+			&doFree);
+		    if (lhs == var_Error) {
+			/*
+			 * Even if !doEval, we still report syntax
+			 * errors, which is what getting var_Error
+			 * back with !doEval means.
+			 */
+			return(Err);
+		    }
+		    condExpr += varSpecLen;
+		} else
+		    lhs = NULL;
 
 		if (!isspace((unsigned char) *condExpr) &&
 		    strchr("!=><", *condExpr) == NULL) {
@@ -529,8 +535,10 @@
 
 		    buf = Buf_Init(0);
 
-		    for (cp = lhs; *cp; cp++)
-			Buf_AddByte(buf, (Byte)*cp);
+		    if (lhs != NULL) {
+			for (cp = lhs; *cp; cp++)
+			    Buf_AddByte(buf, (Byte)*cp);
+		    }
 
 		    if (doFree)
 			free(lhs);
@@ -545,6 +553,9 @@
 
 		    doFree = TRUE;
 		}
+
+		if (lhs == NULL)
+			return (Err);
 
 		/*
 		 * Skip whitespace to get to the operator

--2oS5YaxWCcQjTEyO--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030315192141.GA564>