summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorsjg <sjg@NetBSD.org>2004-04-08 00:59:01 +0000
committersjg <sjg@NetBSD.org>2004-04-08 00:59:01 +0000
commit8bef426d13dfea2e8a39abe5edb5d1593e840ecb (patch)
tree5f4393395fa8f996785c707f09be0366fd00b5d8 /usr.bin/make
parentdfa47cfea0e36ece2027a155635686895abb118e (diff)
Add check for extraneous .else's - based on patch from Arne H. Juul
in PR/24420. Add a unit-test for conditionals. Also in the unit-test makefile strip any .CURDIR in output. PR: 24420
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/cond.c14
-rw-r--r--usr.bin/make/unit-tests/Makefile10
-rw-r--r--usr.bin/make/unit-tests/cond137
-rw-r--r--usr.bin/make/unit-tests/test.exp4
4 files changed, 58 insertions, 7 deletions
diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c
index 4a9f1b08298..9ca36da59ad 100644
--- a/usr.bin/make/cond.c
+++ b/usr.bin/make/cond.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.19 2004/01/06 01:18:52 sjg Exp $ */
+/* $NetBSD: cond.c,v 1.20 2004/04/08 00:59:01 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
*/
#ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: cond.c,v 1.19 2004/01/06 01:18:52 sjg Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.20 2004/04/08 00:59:01 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
#else
-__RCSID("$NetBSD: cond.c,v 1.19 2004/01/06 01:18:52 sjg Exp $");
+__RCSID("$NetBSD: cond.c,v 1.20 2004/04/08 00:59:01 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -173,6 +173,7 @@ static Token condPushBack=None; /* Single push-back token used in
#define MAXIF 30 /* greatest depth of #if'ing */
+static Boolean finalElse[MAXIF+1]; /* Seen final else (stack) */
static Boolean condStack[MAXIF]; /* Stack of conditionals's values */
static int condTop = MAXIF; /* Top-most conditional */
static int skipIfLevel=0; /* Depth of skipped conditionals */
@@ -1232,6 +1233,7 @@ Cond_Eval(char *line)
* so we return COND_PARSE, unless this endif isn't paired with
* a decent if.
*/
+ finalElse[condTop] = FALSE;
if (skipIfLevel != 0) {
skipIfLevel -= 1;
return (COND_SKIP);
@@ -1266,6 +1268,11 @@ Cond_Eval(char *line)
* of the previous if we parsed.
*/
if (isElse && (line[0] == 's') && (line[1] == 'e')) {
+ if (finalElse[condTop]) {
+ Parse_Error (PARSE_WARNING, "extra else");
+ } else {
+ finalElse[condTop] = TRUE;
+ }
if (condTop == MAXIF) {
Parse_Error (level, "if-less else");
return (COND_INVALID);
@@ -1315,6 +1322,7 @@ Cond_Eval(char *line)
}
if (!isElse) {
condTop -= 1;
+ finalElse[condTop] = FALSE;
} else if ((skipIfLevel != 0) || condStack[condTop]) {
/*
* If this is an else-type conditional, it should only take effect
diff --git a/usr.bin/make/unit-tests/Makefile b/usr.bin/make/unit-tests/Makefile
index a00c3a77a53..e11b381e85d 100644
--- a/usr.bin/make/unit-tests/Makefile
+++ b/usr.bin/make/unit-tests/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.11 2004/02/20 09:03:26 sjg Exp $
+# $Id: Makefile,v 1.12 2004/04/08 00:59:01 sjg Exp $
#
# Unit tests for make(1)
# The main targets are:
@@ -19,6 +19,7 @@ UNIT_TESTS:= ${.PARSEDIR}
# Simple sub-makefiles - we run them as a black box
# keep the list sorted.
SUBFILES= \
+ cond1 \
modmatch \
modts \
modword \
@@ -40,12 +41,13 @@ clean:
TEST_MAKE?= ${MAKE}
# The driver.
-# We always pretend .MAKE was called 'make' so the results
-# can be compared.
+# We always pretend .MAKE was called 'make'
+# and strip ${.CURDIR}/ from the output
+# so the results can be compared.
test:
@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
- sed 's,^${TEST_MAKE:T}:,make:,' > ${.TARGET}.out || { \
+ sed -e 's,^${TEST_MAKE:T}:,make:,' -e 's,${.CURDIR}/,,g' > ${.TARGET}.out || { \
tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
diff --git a/usr.bin/make/unit-tests/cond1 b/usr.bin/make/unit-tests/cond1
new file mode 100644
index 00000000000..04bb6d25bfa
--- /dev/null
+++ b/usr.bin/make/unit-tests/cond1
@@ -0,0 +1,37 @@
+# $Id: cond1,v 1.1 2004/04/08 00:59:01 sjg Exp $
+
+PRIMES=2 3 5 7 11
+NUMBERS=1 2 3 4 5
+
+n=2
+.if ${PRIMES:M$n} == ""
+X=not
+.else
+X=
+.endif
+
+# We expect an extra else warning
+.if ${MACHINE_ARCH} == no-such
+A=one
+.else
+A=other
+.else
+A=this should be an error
+.endif
+
+# We expect an extra else warning
+.if $X != ""
+.if ${MACHINE_ARCH} == no-such
+B=one
+.else
+B=other
+.else
+B=this should be an error
+.endif
+.else
+B=unknown
+.endif
+
+all:
+ @echo "$n is $X prime"
+ @echo "A='$A' B='$B'"
diff --git a/usr.bin/make/unit-tests/test.exp b/usr.bin/make/unit-tests/test.exp
index ee72c8daa84..bdfa7e41686 100644
--- a/usr.bin/make/unit-tests/test.exp
+++ b/usr.bin/make/unit-tests/test.exp
@@ -1,3 +1,7 @@
+make: "cond1" line 18: warning: extra else
+make: "cond1" line 28: warning: extra else
+2 is prime
+A='other' B='unknown'
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"