Subject: Re: make - fix :M
To: None <tech-toolchain@netbsd.org>
From: Simon J. Gerraty <sjg@crufty.net>
List: tech-toolchain
Date: 02/19/2004 21:47:37
Ok, I knew that was too easy.  Fortunately adding a unit-test
for mod :M made it easy to check the patch below.

--sjg

Index: var.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/var.c,v
retrieving revision 1.86
diff -u -r1.86 var.c
--- var.c	24 Jan 2004 19:58:54 -0000	1.86
+++ var.c	20 Feb 2004 05:46:49 -0000
@@ -2713,7 +2713,7 @@
 		    copy = FALSE;
 		    nest = 1;
 		    for (cp = tstr + 1;
-			 *cp != '\0' && *cp != ':';
+			 *cp != '\0' && !(*cp == ':' && nest == 1);
 			 cp++)
 		    {
 			if (*cp == '\\' &&
Index: unit-tests/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/make/unit-tests/Makefile,v
retrieving revision 1.10
diff -u -r1.10 Makefile
--- unit-tests/Makefile	19 Jan 2004 00:32:26 -0000	1.10
+++ unit-tests/Makefile	20 Feb 2004 05:46:49 -0000
@@ -16,7 +16,7 @@
 
 UNIT_TESTS:= ${.PARSEDIR}
 
-all: mod-ts varcmd modword ternary
+all: mod-ts varcmd modword ternary modmatch
 
 LIST= one two three
 LIST+= four five six
@@ -49,8 +49,8 @@
 	@echo 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?'
 
 # Some tests are best handled via a sub-make
-.PHONY: varcmd modword
-varcmd modword:
+.PHONY: varcmd modword modmatch
+varcmd modword modmatch:
 	@${.MAKE} -k -f ${UNIT_TESTS}/$@
 
 .PHONY:	ternary
Index: unit-tests/modmatch
===================================================================
RCS file: unit-tests/modmatch
diff -N unit-tests/modmatch
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ unit-tests/modmatch	20 Feb 2004 05:46:49 -0000
@@ -0,0 +1,19 @@
+# $Id$
+
+X=a b c d e
+
+.for x in $X
+LIB${x:tu}=/tmp/lib$x.a
+.endfor
+
+X_LIBS= ${LIBA} ${LIBD} ${LIBE}
+
+LIB?=a
+
+all:
+	@for x in $X; do ${.MAKE} -f ${MAKEFILE} show LIB=$$x; done
+
+show:
+	@echo 'LIB=${LIB} X_LIBS:M$${LIB$${LIB:tu}} is "${X_LIBS:M${LIB${LIB:tu}}}"'
+	@echo 'LIB=${LIB} X_LIBS:M*/lib$${LIB}.a is "${X_LIBS:M*/lib${LIB}.a}"'
+	@echo 'LIB=${LIB} X_LIBS:M*/lib$${LIB}.a:tu is "${X_LIBS:M*/lib${LIB}.a:tu}"'
Index: unit-tests/test.exp
===================================================================
RCS file: /cvsroot/src/usr.bin/make/unit-tests/test.exp,v
retrieving revision 1.7
diff -u -r1.7 test.exp
--- unit-tests/test.exp	9 Jan 2004 00:56:44 -0000	1.7
+++ unit-tests/test.exp	20 Feb 2004 05:46:49 -0000
@@ -165,3 +165,18 @@
 The answer is known
 The answer is 42
 The answer is 42
+LIB=a X_LIBS:M${LIB${LIB:tu}} is "/tmp/liba.a"
+LIB=a X_LIBS:M*/lib${LIB}.a is "/tmp/liba.a"
+LIB=a X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBA.A"
+LIB=b X_LIBS:M${LIB${LIB:tu}} is ""
+LIB=b X_LIBS:M*/lib${LIB}.a is ""
+LIB=b X_LIBS:M*/lib${LIB}.a:tu is ""
+LIB=c X_LIBS:M${LIB${LIB:tu}} is ""
+LIB=c X_LIBS:M*/lib${LIB}.a is ""
+LIB=c X_LIBS:M*/lib${LIB}.a:tu is ""
+LIB=d X_LIBS:M${LIB${LIB:tu}} is "/tmp/libd.a"
+LIB=d X_LIBS:M*/lib${LIB}.a is "/tmp/libd.a"
+LIB=d X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBD.A"
+LIB=e X_LIBS:M${LIB${LIB:tu}} is "/tmp/libe.a"
+LIB=e X_LIBS:M*/lib${LIB}.a is "/tmp/libe.a"
+LIB=e X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBE.A"