Module Name:    src
Committed By:   rillig
Date:           Sun Nov  8 23:38:02 UTC 2020

Modified Files:
        src/usr.bin/make: main.c make.h parse.c var.c

Log Message:
make(1): move lint option away from the debug flags

The lint option affects much more than a typical debug flag.  Not only
does it produce additional diagnostics, it also changes the control flow
and fixes the traditional error handling in a few places.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.454 -r1.455 src/usr.bin/make/main.c
cvs rdiff -u -r1.203 -r1.204 src/usr.bin/make/make.h
cvs rdiff -u -r1.436 -r1.437 src/usr.bin/make/parse.c
cvs rdiff -u -r1.682 -r1.683 src/usr.bin/make/var.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.454 src/usr.bin/make/main.c:1.455
--- src/usr.bin/make/main.c:1.454	Sun Nov  8 15:07:37 2020
+++ src/usr.bin/make/main.c	Sun Nov  8 23:38:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.454 2020/11/08 15:07:37 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.455 2020/11/08 23:38:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.454 2020/11/08 15:07:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.455 2020/11/08 23:38:02 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -250,10 +250,10 @@ parse_debug_options(const char *argvalue
 	for (modules = argvalue; *modules; ++modules) {
 		switch (*modules) {
 		case '0':	/* undocumented, only intended for tests */
-			opts.debug &= DEBUG_LINT;
+			opts.debug = DEBUG_NONE;
 			break;
 		case 'A':
-			opts.debug = ~(0 | DEBUG_LINT);
+			opts.debug = DEBUG_ALL;
 			break;
 		case 'a':
 			opts.debug |= DEBUG_ARCH;
@@ -292,7 +292,7 @@ parse_debug_options(const char *argvalue
 			opts.debug |= DEBUG_JOB;
 			break;
 		case 'L':
-			opts.debug |= DEBUG_LINT;
+			opts.lint = TRUE;
 			break;
 		case 'l':
 			opts.debug |= DEBUG_LOUD;
@@ -1124,6 +1124,7 @@ CmdOpts_Init(void)
 	opts.compatMake = FALSE;	/* No compat mode */
 	opts.debug = 0;			/* No debug verbosity, please. */
 	/* opts.debug_file has been initialized earlier */
+	opts.lint = FALSE;
 	opts.debugVflag = FALSE;
 	opts.checkEnvFirst = FALSE;
 	opts.makefiles = Lst_New();
@@ -1649,7 +1650,7 @@ main_CleanUp(void)
 static int
 main_Exit(Boolean outOfDate)
 {
-	if (DEBUG(LINT) && (errors > 0 || Parse_GetFatals() > 0))
+	if (opts.lint && (errors > 0 || Parse_GetFatals() > 0))
 		return 2;	/* Not 1 so -q can distinguish error */
 	return outOfDate ? 1 : 0;
 }

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.203 src/usr.bin/make/make.h:1.204
--- src/usr.bin/make/make.h:1.203	Sun Nov  8 23:30:59 2020
+++ src/usr.bin/make/make.h	Sun Nov  8 23:38:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.203 2020/11/08 23:30:59 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.204 2020/11/08 23:38:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -496,6 +496,7 @@ extern pid_t myPid;
 #endif
 
 typedef enum DebugFlags {
+    DEBUG_NONE		= 0,
     DEBUG_ARCH		= 1 << 0,
     DEBUG_COND		= 1 << 1,
     DEBUG_CWD		= 1 << 2,
@@ -516,12 +517,7 @@ typedef enum DebugFlags {
     DEBUG_SUFF		= 1 << 17,
     DEBUG_TARG		= 1 << 18,
     DEBUG_VAR		= 1 << 19,
-
-    /* Runs make in strict mode, with additional checks and better error
-     * handling.  This is not the default mode to preserve compatibility.
-     *
-     * XXX: This is not really a debug flag, it doesn't belong here. */
-    DEBUG_LINT		= 1 << 20
+    DEBUG_ALL		= (1 << 20) - 1
 } DebugFlags;
 
 #define CONCAT(a,b)	a##b
@@ -572,6 +568,12 @@ typedef struct CmdOpts {
     /* -df: debug output is written here - default stderr */
     FILE *debug_file;
 
+    /* -dL: lint mode
+     *
+     * Runs make in strict mode, with additional checks and better error
+     * handling. */
+    Boolean lint;
+
     /* -dV: for the -V option, print unexpanded variable values */
     Boolean debugVflag;
 

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.436 src/usr.bin/make/parse.c:1.437
--- src/usr.bin/make/parse.c:1.436	Sun Nov  8 19:53:11 2020
+++ src/usr.bin/make/parse.c	Sun Nov  8 23:38:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.436 2020/11/08 19:53:11 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.437 2020/11/08 23:38:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.436 2020/11/08 19:53:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.437 2020/11/08 23:38:02 rillig Exp $");
 
 /* types and constants */
 
@@ -1884,7 +1884,7 @@ Parse_IsVar(const char *p, VarAssign *ou
 static void
 VarCheckSyntax(VarAssignOp type, const char *uvalue, GNode *ctxt)
 {
-    if (DEBUG(LINT)) {
+    if (opts.lint) {
 	if (type != VAR_SUBST && strchr(uvalue, '$') != NULL) {
 	    /* Check for syntax errors such as unclosed expressions or
 	     * unknown modifiers. */
@@ -3032,7 +3032,7 @@ ParseDependency(char *line)
      * Var_Parse does not print any parse errors in such a case.
      * It simply returns the special empty string var_Error,
      * which cannot be detected in the result of Var_Subst. */
-    eflags = DEBUG(LINT) ? VARE_WANTRES : VARE_WANTRES | VARE_UNDEFERR;
+    eflags = opts.lint ? VARE_WANTRES : VARE_WANTRES | VARE_UNDEFERR;
     (void)Var_Subst(line, VAR_CMDLINE, eflags, &expanded_line);
     /* TODO: handle errors */
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.682 src/usr.bin/make/var.c:1.683
--- src/usr.bin/make/var.c:1.682	Sun Nov  8 19:53:11 2020
+++ src/usr.bin/make/var.c	Sun Nov  8 23:38:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.682 2020/11/08 19:53:11 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.683 2020/11/08 23:38:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.682 2020/11/08 19:53:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.683 2020/11/08 23:38:02 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -2077,7 +2077,7 @@ ApplyModifier_Loop(const char **pp, Appl
 			    &args.tvar, NULL, NULL, NULL);
     if (res != VPR_OK)
 	return AMR_CLEANUP;
-    if (DEBUG(LINT) && strchr(args.tvar, '$') != NULL) {
+    if (opts.lint && strchr(args.tvar, '$') != NULL) {
 	Parse_Error(PARSE_FATAL,
 		    "In the :@ modifier of \"%s\", the variable name \"%s\" "
 		    "must not contain a dollar.",
@@ -3278,7 +3278,7 @@ ApplyModifiersIndirect(
      * is not accepted, but ${VAR:${M_1}:${M_2}} is.
      */
     if (mods[0] != '\0' && *p != '\0' && *p != ':' && *p != st->endc) {
-	if (DEBUG(LINT))
+	if (opts.lint)
 	    Parse_Error(PARSE_FATAL,
 			"Missing delimiter ':' after indirect modifier \"%.*s\"",
 			(int)(p - *inout_p), *inout_p);
@@ -3414,7 +3414,7 @@ ApplyModifiers(
 		  st.endc, st.v->name, st.val, *mod);
 	} else if (*p == ':') {
 	    p++;
-	} else if (DEBUG(LINT) && *p != '\0' && *p != endc) {
+	} else if (opts.lint && *p != '\0' && *p != endc) {
 	    Parse_Error(PARSE_FATAL,
 			"Missing delimiter ':' after modifier \"%.*s\"",
 			(int)(p - mod), mod);
@@ -3549,7 +3549,7 @@ ValidShortVarname(char varname, const ch
 	return VPR_OK;
     }
 
-    if (!DEBUG(LINT))
+    if (!opts.lint)
 	return VPR_PARSE_SILENT;
 
     if (varname == '$')
@@ -3597,7 +3597,7 @@ ParseVarnameShort(char startc, const cha
 	*pp += 2;
 
 	*out_FALSE_val = UndefinedShortVarValue(startc, ctxt, eflags);
-	if (DEBUG(LINT) && *out_FALSE_val == var_Error) {
+	if (opts.lint && *out_FALSE_val == var_Error) {
 	    Parse_Error(PARSE_FATAL, "Variable \"%s\" is undefined", name);
 	    *out_FALSE_res = VPR_UNDEF_MSG;
 	    return FALSE;
@@ -3654,7 +3654,7 @@ EvalUndefined(Boolean dynamic, const cha
 	return VPR_OK;
     }
 
-    if ((eflags & VARE_UNDEFERR) && DEBUG(LINT)) {
+    if ((eflags & VARE_UNDEFERR) && opts.lint) {
 	Parse_Error(PARSE_FATAL, "Variable \"%s\" is undefined", varname);
 	free(varname);
 	*out_val = var_Error;
@@ -3864,7 +3864,7 @@ Var_Parse(const char **pp, GNode *ctxt, 
      * variable value. */
     if (strchr(value, '$') != NULL && (eflags & VARE_WANTRES)) {
 	VarEvalFlags nested_eflags = eflags;
-	if (DEBUG(LINT))
+	if (opts.lint)
 	    nested_eflags &= ~(unsigned)VARE_UNDEFERR;
 	v->flags |= VAR_IN_USE;
 	(void)Var_Subst(value, ctxt, nested_eflags, &value);

Reply via email to