From ecb0e97ca6646d2efa3b5168b96abcf2ce2e5eb0 Mon Sep 17 00:00:00 2001 From: rillig Date: Fri, 13 Nov 2020 09:01:59 +0000 Subject: [PATCH] make(1): in lint mode, check for ".else " --- usr.bin/make/cond.c | 8 +++++--- usr.bin/make/unit-tests/directive-else.exp | 13 ++++++++----- usr.bin/make/unit-tests/directive-else.mk | 4 +++- usr.bin/make/unit-tests/objdir-writable.mk | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c index e107391fb743..a1b0d75dcb09 100644 --- a/usr.bin/make/cond.c +++ b/usr.bin/make/cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.213 2020/11/13 07:52:03 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.214 2020/11/13 09:01:59 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -94,7 +94,7 @@ #include "dir.h" /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: cond.c,v 1.213 2020/11/13 07:52:03 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.214 2020/11/13 09:01:59 rillig Exp $"); /* * The parsing of conditional expressions is based on this grammar: @@ -1151,7 +1151,9 @@ Cond_EvalLine(const char *const line) p += 2; if (is_token(p, "se", 2)) { /* It is an 'else'. */ - /* TODO: check for extraneous */ + if (opts.lint && p[2] != '\0') + Parse_Error(PARSE_FATAL, + "The .else directive does not take arguments."); if (cond_depth == cond_min_depth) { Parse_Error(PARSE_FATAL, "if-less else"); diff --git a/usr.bin/make/unit-tests/directive-else.exp b/usr.bin/make/unit-tests/directive-else.exp index 387577099b81..ca60595745a9 100644 --- a/usr.bin/make/unit-tests/directive-else.exp +++ b/usr.bin/make/unit-tests/directive-else.exp @@ -1,8 +1,11 @@ -make: "directive-else.mk" line 10: ok -make: "directive-else.mk" line 14: ok -make: "directive-else.mk" line 20: if-less else -make: "directive-else.mk" line 26: ok -make: "directive-else.mk" line 27: warning: extra else +make: "directive-else.mk" line 11: The .else directive does not take arguments. +make: "directive-else.mk" line 12: ok +make: "directive-else.mk" line 16: ok +make: "directive-else.mk" line 17: The .else directive does not take arguments. +make: "directive-else.mk" line 22: if-less else +make: "directive-else.mk" line 28: ok +make: "directive-else.mk" line 29: warning: extra else +make: "directive-else.mk" line 42: The .else directive does not take arguments. make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/usr.bin/make/unit-tests/directive-else.mk b/usr.bin/make/unit-tests/directive-else.mk index 3d20551b9797..fdd94007a1fa 100644 --- a/usr.bin/make/unit-tests/directive-else.mk +++ b/usr.bin/make/unit-tests/directive-else.mk @@ -1,7 +1,9 @@ -# $NetBSD: directive-else.mk,v 1.5 2020/11/13 08:35:34 rillig Exp $ +# $NetBSD: directive-else.mk,v 1.6 2020/11/13 09:01:59 rillig Exp $ # # Tests for the .else directive. +.MAKEFLAGS: -dL # To enable the check for ".else " + # The .else directive does not take any arguments. # As of 2020-08-29, make doesn't warn about this. .if 0 diff --git a/usr.bin/make/unit-tests/objdir-writable.mk b/usr.bin/make/unit-tests/objdir-writable.mk index f40c50aea099..fac55fa2ea47 100644 --- a/usr.bin/make/unit-tests/objdir-writable.mk +++ b/usr.bin/make/unit-tests/objdir-writable.mk @@ -1,4 +1,4 @@ -# $NetBSD: objdir-writable.mk,v 1.2 2020/11/12 23:53:17 sjg Exp $ +# $NetBSD: objdir-writable.mk,v 1.3 2020/11/13 09:01:59 rillig Exp $ # test checking for writable objdir @@ -22,6 +22,6 @@ ro-objdir: @MAKEOBJDIR=${RO_OBJDIR} ${.MAKE} -r -f /dev/null -C /tmp -V .OBJDIR MAKE_OBJDIR_CHECK_WRITABLE=no explicit-objdir: - @MAKEOBJDIR=/tmp ${.MAKE} -r -f ${MAKEFILE} -C /tmp do-objdir -V .OBJDIR + @MAKEOBJDIR=/tmp ${.MAKE} -r -f ${MAKEFILE:tA} -C /tmp do-objdir -V .OBJDIR .endif