Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Reviewed by: apb
details: https://anonhg.NetBSD.org/src/rev/0f9ec796266c
branches: trunk
changeset: 747285:0f9ec796266c
user: sjg <sjg%NetBSD.org@localhost>
date: Tue Sep 08 17:29:20 2009 +0000
description:
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().
diffstat:
usr.bin/make/main.c | 11 ++++++++---
usr.bin/make/make.1 | 15 +++++++++++++--
usr.bin/make/make.h | 3 ++-
usr.bin/make/var.c | 23 ++++++++++++++++++++---
4 files changed, 43 insertions(+), 9 deletions(-)
diffs (143 lines):
diff -r 78bf1c58ea38 -r 0f9ec796266c usr.bin/make/main.c
--- a/usr.bin/make/main.c Tue Sep 08 17:16:33 2009 +0000
+++ b/usr.bin/make/main.c Tue Sep 08 17:29:20 2009 +0000
@@ -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());
diff -r 78bf1c58ea38 -r 0f9ec796266c usr.bin/make/make.1
--- a/usr.bin/make/make.1 Tue Sep 08 17:16:33 2009 +0000
+++ b/usr.bin/make/make.1 Tue Sep 08 17:29:20 2009 +0000
@@ -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 .
diff -r 78bf1c58ea38 -r 0f9ec796266c usr.bin/make/make.h
--- a/usr.bin/make/make.h Tue Sep 08 17:16:33 2009 +0000
+++ b/usr.bin/make/make.h Tue Sep 08 17:29:20 2009 +0000
@@ -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:
diff -r 78bf1c58ea38 -r 0f9ec796266c usr.bin/make/var.c
--- a/usr.bin/make/var.c Tue Sep 08 17:16:33 2009 +0000
+++ b/usr.bin/make/var.c Tue Sep 08 17:29:20 2009 +0000
@@ -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);
Home |
Main Index |
Thread Index |
Old Index