递归make调用中并行构建作业的数量 [英] Number of parallel build jobs in recursive make call

查看:110
本文介绍了递归make调用中并行构建作业的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个makefile,它将生成的构建文件包装在一个递归调用中,以便在构建文件的周围获取和释放许可证,而不管构建是否成功.示例:

I have a makefile which wraps the real build in a single recursive call, in order to grab and release a license around the build, regardless of whether the build succeeds. Example:

.PHONY main_target
main_target:
    @license_grab &
    @sleep 2
    -@$(MAKE) real_target
    @license_release

这很好用,直到我要并行运行make.在某些系统上它可以正常工作,但是在其他系统上,当将选项传递给子品牌:

This works great, until I want to run the make in parallel. On some systems it works fine, but on other systems I run into the documented problem with the -j flag when passing options to a sub-make:

如果您的操作系统不支持上述通信,则 "-j 1"总是放在MAKEFLAGS中,而不是您输入的值 指定的.这是因为如果将'-j'选项传递给 子品牌,您将获得比您并行运行的更多工作 要求.

If your operating system doesn’t support the above communication, then ‘-j 1’ is always put into MAKEFLAGS instead of the value you specified. This is because if the ‘-j’ option were passed down to sub-makes, you would get many more jobs running in parallel than you asked for.

由于我只有一个递归调用,所以我真的很想将未更改的-j标志传递给子make.我不想将-j标志(带有数字)硬编码到生成文件中,因为生成文件可在具有不同数量处理器的多台机器上运行.我不想无限制地使用-j,因为这会立即启动一堆进程,而不是等待作业完成.我在构建时尝试使用-l标志,但是我发现该限制并不立即适用,可能是因为限制没有申请,直到make可以开始采样.

Since I only ever have one recursive call, I'd really like to pass the -j flag untouched to the sub-make. I don't want to hard-code the -j flag (with a number) into the makefile, because the makefile runs on multiple machines, with differing numbers of processors. I don't want to use -j with no limit, because that launches a bunch of processes right away rather than waiting for jobs to finish. I tried using the -l flag when I build, but I found that the limit doesn't apply right away, probably because limits don't apply until make can start sampling.

是否有一种方法可以强制子品牌使用多个作业?或者,一种使-l标志实际完成某件事的方法?

Is there a way to force a sub-make to use multiple jobs? Or, a way to make the -l flag actually accomplish something?

我想我可以使用makefile修改(例如使用-@$(MAKE) $(JOBS) real_target)并调用make(例如make JOBS="-j4" main_target)来做到这一点.

I think I could do it using a makefile modification like using -@$(MAKE) $(JOBS) real_target, and invoking make like make JOBS="-j4" main_target.

但是,我宁愿只使用标准的make参数,而不要在变量上添加额外的依赖项.我也希望尽可能少地修改makefile.

But, I'd prefer to just use standard make parameters, not adding extra dependencies on variables. I'd also prefer to modify the makefile as little as possible.

推荐答案

问题是,无论出于什么原因,我的make不支持作业服务器,因此不会在-j标志>变量.由于升级到不能通过 标志的版本不是一种选择,因此解决方案是将-j标志传递到其他地方.就像可以滥用$(MAKE)变量来传递-f标志一样,也可以使用相同的方式传递-j标志:

The problem is that for whatever reason my make does not support the job server, thus it does not pass the -j flag on in the $(MAKEFLAGS) variable. Since upgrading make to a version that does pass the flag is not an option, the solution is to pass the -j flag elsewhere. Just like the $(MAKE) variable can be abused to pass the -f flag, it can be used in the same way to pass the -j flag:

make MAKE="make -j4" main_target

这将以一个作业开始main_target构建,但是在sub-make流程中以4个作业调用make.显然,如果您需要特殊的制作工具( $(MAKE)的正常用途,那么您需要在MAKE字符串以及命令中指定它.

This will start the main_target build with one job, but invoke make with 4 jobs on the sub-make process. Obviously, if you need a special make tool (the normal purpose of $(MAKE) then you'll need to specify it in the MAKE string as well as in the command.

这篇关于递归make调用中并行构建作业的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