这个神奇的问题我也是找了很久才找到答案:
Recursive make
commands should always use the variable MAKE
, not the explicit command name ‘make’, as shown here:
subsystem: cd subdir && $(MAKE)
简单来说,当使用make -j4的时候,一个make进程会再启动2个make子进程,共同完成make工作。但是如果启动的make子进程不知道自己是make -j4的,他就开始弹出警告了。
In order for make
processes to communicate, the parent will pass information to the child. Since this could result in problems if the child process isn’t actually a make
, the parent will only do this if it thinks the child is a make
.
If the makefile is constructed such that the parent doesn’t know the child is a make
process, then the child will receive only part of the information necessary. In this case, the child will generate this warning message and proceed with its build in a sequential manner.
我来验证一下这个:
all: proj
echo hi
proj:
cd project && $(MAKE);
proj2:
cd project && make
然后在project目录下的makefile:
all:
echo $(MAKEFLAGS)
结果如下:
~/test$ /usr/bin/make -j5 proj2
cd project && make
make[1]: warning: jobserver unavailable: using -j1. Add '+' to parent make rule.
make[1]: Entering directory '/home/tiantian/test/project'
echo w -j1
w -j1
make[1]: Leaving directory '/home/tiantian/test/project'
~/test$ /usr/bin/make -j5 proj
cd project && /usr/bin/make;
make[1]: Entering directory '/home/tiantian/test/project'
echo w -j5 --jobserver-auth=3,6
w -j5 --jobserver-auth=3,6
make[1]: Leaving directory '/home/tiantian/test/project'
# cd project && make
可以看到,在使用了$(MAKE) 变量后,会将make -j4中的-j4传递下去。
即一个产生2个子进程,每个子进程再产生2个子进程,并行编译的效果最大化。