tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
make: add .MAKE.LEVEL
The patch below adds a means of tracking the level of recursion for
make.
It lets you protect things which should only be done by
the initial instance of make.
You can include it in .MAKE.JOB.PREFIX to help guage the level of
parallelism being achieved etc.
You can even test it for an unacceptible value.
Eg. if you want to ensure the top-level make is only visiting leaves
of the tree, you can throw an error for .MAKE.LEVEL > 1
As an example, the following
.PHONY: ${LIBBUG}
${LIBBUG}:
@echo making sure the libbug is up to date...
@(cd ${LIB_BUG_DIR}; ${MAKE})
in sys/arch/mvme68k/stand/Makefile.booters should be protected by
.if ${.MAKE.LEVEL} == 0
since while it might be handy when kicking off a build in say
sys/arch/mvme68k/stand/bootsd, it is dangerous in a full tree parallel
build, as multiple makes can end up playing in the same dir - which
usually ends in tears.
--sjg
Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/main.c,v
retrieving revision 1.172
diff -u -p -r1.172 main.c
--- main.c 3 Sep 2009 06:45:23 -0000 1.172
+++ main.c 8 Sep 2009 00:36:22 -0000
@@ -916,7 +916,19 @@ main(int argc, char **argv)
*/
{
char tmp[64];
+ int level = 0;
+ /*
+ * .MAKE.LEVEL should be 0 for the initial instance.
+ * It should increment with depth.
+ */
+ if ((cp = getenv(".MAKE.LEVEL"))) {
+ level = atoi(cp);
+ }
+ snprintf(tmp, sizeof(tmp), "%u", level);
+ Var_Set(".MAKE.LEVEL", tmp, VAR_GLOBAL, 0); /* what we see */
+ snprintf(tmp, sizeof(tmp), "%u", ++level);
+ setenv(".MAKE.LEVEL", tmp, 1); /* children see +1 */
snprintf(tmp, sizeof(tmp), "%u", getpid());
Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0);
snprintf(tmp, sizeof(tmp), "%u", getppid());
Index: make.1
===================================================================
RCS file: /cvsroot/src/usr.bin/make/make.1,v
retrieving revision 1.160
diff -u -p -r1.160 make.1
--- make.1 26 Aug 2009 23:18:57 -0000 1.160
+++ make.1 8 Sep 2009 00:36:23 -0000
@@ -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 @@ The list of makefiles read by
.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 .
Home |
Main Index |
Thread Index |
Old Index