jobserver unavailable: using -j1. Add `+‘ to parent make rule

这个神奇的问题我也是找了很久才找到答案:

makefile里面调用make

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个子进程,并行编译的效果最大化

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值