Module Name:    src
Committed By:   rillig
Date:           Mon Sep 28 20:46:12 UTC 2020

Modified Files:
        src/usr.bin/make: arch.c compat.c cond.c dir.c for.c hash.c job.c
            main.c make.c make.h meta.c parse.c suff.c

Log Message:
make(1): make debugging code shorter


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/make/arch.c
cvs rdiff -u -r1.156 -r1.157 src/usr.bin/make/compat.c
cvs rdiff -u -r1.153 -r1.154 src/usr.bin/make/cond.c
cvs rdiff -u -r1.150 -r1.151 src/usr.bin/make/dir.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/make/for.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/make/hash.c
cvs rdiff -u -r1.249 -r1.250 src/usr.bin/make/job.c
cvs rdiff -u -r1.351 -r1.352 src/usr.bin/make/main.c
cvs rdiff -u -r1.151 -r1.152 src/usr.bin/make/make.c
cvs rdiff -u -r1.148 -r1.149 src/usr.bin/make/make.h
cvs rdiff -u -r1.120 -r1.121 src/usr.bin/make/meta.c
cvs rdiff -u -r1.340 -r1.341 src/usr.bin/make/parse.c
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/make/suff.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/arch.c
diff -u src/usr.bin/make/arch.c:1.124 src/usr.bin/make/arch.c:1.125
--- src/usr.bin/make/arch.c:1.124	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/arch.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.124 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.125 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -134,7 +134,7 @@
 #include    "config.h"
 
 /*	"@(#)arch.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: arch.c,v 1.124 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.125 2020/09/28 20:46:11 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -676,9 +676,7 @@ ArchSVR4Entry(Arch *ar, char *name, size
 	strncmp(name, ARLONGNAMES2, sizeof(ARLONGNAMES2) - 1) == 0) {
 
 	if (ar->fnametab != NULL) {
-	    if (DEBUG(ARCH)) {
-		fprintf(debug_file, "Attempted to redefine an SVR4 name table\n");
-	    }
+	    DEBUG0(ARCH, "Attempted to redefine an SVR4 name table\n");
 	    return -1;
 	}
 
@@ -690,9 +688,7 @@ ArchSVR4Entry(Arch *ar, char *name, size
 	ar->fnamesize = size;
 
 	if (fread(ar->fnametab, size, 1, arch) != 1) {
-	    if (DEBUG(ARCH)) {
-		fprintf(debug_file, "Reading an SVR4 name table failed\n");
-	    }
+	    DEBUG0(ARCH, "Reading an SVR4 name table failed\n");
 	    return -1;
 	}
 	eptr = ar->fnametab + size;
@@ -701,10 +697,8 @@ ArchSVR4Entry(Arch *ar, char *name, size
 		entry++;
 		*ptr = '\0';
 	    }
-	if (DEBUG(ARCH)) {
-	    fprintf(debug_file, "Found svr4 archive name table with %lu entries\n",
-		    (unsigned long)entry);
-	}
+	DEBUG1(ARCH, "Found svr4 archive name table with %lu entries\n",
+	       (unsigned long)entry);
 	return 0;
     }
 
@@ -713,22 +707,16 @@ ArchSVR4Entry(Arch *ar, char *name, size
 
     entry = (size_t)strtol(&name[1], &eptr, 0);
     if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) {
-	if (DEBUG(ARCH)) {
-	    fprintf(debug_file, "Could not parse SVR4 name %s\n", name);
-	}
+        DEBUG1(ARCH, "Could not parse SVR4 name %s\n", name);
 	return 2;
     }
     if (entry >= ar->fnamesize) {
-	if (DEBUG(ARCH)) {
-	    fprintf(debug_file, "SVR4 entry offset %s is greater than %lu\n",
+	DEBUG2(ARCH, "SVR4 entry offset %s is greater than %lu\n",
 		   name, (unsigned long)ar->fnamesize);
-	}
 	return 2;
     }
 
-    if (DEBUG(ARCH)) {
-	fprintf(debug_file, "Replaced %s with %s\n", name, &ar->fnametab[entry]);
-    }
+    DEBUG2(ARCH, "Replaced %s with %s\n", name, &ar->fnametab[entry]);
 
     snprintf(name, MAXPATHLEN + 1, "%s", &ar->fnametab[entry]);
     return 1;

Index: src/usr.bin/make/compat.c
diff -u src/usr.bin/make/compat.c:1.156 src/usr.bin/make/compat.c:1.157
--- src/usr.bin/make/compat.c:1.156	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/compat.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.156 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.157 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -99,7 +99,7 @@
 #include    "pathnames.h"
 
 /*	"@(#)compat.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: compat.c,v 1.156 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.157 2020/09/28 20:46:11 rillig Exp $");
 
 static GNode	    *curTarg = NULL;
 static void CompatInterrupt(int);
@@ -301,8 +301,7 @@ Compat_RunCommand(const char *cmdp, stru
     if (!doIt && NoExecute(gn)) {
 	return 0;
     }
-    if (DEBUG(JOB))
-	fprintf(debug_file, "Execute: '%s'\n", cmd);
+    DEBUG1(JOB, "Execute: '%s'\n", cmd);
 
     if (useShell) {
 	/*
@@ -532,18 +531,13 @@ Compat_Make(GNode *gn, GNode *pgn)
 	 * exist and when we were modified last. The criteria for datedness
 	 * are defined by the Make_OODate function.
 	 */
