Consider the following contrived Makefile:
.PHONY: all one two
SLEEP = 2
all: one two
one two:
@sleep $(SLEEP)
@echo $@
Running this with make -j 2 all
gets both jobs done in the time it takes to run either of them because they are both running in parallel. This works great if you control the invocation of make and remember to do it every time, but not if all you control is the Makefile.
Setting the MAKEFLAGS environment variable can also control this:
$ export MAKEFLAGS="-j 2"
$ make all
However setting this value in the Makefile does not seem to work:
MAKEFLAGS = -j 2
Fail.
export MAKEFLAGS="-j 2"
Fail.
Setting JOBS likewise doesn't seem to have any effect. Is there any way to control the default number of jobs run from inside a Makefile?
Note I'm aware that I could use a dummy recipe and invoke a recursive make from inside it, but that would introduce a giant amount of mess because I would need to set it up for a whole bunch of possible targets, and I'm dealing with included Makefiles that don't necessarily play nice with recursion.