Module Name: src
Committed By: sjg
Date: Tue Sep 8 17:29:20 UTC 2009
Modified Files:
src/usr.bin/make: main.c make.1 make.h var.c
Log Message:
Reviewed by: apb
Use .MAKE.LEVEL to track recursion.
The first instance of make will have .MAKE.LEVEL 0, which
can be handy for excluding rules which should not apply
in a sub-make.
gmake and freebsd's make have a similar mechanism, but each
uses a different variable to track it. Since we cannot be
compatible with both, we allow the makefiles to cope if they want
by handling the export of .MAKE.LEVEL+1 in Var_Set().
To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/usr.bin/make/main.c
cvs rdiff -u -r1.160 -r1.161 src/usr.bin/make/make.1
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/make/make.h
cvs rdiff -u -r1.153 -r1.154 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.172 src/usr.bin/make/main.c:1.173
--- src/usr.bin/make/main.c:1.172 Thu Sep 3 06:45:23 2009
+++ src/usr.bin/make/main.c Tue Sep 8 17:29:20 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.172 2009/09/03 06:45:23 dholland Exp $ */
+/* $NetBSD: main.c,v 1.173 2009/09/08 17:29:20 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.172 2009/09/03 06:45:23 dholland Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.173 2009/09/08 17:29:20 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@@ -81,7 +81,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: main.c,v 1.172 2009/09/03 06:45:23 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.173 2009/09/08 17:29:20 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -916,7 +916,12 @@
*/
{
char tmp[64];
+ const char *ep;
+ if (!(ep = getenv(MAKE_LEVEL))) {
+ ep = "0";
+ }
+ Var_Set(MAKE_LEVEL, ep, VAR_GLOBAL, 0);
snprintf(tmp, sizeof(tmp), "%u", getpid());
Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0);
snprintf(tmp, sizeof(tmp), "%u", getppid());
Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.160 src/usr.bin/make/make.1:1.161
--- src/usr.bin/make/make.1:1.160 Wed Aug 26 23:18:57 2009
+++ src/usr.bin/make/make.1 Tue Sep 8 17:29:20 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: make.1,v 1.160 2009/08/26 23:18:57 sjg Exp $
+.\" $NetBSD: make.1,v 1.161 2009/09/08 17:29:20 sjg Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\"
-.Dd August 26, 2009
+.Dd September 7, 2009
.Dt MAKE 1
.Os
.Sh NAME
@@ -660,6 +660,17 @@
.Nm ,
which is useful for tracking dependencies.
Each makefile is recorded only once, regardless of the number of times read.
+.It Va .MAKE.LEVEL
+The recursion depth of
+.Nm .
+The initial instance of
+.Nm
+will be 0, and an incremented value is put into the environment
+to be seen by the next generation.
+This allows tests like:
+.Li .if ${.MAKE.LEVEL} == 0
+to protect things which should only be evaluated in the initial instance of
+.Nm .
.It Va .MAKE.PID
The process-id of
.Nm .
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.78 src/usr.bin/make/make.h:1.79
--- src/usr.bin/make/make.h:1.78 Sat Jan 24 14:43:28 2009
+++ src/usr.bin/make/make.h Tue Sep 8 17:29:20 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.78 2009/01/24 14:43:28 dsl Exp $ */
+/* $NetBSD: make.h,v 1.79 2009/09/08 17:29:20 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -398,6 +398,7 @@
#define MAKE_JOB_PREFIX ".MAKE.JOB.PREFIX" /* prefix for job target output */
#define MAKE_EXPORTED ".MAKE.EXPORTED" /* variables we export */
#define MAKE_MAKEFILES ".MAKE.MAKEFILES" /* all the makefiles we read */
+#define MAKE_LEVEL ".MAKE.LEVEL" /* recursion level */
/*
* debug control:
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.153 src/usr.bin/make/var.c:1.154
--- src/usr.bin/make/var.c:1.153 Mon Sep 7 17:56:24 2009
+++ src/usr.bin/make/var.c Tue Sep 8 17:29:20 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.153 2009/09/07 17:56:24 sjg Exp $ */
+/* $NetBSD: var.c,v 1.154 2009/09/08 17:29:20 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.153 2009/09/07 17:56:24 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.154 2009/09/08 17:29:20 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.153 2009/09/07 17:56:24 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.154 2009/09/08 17:29:20 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -811,6 +811,23 @@
Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL);
}
+ /*
+ * Another special case.
+ * Several make's support this sort of mechanism for tracking
+ * recursion - but each uses a different name.
+ * We allow the makefiles to update .MAKE.LEVEL and ensure
+ * children see a correctly incremented value.
+ */
+ if (ctxt == VAR_GLOBAL && strcmp(MAKE_LEVEL, name) == 0) {
+ char tmp[64];
+ int level;
+
+ level = atoi(val);
+ snprintf(tmp, sizeof(tmp), "%u", level + 1);
+ setenv(MAKE_LEVEL, tmp, 1);
+ }
+
+
out:
if (expanded_name != NULL)
free(expanded_name);