I have a makefile which calls multiple other makefiles.
I'd like to pass the -j param along to the other makefile calls.
Something like (make -j8):
all:
make -f libpng_linux.mk -j$(J)
Where $(J) is the value 8 from -j8. I absolutely swear I've done this before but I cannot locate my example.
$(MAKEFLAGS) seems to contain --jobserver-fds=3,4 -j regardless of what -j2 or -j8
Edit: Possible Solution:
Will post this as an answer soon.
It appears one solution to not worry about it. Include -j8 when you call the main makefile. The sub calls to make should look like this:
all:
+make -f libpng_linux.mk -j$(J)
Notice the "+" in front of make. I noticed make tossing a warning when I tried parallel builds: make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
"Do not do that" is not always the answer, but in this case it is, at least for GNU
make
.GNU make parent process has an internal jobserver. If top-level
Makefile
is run with-j
, subprocessmake
s will talk to the jobserver and read a parallelism level from it, without an explicit-j
.Ongoing coordination with parent's jobserver is much better for core utilization. For example, during the same build with
-j6
, parent could be running 2 jobs and the child 4 more, next moment both could be running 3 jobs each, then a parent would run 1 and the child 5.Only certain flags go into
$(MAKEFLAGS)
.-j
isn't included because the sub-makes communicate with each other to ensure the appropriate number of jobs are occuringAlso, you should use
$(MAKE)
instead ofmake
, since$(MAKE)
will always evaluate to the correct executable name (which might not bemake
).