-	if (DEBUG(MAKE)) {
-	    fprintf(debug_file, "Examining %s...", gn->name);
-	}
+	DEBUG1(MAKE, "Examining %s...", gn->name);
 	if (! Make_OODate(gn)) {
 	    gn->made = UPTODATE;
-	    if (DEBUG(MAKE)) {
-		fprintf(debug_file, "up-to-date.\n");
-	    }
+	    DEBUG0(MAKE, "up-to-date.\n");
 	    goto cohorts;
-	} else if (DEBUG(MAKE)) {
-	    fprintf(debug_file, "out-of-date.\n");
-	}
+	} else
+	    DEBUG0(MAKE, "out-of-date.\n");
 
 	/*
 	 * If the user is just seeing if something is out-of-date, exit now

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.153 src/usr.bin/make/cond.c:1.154
--- src/usr.bin/make/cond.c:1.153	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/cond.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.153 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.154 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.153 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.154 2020/09/28 20:46:11 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -312,10 +312,7 @@ FuncExists(int argLen MAKE_ATTR_UNUSED, 
     char *path;
 
     path = Dir_FindFile(arg, dirSearchPath);
-    if (DEBUG(COND)) {
-	fprintf(debug_file, "exists(%s) result is \"%s\"\n",
-		arg, path ? path : "");
-    }
+    DEBUG2(COND, "exists(%s) result is \"%s\"\n", arg, path ? path : "");
     if (path != NULL) {
 	result = TRUE;
 	free(path);
@@ -549,8 +546,7 @@ EvalNotEmpty(CondParser *par, const char
 static Token
 EvalCompareNum(double lhs, const char *op, double rhs)
 {
-    if (DEBUG(COND))
-	fprintf(debug_file, "lhs = %f, rhs = %f, op = %.2s\n", lhs, rhs, op);
+    DEBUG3(COND, "lhs = %f, rhs = %f, op = %.2s\n", lhs, rhs, op);
 
     switch (op[0]) {
     case '!':
@@ -585,10 +581,7 @@ EvalCompareStr(const char *lhs, const ch
 	return TOK_ERROR;
     }
 
-    if (DEBUG(COND)) {
-	fprintf(debug_file, "lhs = \"%s\", rhs = \"%s\", op = %.2s\n",
-		lhs, rhs, op);
-    }
+    DEBUG3(COND, "lhs = \"%s\", rhs = \"%s\", op = %.2s\n", lhs, rhs, op);
     return (*op == '=') == (strcmp(lhs, rhs) == 0);
 }
 
@@ -987,8 +980,7 @@ CondParser_Eval(CondParser *par, Boolean
 {
     Token res;
 
-    if (DEBUG(COND))
-	fprintf(debug_file, "CondParser_Eval: %s\n", par->p);
+    DEBUG1(COND, "CondParser_Eval: %s\n", par->p);
 
     res = CondParser_Expr(par, TRUE);
     if (res != TOK_FALSE && res != TOK_TRUE)

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.150 src/usr.bin/make/dir.c:1.151
--- src/usr.bin/make/dir.c:1.150	Sun Sep 27 22:17:07 2020
+++ src/usr.bin/make/dir.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.150 2020/09/27 22:17:07 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.151 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -136,17 +136,11 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.150 2020/09/27 22:17:07 rillig Exp $");
-
-#define DIR_DEBUG0(fmt) \
-    if (!DEBUG(DIR)) (void) 0; else fprintf(debug_file, fmt)
-
-#define DIR_DEBUG1(fmt, arg1) \
-    if (!DEBUG(DIR)) (void) 0; else fprintf(debug_file, fmt, arg1)
-
-#define DIR_DEBUG2(fmt, arg1, arg2) \
-    if (!DEBUG(DIR)) (void) 0; else fprintf(debug_file, fmt, arg1, arg2)
+MAKE_RCSID("$NetBSD: dir.c,v 1.151 2020/09/28 20:46:11 rillig Exp $");
 
+#define DIR_DEBUG0(text) DEBUG0(DIR, text)
+#define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
+#define DIR_DEBUG2(fmt, arg1, arg2) DEBUG2(DIR, fmt, arg1, arg2)
 
 /*
  *	A search path consists of a list of CachedDir structures. A CachedDir

Index: src/usr.bin/make/for.c
diff -u src/usr.bin/make/for.c:1.88 src/usr.bin/make/for.c:1.89
--- src/usr.bin/make/for.c:1.88	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/for.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.88 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.89 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -61,7 +61,7 @@
 #include    "strlist.h"
 
 /*	"@(#)for.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: for.c,v 1.88 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.89 2020/09/28 20:46:11 rillig Exp $");
 
 typedef enum {
     FOR_SUB_ESCAPE_CHAR = 0x0001,
@@ -272,14 +272,12 @@ For_Accum(const char *line)
 	    continue;
 
 	if (strncmp(ptr, "endfor", 6) == 0 && (ch_isspace(ptr[6]) || !ptr[6])) {
-	    if (DEBUG(FOR))
-		(void)fprintf(debug_file, "For: end for %d\n", forLevel);
+	    DEBUG1(FOR, "For: end for %d\n", forLevel);
 	    if (--forLevel <= 0)
 		return FALSE;
 	} else if (strncmp(ptr, "for", 3) == 0 && ch_isspace(ptr[3])) {
 	    forLevel++;
-	    if (DEBUG(FOR))
-		(void)fprintf(debug_file, "For: new loop %d\n", forLevel);
+	    DEBUG1(FOR, "For: new loop %d\n", forLevel);
 	}
     }
 
@@ -436,8 +434,7 @@ ForIterate(void *v_arg, size_t *ret_len)
 
     *ret_len = Buf_Len(&cmds);
     cmds_str = Buf_Destroy(&cmds, FALSE);
-    if (DEBUG(FOR))
-	(void)fprintf(debug_file, "For: loop body:\n%s", cmds_str);
+    DEBUG1(FOR, "For: loop body:\n%s", cmds_str);
 
     arg->sub_next += strlist_num(&arg->vars);
 

Index: src/usr.bin/make/hash.c
diff -u src/usr.bin/make/hash.c:1.34 src/usr.bin/make/hash.c:1.35
--- src/usr.bin/make/hash.c:1.34	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/hash.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.c,v 1.34 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: hash.c,v 1.35 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -79,7 +79,7 @@
 #include "make.h"
 
 /*	"@(#)hash.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: hash.c,v 1.34 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.35 2020/09/28 20:46:11 rillig Exp $");
 
 /*
  * Forward references to local procedures that are used before they're
@@ -174,9 +174,7 @@ Hash_FindEntry(Hash_Table *t, const char
 	p = key;
 	chainlen = 0;
 #ifdef DEBUG_HASH_LOOKUP
-	if (DEBUG(HASH))
-		fprintf(debug_file, "%s: %p h=%x key=%s\n", __func__,
-		    t, h, key);
+	DEBUG4(HASH, "%s: %p h=%x key=%s\n", __func__, t, h, key);
 #endif
 	for (e = t->buckets[h & t->bucketsMask]; e != NULL; e = e->next) {
 		chainlen++;
@@ -223,9 +221,7 @@ Hash_CreateEntry(Hash_Table *t, const ch
 	p = key;
 	chainlen = 0;
 #ifdef DEBUG_HASH_LOOKUP
-	if (DEBUG(HASH))
-		fprintf(debug_file, "%s: %p h=%x key=%s\n", __func__,
-		    t, h, key);
+	DEBUG4(HASH, "%s: %p h=%x key=%s\n", __func__, t, h, key);
 #endif
 	for (e = t->buckets[h & t->bucketsMask]; e != NULL; e = e->next) {
 		chainlen++;
@@ -361,9 +357,8 @@ RebuildTable(Hash_Table *t)
 		}
 	}
 	free(oldhp);
-	if (DEBUG(HASH))
-		fprintf(debug_file, "%s: %p size=%d entries=%d maxchain=%d\n",
-			__func__, t, t->bucketsSize, t->numEntries, t->maxchain);
+	DEBUG5(HASH, "%s: %p size=%d entries=%d maxchain=%d\n",
+	       __func__, t, t->bucketsSize, t->numEntries, t->maxchain);
 	t->maxchain = 0;
 }
 
@@ -382,7 +377,6 @@ Hash_ForEach(Hash_Table *t, void (*actio
 void
 Hash_DebugStats(Hash_Table *t, const char *name)
 {
-    if (DEBUG(HASH))
-	fprintf(debug_file, "Hash_Table %s: size=%d numEntries=%d maxchain=%d\n",
-		name, t->bucketsSize, t->numEntries, t->maxchain);
+    DEBUG4(HASH, "Hash_Table %s: size=%d numEntries=%d maxchain=%d\n",
+	   name, t->bucketsSize, t->numEntries, t->maxchain);
 }

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.249 src/usr.bin/make/job.c:1.250
--- src/usr.bin/make/job.c:1.249	Mon Sep 28 00:06:36 2020
+++ src/usr.bin/make/job.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.249 2020/09/28 00:06:36 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.250 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.249 2020/09/28 00:06:36 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.250 2020/09/28 20:46:11 rillig Exp $");
 
 # define STATIC static
 
@@ -444,18 +444,13 @@ JobCondPassSig(int signo)
 {
     Job *job;
 
-    if (DEBUG(JOB)) {
-	(void)fprintf(debug_file, "JobCondPassSig(%d) called.\n", signo);
-    }
+    DEBUG1(JOB, "JobCondPassSig(%d) called.\n", signo);
 
     for (job = job_table; job < job_table_end; job++) {
 	if (job->job_state != JOB_ST_RUNNING)
 	    continue;
-	if (DEBUG(JOB)) {
-	    (void)fprintf(debug_file,
-			   "JobCondPassSig passing signal %d to child %d.\n",
-			   signo, job->pid);
-	}
+	DEBUG2(JOB, "JobCondPassSig passing signal %d to child %d.\n",
+	       signo, job->pid);
 	KILLPG(job->pid, signo);
     }
 }
@@ -878,10 +873,8 @@ JobFinish(Job *job, int status)
 {
     Boolean done, return_job_token;
 
-    if (DEBUG(JOB)) {
-	fprintf(debug_file, "Jobfinish: %d [%s], status %d\n",
-				job->pid, job->node->name, status);
-    }
+    DEBUG3(JOB, "Jobfinish: %d [%s], status %d\n",
+	   job->pid, job->node->name, status);
 
     if ((WIFEXITED(status) &&
 	 (((WEXITSTATUS(status) != 0) && !(job->flags & JOB_IGNERR)))) ||
@@ -926,10 +919,8 @@ JobFinish(Job *job, int status)
 
     if (done) {
 	if (WIFEXITED(status)) {
-	    if (DEBUG(JOB)) {
-		(void)fprintf(debug_file, "Process %d [%s] exited.\n",
-				job->pid, job->node->name);
-	    }
+	    DEBUG2(JOB, "Process %d [%s] exited.\n",
+		   job->pid, job->node->name);
 	    if (WEXITSTATUS(status) != 0) {
 		if (job->node != lastNode) {
 		    MESSAGE(stdout, job->node);
@@ -1860,10 +1851,7 @@ Job_CatchChildren(void)
 	return;
 
     while ((pid = waitpid((pid_t) -1, &status, WNOHANG | WUNTRACED)) > 0) {
-	if (DEBUG(JOB)) {
-	    (void)fprintf(debug_file, "Process %d exited/stopped status %x.\n", pid,
-	      status);
-	}
+	DEBUG2(JOB, "Process %d exited/stopped status %x.\n", pid, status);
 	JobReapChild(pid, status, TRUE);
     }
 }
@@ -1892,10 +1880,7 @@ JobReapChild(pid_t pid, int status, Bool
 	return;				/* not ours */
     }
     if (WIFSTOPPED(status)) {
-	if (DEBUG(JOB)) {
-	    (void)fprintf(debug_file, "Process %d (%s) stopped.\n",
-			  job->pid, job->node->name);
-	}
+	DEBUG2(JOB, "Process %d (%s) stopped.\n", job->pid, job->node->name);
 	if (!make_suspended) {
 	    switch (WSTOPSIG(status)) {
 	    case SIGTSTP:
@@ -2418,11 +2403,8 @@ JobInterrupt(int runINTERRUPT, int signo
 
 	JobDeleteTarget(gn);
 	if (job->pid) {
-	    if (DEBUG(JOB)) {
-		(void)fprintf(debug_file,
-			   "JobInterrupt passing signal %d to child %d.\n",
-			   signo, job->pid);
-	    }
+	    DEBUG2(JOB, "JobInterrupt passing signal %d to child %d.\n",
+		   signo, job->pid);
 	    KILLPG(job->pid, signo);
 	}
     }
@@ -2521,10 +2503,7 @@ JobRestartJobs(void)
     for (job = job_table; job < job_table_end; job++) {
 	if (job->job_state == JOB_ST_RUNNING &&
 		(make_suspended || job->job_suspended)) {
-	    if (DEBUG(JOB)) {
-		(void)fprintf(debug_file, "Restarting stopped job pid %d.\n",
-			job->pid);
-	    }
+	    DEBUG1(JOB, "Restarting stopped job pid %d.\n", job->pid);
 	    if (job->job_suspended) {
 		    (void)printf("*** [%s] Continued\n", job->node->name);
 		    (void)fflush(stdout);
@@ -2618,9 +2597,8 @@ JobTokenAdd(void)
     while (tok != '+' && read(tokenWaitJob.inPipe, &tok1, 1) == 1)
 	continue;
 
-    if (DEBUG(JOB))
-	fprintf(debug_file, "(%d) aborting %d, deposit token %c\n",
-	    getpid(), aborting, JOB_TOKENS[aborting]);
+    DEBUG3(JOB, "(%d) aborting %d, deposit token %c\n",
+	   getpid(), aborting, JOB_TOKENS[aborting]);
     while (write(tokenWaitJob.outPipe, &tok, 1) == -1 && errno == EAGAIN)
 	continue;
 }
@@ -2686,9 +2664,8 @@ Job_TokenWithdraw(void)
     int count;
 
     wantToken = 0;
-    if (DEBUG(JOB))
-	fprintf(debug_file, "Job_TokenWithdraw(%d): aborting %d, running %d\n",
-		getpid(), aborting, jobTokensRunning);
+    DEBUG3(JOB, "Job_TokenWithdraw(%d): aborting %d, running %d\n",
+	   getpid(), aborting, jobTokensRunning);
 
     if (aborting || (jobTokensRunning >= maxJobs))
 	return FALSE;
@@ -2700,15 +2677,13 @@ Job_TokenWithdraw(void)
 	if (errno != EAGAIN) {
 	    Fatal("job pipe read: %s", strerror(errno));
 	}
-	if (DEBUG(JOB))
-	    fprintf(debug_file, "(%d) blocked for token\n", getpid());
+	DEBUG1(JOB, "(%d) blocked for token\n", getpid());
 	return FALSE;
     }
 
     if (count == 1 && tok != '+') {
 	/* make being abvorted - remove any other job tokens */
-	if (DEBUG(JOB))
-	    fprintf(debug_file, "(%d) aborted by token %c\n", getpid(), tok);
+	DEBUG2(JOB, "(%d) aborted by token %c\n", getpid(), tok);
 	while (read(tokenWaitJob.inPipe, &tok1, 1) == 1)
 	    continue;
 	/* And put the stopper back */
@@ -2725,8 +2700,7 @@ Job_TokenWithdraw(void)
 	    continue;
 
     jobTokensRunning++;
-    if (DEBUG(JOB))
-	fprintf(debug_file, "(%d) withdrew token\n", getpid());
+    DEBUG1(JOB, "(%d) withdrew token\n", getpid());
     return TRUE;
 }
 

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.351 src/usr.bin/make/main.c:1.352
--- src/usr.bin/make/main.c:1.351	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/main.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.351 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.352 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #endif
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.351 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.352 2020/09/28 20:46:11 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
  The Regents of the University of California.  All rights reserved.");
@@ -1411,10 +1411,8 @@ main(int argc, char **argv)
 
 	if (!compatMake)
 	    Job_ServerStart(maxJobTokens, jp_0, jp_1);
-	if (DEBUG(JOB))
-	    fprintf(debug_file,
-		    "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n",
-		    jp_0, jp_1, maxJobs, maxJobTokens, compatMake ? 1 : 0);
+	DEBUG5(JOB, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n",
+	       jp_0, jp_1, maxJobs, maxJobTokens, compatMake ? 1 : 0);
 
 	if (!printVars)
 	    Main_ExportMAKEFLAGS(TRUE);	/* initial export */

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.151 src/usr.bin/make/make.c:1.152
--- src/usr.bin/make/make.c:1.151	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/make.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.151 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.152 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
 #include    "job.h"
 
 /*	"@(#)make.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: make.c,v 1.151 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.152 2020/09/28 20:46:11 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked = 1;
@@ -237,15 +237,11 @@ Make_OODate(GNode *gn)
 	 * If the node is a USE node it is *never* out of date
 	 * no matter *what*.
 	 */
-	if (DEBUG(MAKE)) {
-	    fprintf(debug_file, ".USE node...");
-	}
+	DEBUG0(MAKE, ".USE node...");
 	oodate = FALSE;
     } else if ((gn->type & OP_LIB) &&
 	       ((gn->mtime==0) || Arch_IsLib(gn))) {
-	if (DEBUG(MAKE)) {
-	    fprintf(debug_file, "library...");
-	}
+	DEBUG0(MAKE, "library...");
 
 	/*
 	 * always out of date if no children and :: target
@@ -258,12 +254,8 @@ Make_OODate(GNode *gn)
 	 * A target with the .JOIN attribute is only considered
 	 * out-of-date if any of its children was out-of-date.
 	 */
-	if (DEBUG(MAKE)) {
-	    fprintf(debug_file, ".JOIN node...");
-	}
-	if (DEBUG(MAKE)) {
-	    fprintf(debug_file, "source %smade...", gn->flags & CHILDMADE ? "" : "not ");
-	}
+	DEBUG0(MAKE, ".JOIN node...");
+	DEBUG1(MAKE, "source %smade...", gn->flags & CHILDMADE ? "" : "not ");
 	oodate = (gn->flags & CHILDMADE) ? TRUE : FALSE;
     } else if (gn->type & (OP_FORCE|OP_EXEC|OP_PHONY)) {
 	/*
@@ -346,9 +338,8 @@ MakeAddChild(void *gnp, void *lp)
     GNodeList *l = lp;
 
     if ((gn->flags & REMAKE) == 0 && !(gn->type & (OP_USE|OP_USEBEFORE))) {
-	if (DEBUG(MAKE))
-	    fprintf(debug_file, "MakeAddChild: need to examine %s%s\n",
-		gn->name, gn->cohort_num);
+	DEBUG2(MAKE, "MakeAddChild: need to examine %s%s\n",
+	       gn->name, gn->cohort_num);
 	Lst_Enqueue(l, gn);
     }
     return 0;
@@ -550,17 +541,13 @@ Make_Recheck(GNode *gn)
      */
     if (NoExecute(gn) || (gn->type & OP_SAVE_CMDS) ||
 	    (mtime == 0 && !(gn->type & OP_WAIT))) {
-	if (DEBUG(MAKE)) {
-	    fprintf(debug_file, " recheck(%s): update time from %s to now\n",
-		   gn->name, Targ_FmtTime(gn->mtime));
-	}
+	DEBUG2(MAKE, " recheck(%s): update time from %s to now\n",
+	       gn->name, Targ_FmtTime(gn->mtime));
 	gn->mtime = now;
     }
     else {
-	if (DEBUG(MAKE)) {
-	    fprintf(debug_file, " recheck(%s): current update time: %s\n",
-		   gn->name, Targ_FmtTime(gn->mtime));
-	}
+	DEBUG2(MAKE, " recheck(%s): current update time: %s\n",
+	       gn->name, Targ_FmtTime(gn->mtime));
     }
 #endif
     return mtime;
@@ -602,8 +589,7 @@ Make_Update(GNode *cgn)
     cname = Var_Value(TARGET, cgn, &p1);
     bmake_free(p1);
 
-    if (DEBUG(MAKE))
-	fprintf(debug_file, "Make_Update: %s%s\n", cgn->name, cgn->cohort_num);
+    DEBUG2(MAKE, "Make_Update: %s%s\n", cgn->name, cgn->cohort_num);
 
     /*
      * If the child was actually made, see what its modification time is
@@ -644,8 +630,7 @@ Make_Update(GNode *cgn)
 
 	if (!(pgn->flags & REMAKE)) {
 	    /* This parent isn't needed */
-	    if (DEBUG(MAKE))
-		fprintf(debug_file, "- not needed\n");
+	    DEBUG0(MAKE, "- not needed\n");
 	    continue;
 	}
 	if (mtime == 0 && !(cgn->type & OP_WAIT))
@@ -660,8 +645,7 @@ Make_Update(GNode *cgn)
 	 * the child build finishes.
 	 */
 	if (pgn->type & OP_MADE) {
-	    if (DEBUG(MAKE))
-		fprintf(debug_file, "- .MADE\n");
+	    DEBUG0(MAKE, "- .MADE\n");
 	    continue;
 	}
 
@@ -676,10 +660,8 @@ Make_Update(GNode *cgn)
 	 * of a `::' dependency.
 	 */
 	if (centurion->unmade_cohorts != 0 || centurion->made < MADE) {
-	    if (DEBUG(MAKE))
-		fprintf(debug_file,
-			"- centurion made %d, %d unmade cohorts\n",
-			centurion->made, centurion->unmade_cohorts);
+	    DEBUG2(MAKE, "- centurion made %d, %d unmade cohorts\n",
+		   centurion->made, centurion->unmade_cohorts);
 	    continue;
 	}
 
@@ -697,8 +679,7 @@ Make_Update(GNode *cgn)
 	/* We must always rescan the parents of .WAIT and .ORDER nodes. */
 	if (pgn->unmade != 0 && !(centurion->type & OP_WAIT)
 		&& !(centurion->flags & DONE_ORDER)) {
-	    if (DEBUG(MAKE))
-		fprintf(debug_file, "- unmade children\n");
+	    DEBUG0(MAKE, "- unmade children\n");
 	    continue;
 	}
 	if (pgn->made != DEFERRED) {
@@ -707,8 +688,7 @@ Make_Update(GNode *cgn)
 	     * or it on the RHS of a .WAIT directive
 	     * or it is already on the toBeMade list.
 	     */
-	    if (DEBUG(MAKE))
-		fprintf(debug_file, "- not deferred\n");
+	    DEBUG0(MAKE, "- not deferred\n");
 	    continue;
 	}
 	assert(pgn->order_pred != NULL);
@@ -876,9 +856,8 @@ MakeCheckOrder(void *v_bn, void *ignore 
 
     if (bn->made >= MADE || !(bn->flags & REMAKE))
 	return 0;
-    if (DEBUG(MAKE))
-	fprintf(debug_file, "MakeCheckOrder: Waiting for .ORDER node %s%s\n",
-		bn->name, bn->cohort_num);
+    DEBUG2(MAKE, "MakeCheckOrder: Waiting for .ORDER node %s%s\n",
+	   bn->name, bn->cohort_num);
     return 1;
 }
 
@@ -887,9 +866,8 @@ MakeBuildChild(void *v_cn, void *toBeMad
 {
     GNode *cn = v_cn;
 
-    if (DEBUG(MAKE))
-	fprintf(debug_file, "MakeBuildChild: inspect %s%s, made %d, type %x\n",
-	    cn->name, cn->cohort_num, cn->made, cn->type);
+    DEBUG4(MAKE, "MakeBuildChild: inspect %s%s, made %d, type %x\n",
+	   cn->name, cn->cohort_num, cn->made, cn->type);
     if (cn->made > DEFERRED)
 	return 0;
 
@@ -901,9 +879,7 @@ MakeBuildChild(void *v_cn, void *toBeMad
 	return 0;			/* but keep looking */
     }
 
-    if (DEBUG(MAKE))
-	fprintf(debug_file, "MakeBuildChild: schedule %s%s\n",
-		cn->name, cn->cohort_num);
+    DEBUG2(MAKE, "MakeBuildChild: schedule %s%s\n", cn->name, cn->cohort_num);
 
     cn->made = REQUESTED;
     if (toBeMade_next == NULL)
@@ -957,22 +933,17 @@ MakeStartJobs(void)
 	have_token = 1;
 
 	gn = Lst_Dequeue(toBeMade);
-	if (DEBUG(MAKE))
-	    fprintf(debug_file, "Examining %s%s...\n",
-		    gn->name, gn->cohort_num);
+	DEBUG2(MAKE, "Examining %s%s...\n", gn->name, gn->cohort_num);
 
 	if (gn->made != REQUESTED) {
-	    if (DEBUG(MAKE))
-		fprintf(debug_file, "state %d\n", gn->made);
+	    DEBUG1(MAKE, "state %d\n", gn->made);
 
 	    make_abort(gn, __LINE__);
 	}
 
 	if (gn->checked == checked) {
 	    /* We've already looked at this node since a job finished... */
-	    if (DEBUG(MAKE))
-		fprintf(debug_file, "already checked %s%s\n",
-			gn->name, gn->cohort_num);
+	    DEBUG2(MAKE, "already checked %s%s\n", gn->name, gn->cohort_num);
 	    gn->made = DEFERRED;
 	    continue;
 	}
@@ -986,16 +957,13 @@ MakeStartJobs(void)
 	    gn->made = DEFERRED;
 	    Lst_ForEachUntil(gn->children, MakeBuildChild, Lst_First(toBeMade));
 	    /* and drop this node on the floor */
-	    if (DEBUG(MAKE))
-		fprintf(debug_file, "dropped %s%s\n", gn->name, gn->cohort_num);
+	    DEBUG2(MAKE, "dropped %s%s\n", gn->name, gn->cohort_num);
 	    continue;
 	}
 
 	gn->made = BEINGMADE;
 	if (Make_OODate(gn)) {
-	    if (DEBUG(MAKE)) {
-		fprintf(debug_file, "out-of-date\n");
-	    }
+	    DEBUG0(MAKE, "out-of-date\n");
 	    if (queryFlag) {
 		return TRUE;
 	    }
@@ -1003,9 +971,7 @@ MakeStartJobs(void)
 	    Job_Make(gn);
 	    have_token = 0;
 	} else {
-	    if (DEBUG(MAKE)) {
-		fprintf(debug_file, "up-to-date\n");
-	    }
+	    DEBUG0(MAKE, "up-to-date\n");
 	    gn->made = UPTODATE;
 	    if (gn->type & OP_JOIN) {
 		/*
@@ -1097,9 +1063,8 @@ MakePrintStatus(void *gnp, void *v_error
 	return 0;
     }
 
-    if (DEBUG(MAKE))
-	fprintf(debug_file, "MakePrintStatus: %s%s has %d unmade children\n",
-		gn->name, gn->cohort_num, gn->unmade);
+    DEBUG3(MAKE, "MakePrintStatus: %s%s has %d unmade children\n",
+	   gn->name, gn->cohort_num, gn->unmade);
     /*
      * If printing cycles and came to one that has unmade children,
      * print out the cycle by recursing on its children.
@@ -1153,9 +1118,8 @@ Make_ExpandUse(GNodeList *targs)
 	    /* We've looked at this one already */
 	    continue;
 	gn->flags |= REMAKE;
-	if (DEBUG(MAKE))
-	    fprintf(debug_file, "Make_ExpandUse: examine %s%s\n",
-		    gn->name, gn->cohort_num);
+	DEBUG2(MAKE, "Make_ExpandUse: examine %s%s\n",
+	       gn->name, gn->cohort_num);
 
 	if (gn->type & OP_DOUBLEDEP)
 	    Lst_PrependAll(examine, gn->cohorts);
@@ -1222,9 +1186,8 @@ add_wait_dependency(GNodeListNode *owln,
     GNode *cn;
 
     for (cln = owln; (cn = cln->datum) != wn; cln = cln->next) {
-	if (DEBUG(MAKE))
-	    fprintf(debug_file, ".WAIT: add dependency %s%s -> %s\n",
-		    cn->name, cn->cohort_num, wn->name);
+	DEBUG3(MAKE, ".WAIT: add dependency %s%s -> %s\n",
+	       cn->name, cn->cohort_num, wn->name);
 
 	/* XXX: This pattern should be factored out, it repeats often */
 	Lst_Append(wn->children, cn);
@@ -1270,8 +1233,7 @@ Make_ProcessWait(GNodeList *targs)
 	if (pgn->flags & DONE_WAIT)
 	    continue;
 	pgn->flags |= DONE_WAIT;
-	if (DEBUG(MAKE))
-	    fprintf(debug_file, "Make_ProcessWait: examine %s\n", pgn->name);
+	DEBUG1(MAKE, "Make_ProcessWait: examine %s\n", pgn->name);
 
 	if (pgn->type & OP_DOUBLEDEP)
 	    Lst_PrependAll(examine, pgn->cohorts);
@@ -1371,8 +1333,7 @@ Make_Run(GNodeList *targs)
      * Print the final status of each target. E.g. if it wasn't made
      * because some inferior reported an error.
      */
-    if (DEBUG(MAKE))
-	 fprintf(debug_file, "done: errors %d\n", errors);
+    DEBUG1(MAKE, "done: errors %d\n", errors);
     if (errors == 0) {
 	Lst_ForEachUntil(targs, MakePrintStatus, &errors);
 	if (DEBUG(MAKE)) {

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.148 src/usr.bin/make/make.h:1.149
--- src/usr.bin/make/make.h:1.148	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/make.h	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.148 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.149 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -523,6 +523,30 @@ extern int debug;
 
 #define	DEBUG(module)	(debug & CONCAT(DEBUG_,module))
 
+#define DEBUG0(module, text) \
+    if (!DEBUG(module)) (void)0; \
+    else fprintf(debug_file, "%s", text)
+
+#define DEBUG1(module, fmt, arg1) \
+    if (!DEBUG(module)) (void)0; \
+    else fprintf(debug_file, fmt, arg1)
+
+#define DEBUG2(module, fmt, arg1, arg2) \
+    if (!DEBUG(module)) (void)0; \
+    else fprintf(debug_file, fmt, arg1, arg2)
+
+#define DEBUG3(module, fmt, arg1, arg2, arg3) \
+    if (!DEBUG(module)) (void)0; \
+    else fprintf(debug_file, fmt, arg1, arg2, arg3)
+
+#define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \
+    if (!DEBUG(module)) (void)0; \
+    else fprintf(debug_file, fmt, arg1, arg2, arg3, arg4)
+
+#define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \
+    if (!DEBUG(module)) (void)0; \
+    else fprintf(debug_file, fmt, arg1, arg2, arg3, arg4, arg5)
+
 #include "nonints.h"
 
 void Make_TimeStamp(GNode *, GNode *);

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.120 src/usr.bin/make/meta.c:1.121
--- src/usr.bin/make/meta.c:1.120	Sat Sep 26 17:15:20 2020
+++ src/usr.bin/make/meta.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.120 2020/09/26 17:15:20 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.121 2020/09/28 20:46:11 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -428,9 +428,7 @@ meta_needed(GNode *gn, const char *dname
     if ((gn->type & (OP_META|OP_SUBMAKE)) == OP_SUBMAKE) {
 	/* OP_SUBMAKE is a bit too aggressive */
 	if (Lst_ForEachUntil(gn->commands, is_submake, gn)) {
-	    if (DEBUG(META))
-		fprintf(debug_file, "Skipping meta for %s: .SUBMAKE\n",
-			gn->name);
+	    DEBUG1(META, "Skipping meta for %s: .SUBMAKE\n", gn->name);
 	    return FALSE;
 	}
     }
@@ -510,8 +508,7 @@ meta_create(BuildMon *pbm, GNode *gn)
 		      dname, tname, objdir);
 
 #ifdef DEBUG_META_MODE
-    if (DEBUG(META))
-	fprintf(debug_file, "meta_create: %s\n", fname);
+    DEBUG1(META, "meta_create: %s\n", fname);
 #endif
 
     if ((mf.fp = fopen(fname, "w")) == NULL)
@@ -930,9 +927,7 @@ fgetLine(char **bufp, size_t *szp, int o
 		newsz = ROUNDUP(fs.st_size, BUFSIZ);
 	    if (newsz <= bufsz)
 		return x;		/* truncated */
-	    if (DEBUG(META))
-		fprintf(debug_file, "growing buffer %zu -> %zu\n",
-			bufsz, newsz);
+	    DEBUG2(META, "growing buffer %zu -> %zu\n", bufsz, newsz);
 	    p = bmake_realloc(buf, newsz);
 	    if (p) {
 		*bufp = buf = p;
@@ -990,9 +985,7 @@ meta_ignore(GNode *gn, const char *p)
 	cached_realpath(p, fname); /* clean it up */
 	if (Lst_ForEachUntil(metaIgnorePaths, prefix_match, fname)) {
 #ifdef DEBUG_META_MODE
-	    if (DEBUG(META))
-		fprintf(debug_file, "meta_oodate: ignoring path: %s\n",
-			p);
+	    DEBUG1(META, "meta_oodate: ignoring path: %s\n", p);
 #endif
 	    return TRUE;
 	}
@@ -1008,9 +1001,7 @@ meta_ignore(GNode *gn, const char *p)
 	/* TODO: handle errors */
 	if (*pm) {
 #ifdef DEBUG_META_MODE
-	    if (DEBUG(META))
-		fprintf(debug_file, "meta_oodate: ignoring pattern: %s\n",
-			p);
+	    DEBUG1(META, "meta_oodate: ignoring pattern: %s\n", p);
 #endif
 	    free(pm);
 	    return TRUE;
@@ -1029,9 +1020,7 @@ meta_ignore(GNode *gn, const char *p)
 	/* TODO: handle errors */
 	if (*fm == '\0') {
 #ifdef DEBUG_META_MODE
-	    if (DEBUG(META))
-		fprintf(debug_file, "meta_oodate: ignoring filtered: %s\n",
-			p);
+	    DEBUG1(META, "meta_oodate: ignoring filtered: %s\n", p);
 #endif
 	    free(fm);
 	    return TRUE;
@@ -1121,8 +1110,7 @@ meta_oodate(GNode *gn, Boolean oodate)
     meta_name(gn, fname, sizeof(fname), dname, tname, dname);
 
 #ifdef DEBUG_META_MODE
-    if (DEBUG(META))
-	fprintf(debug_file, "meta_oodate: %s\n", fname);
+    DEBUG1(META, "meta_oodate: %s\n", fname);
 #endif
 
     if ((fp = fopen(fname, "r")) != NULL) {
@@ -1183,8 +1171,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 	    /* Delimit the record type. */
 	    p = buf;
 #ifdef DEBUG_META_MODE
-	    if (DEBUG(META))
-		fprintf(debug_file, "%s: %d: %s\n", fname, lineno, buf);
+	    DEBUG3(META, "%s: %d: %s\n", fname, lineno, buf);
 #endif
 	    strsep(&p, " ");
 	    if (have_filemon) {
@@ -1298,8 +1285,8 @@ meta_oodate(GNode *gn, Boolean oodate)
 		    Var_Set(lcwd_vname, lcwd, VAR_GLOBAL);
 		    Var_Set(ldir_vname, lcwd, VAR_GLOBAL);
 #ifdef DEBUG_META_MODE
-		    if (DEBUG(META))
-			fprintf(debug_file, "%s: %d: cwd=%s ldir=%s\n", fname, lineno, cwd, lcwd);
+		    DEBUG4(META, "%s: %d: cwd=%s ldir=%s\n",
+			   fname, lineno, cwd, lcwd);
 #endif
 		    break;
 
@@ -1342,9 +1329,8 @@ meta_oodate(GNode *gn, Boolean oodate)
 		    if (buf[0] == 'M') {
 			/* the target of the mv is a file 'W'ritten */
 #ifdef DEBUG_META_MODE
-			if (DEBUG(META))
-			    fprintf(debug_file, "meta_oodate: M %s -> %s\n",
-				    p, move_target);
+			DEBUG2(META, "meta_oodate: M %s -> %s\n",
+			       p, move_target);
 #endif
 			p = move_target;
 			goto check_write;
@@ -1365,9 +1351,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 		    DEQUOTE(p);
 		    DEQUOTE(link_src);
 #ifdef DEBUG_META_MODE
-		    if (DEBUG(META))
-			fprintf(debug_file, "meta_oodate: L %s -> %s\n",
-				link_src, p);
+		    DEBUG2(META, "meta_oodate: L %s -> %s\n", link_src, p);
 #endif
 		    /* FALLTHROUGH */
 		case 'W':		/* Write */
@@ -1411,8 +1395,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 		    p = link_src;
 		    link_src = NULL;
 #ifdef DEBUG_META_MODE
-		    if (DEBUG(META))
-			fprintf(debug_file, "meta_oodate: L src %s\n", p);
+		    DEBUG1(META, "meta_oodate: L src %s\n", p);
 #endif
 		    /* FALLTHROUGH */
 		case 'R':		/* Read */
@@ -1460,8 +1443,8 @@ meta_oodate(GNode *gn, Boolean oodate)
 
 			for (sdp = sdirs; *sdp && !found; sdp++) {
 #ifdef DEBUG_META_MODE
-			    if (DEBUG(META))
-				fprintf(debug_file, "%s: %d: looking for: %s\n", fname, lineno, *sdp);
+			    DEBUG3(META, "%s: %d: looking for: %s\n",
+				   fname, lineno, *sdp);
 #endif
 			    if (cached_stat(*sdp, &mst) == 0) {
 				found = 1;
@@ -1470,13 +1453,13 @@ meta_oodate(GNode *gn, Boolean oodate)
 			}
 			if (found) {
 #ifdef DEBUG_META_MODE
-			    if (DEBUG(META))
-				fprintf(debug_file, "%s: %d: found: %s\n", fname, lineno, p);
+			    DEBUG3(META, "%s: %d: found: %s\n",
+				   fname, lineno, p);
 #endif
 			    if (!S_ISDIR(mst.mst_mode) &&
 				mst.mst_mtime > gn->mtime) {
-				if (DEBUG(META))
-				    fprintf(debug_file, "%s: %d: file '%s' is newer than the target...\n", fname, lineno, p);
+				DEBUG3(META, "%s: %d: file '%s' is newer than the target...\n",
+				       fname, lineno, p);
 				oodate = TRUE;
 			    } else if (S_ISDIR(mst.mst_mode)) {
 				/* Update the latest directory. */
@@ -1508,8 +1491,8 @@ meta_oodate(GNode *gn, Boolean oodate)
 		 * meta data file.
 		 */
 		if (cmdNode == NULL) {
-		    if (DEBUG(META))
-			fprintf(debug_file, "%s: %d: there were more build commands in the meta data file than there are now...\n", fname, lineno);
+		    DEBUG2(META, "%s: %d: there were more build commands in the meta data file than there are now...\n",
+			   fname, lineno);
 		    oodate = TRUE;
 		} else {
 		    char *cmd = LstNode_Datum(cmdNode);
@@ -1524,8 +1507,8 @@ meta_oodate(GNode *gn, Boolean oodate)
 		    }
 		    if (hasOODATE) {
 			needOODATE = TRUE;
-			if (DEBUG(META))
-			    fprintf(debug_file, "%s: %d: cannot compare command using .OODATE\n", fname, lineno);
+			DEBUG2(META, "%s: %d: cannot compare command using .OODATE\n",
+			       fname, lineno);
 		    }
 		    (void)Var_Subst(cmd, gn, VARE_WANTRES|VARE_UNDEFERR, &cmd);
 		    /* TODO: handle errors */
@@ -1559,8 +1542,8 @@ meta_oodate(GNode *gn, Boolean oodate)
 			!hasOODATE &&
 			!(gn->type & OP_NOMETA_CMP) &&
 			strcmp(p, cmd) != 0) {
-			if (DEBUG(META))
-			    fprintf(debug_file, "%s: %d: a build command has changed\n%s\nvs\n%s\n", fname, lineno, p, cmd);
+			DEBUG4(META, "%s: %d: a build command has changed\n%s\nvs\n%s\n",
+			       fname, lineno, p, cmd);
 			if (!metaIgnoreCMDs)
 			    oodate = TRUE;
 		    }
@@ -1573,14 +1556,14 @@ meta_oodate(GNode *gn, Boolean oodate)
 		 * that weren't in the meta data file.
 		 */
 		if (!oodate && cmdNode != NULL) {
-		    if (DEBUG(META))
-			fprintf(debug_file, "%s: %d: there are extra build commands now that weren't in the meta data file\n", fname, lineno);
+		    DEBUG2(META, "%s: %d: there are extra build commands now that weren't in the meta data file\n",
+			   fname, lineno);
 		    oodate = TRUE;
 		}
 		CHECK_VALID_META(p);
 		if (strcmp(p, cwd) != 0) {
-		    if (DEBUG(META))
-			fprintf(debug_file, "%s: %d: the current working directory has changed from '%s' to '%s'\n", fname, lineno, p, curdir);
+		    DEBUG4(META, "%s: %d: the current working directory has changed from '%s' to '%s'\n",
+			   fname, lineno, p, curdir);
 		    oodate = TRUE;
 		}
 	    }
@@ -1588,14 +1571,12 @@ meta_oodate(GNode *gn, Boolean oodate)
 
 	fclose(fp);
 	if (!Lst_IsEmpty(missingFiles)) {
-	    if (DEBUG(META))
-		fprintf(debug_file, "%s: missing files: %s...\n",
+	    DEBUG2(META, "%s: missing files: %s...\n",
 			fname, (char *)LstNode_Datum(Lst_First(missingFiles)));
 	    oodate = TRUE;
 	}
 	if (!oodate && !have_filemon && filemonMissing) {
-	    if (DEBUG(META))
-		fprintf(debug_file, "%s: missing filemon data\n", fname);
+	    DEBUG1(META, "%s: missing filemon data\n", fname);
 	    oodate = TRUE;
 	}
     } else {
@@ -1609,8 +1590,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 		}
 	    }
 	    if (!cp) {
-		if (DEBUG(META))
-		    fprintf(debug_file, "%s: required but missing\n", fname);
+		DEBUG1(META, "%s: required but missing\n", fname);
 		oodate = TRUE;
 		needOODATE = TRUE;	/* assume the worst */
 	    }

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.340 src/usr.bin/make/parse.c:1.341
--- src/usr.bin/make/parse.c:1.340	Mon Sep 28 02:06:27 2020
+++ src/usr.bin/make/parse.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.340 2020/09/28 02:06:27 sjg Exp $	*/
+/*	$NetBSD: parse.c,v 1.341 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -132,7 +132,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.340 2020/09/28 02:06:27 sjg Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.341 2020/09/28 20:46:11 rillig Exp $");
 
 /* types and constants */
 
@@ -1164,8 +1164,7 @@ ParseDoDependency(char *line)
      */
     ParseSpecial specType = Not;
 
-    if (DEBUG(PARSE))
-	fprintf(debug_file, "ParseDoDependency(%s)\n", line);
+    DEBUG1(PARSE, "ParseDoDependency(%s)\n", line);
     tOp = 0;
 
     paths = NULL;
@@ -2221,9 +2220,8 @@ SetFilenameVars(const char *filename, co
     Var_Set(dirvar, dirname, VAR_GLOBAL);
     Var_Set(filevar, basename, VAR_GLOBAL);
 
-    if (DEBUG(PARSE))
-	fprintf(debug_file, "%s: ${%s} = `%s' ${%s} = `%s'\n",
-		__func__, dirvar, dirname, filevar, basename);
+    DEBUG5(PARSE, "%s: ${%s} = `%s' ${%s} = `%s'\n",
+	   __func__, dirvar, dirname, filevar, basename);
     free(freeIt);
 }
 
@@ -2407,8 +2405,7 @@ ParseTraditionalInclude(char *line)
     char	  *file = &line[silent + 7];
     char	  *all_files;
 
-    if (DEBUG(PARSE))
-	fprintf(debug_file, "%s: %s\n", __func__, file);
+    DEBUG2(PARSE, "%s: %s\n", __func__, file);
 
     /*
      * Skip over whitespace
@@ -2454,8 +2451,7 @@ ParseGmakeExport(char *line)
     char	  *variable = &line[6];
     char	  *value;
 
-    if (DEBUG(PARSE))
-	fprintf(debug_file, "%s: %s\n", __func__, variable);
+    DEBUG2(PARSE, "%s: %s\n", __func__, variable);
 
     /*
      * Skip over whitespace
@@ -2535,9 +2531,8 @@ ParseEOF(void)
     }
 
     curFile = Stack_Pop(&includes);
-    if (DEBUG(PARSE))
-	fprintf(debug_file, "ParseEOF: returning to file %s, line %d\n",
-	    curFile->fname, curFile->lineno);
+    DEBUG2(PARSE, "ParseEOF: returning to file %s, line %d\n",
+	   curFile->fname, curFile->lineno);
 
     ParseSetParseFile(curFile->fname);
     return CONTINUE;
@@ -2849,9 +2844,7 @@ Parse_File(const char *name, int fd)
 
     do {
 	for (; (line = ParseReadLine()) != NULL; ) {
-	    if (DEBUG(PARSE))
-		fprintf(debug_file, "ParseReadLine (%d): '%s'\n",
-			curFile->lineno, line);
+	    DEBUG2(PARSE, "ParseReadLine (%d): '%s'\n", curFile->lineno, line);
 	    if (*line == '.') {
 		/*
 		 * Lines that begin with the special character may be

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.170 src/usr.bin/make/suff.c:1.171
--- src/usr.bin/make/suff.c:1.170	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/suff.c	Mon Sep 28 20:46:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.170 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.171 2020/09/28 20:46:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -129,19 +129,12 @@
 #include	  "dir.h"
 
 /*	"@(#)suff.c	8.4 (Berkeley) 3/21/94"	*/
-MAKE_RCSID("$NetBSD: suff.c,v 1.170 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.171 2020/09/28 20:46:11 rillig Exp $");
 
-#define SUFF_DEBUG0(fmt) \
-    if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt)
-
-#define SUFF_DEBUG1(fmt, arg1) \
-    if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt, arg1)
-
-#define SUFF_DEBUG2(fmt, arg1, arg2) \
-    if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt, arg1, arg2)
-
-#define SUFF_DEBUG3(fmt, arg1, arg2, arg3) \
-    if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt, arg1, arg2, arg3)
+#define SUFF_DEBUG0(text) DEBUG0(SUFF, text)
+#define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1)
+#define SUFF_DEBUG2(fmt, arg1, arg2) DEBUG2(SUFF, fmt, arg1, arg2)
+#define SUFF_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(SUFF, fmt, arg1, arg2, arg3)
 
 typedef List SuffList;
 typedef ListNode SuffListNode;

Reply via email to