本文介绍了在递归制作中,防止-j级联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个顶级makefile,它为并行构建指定了-jn.这个顶层的makefile调用许多不同的组件makefile.不同的组件来自不同的存储库,其中一些支持并行构建,而另一些则不支持.我可以在顶层指定-j1以使所有组件正常工作.但是,有没有一种方法可以在顶层指定-jn,让该标志级联到某些组件,而对其他组件强制使用-j1呢?如果我在选定的较低级别的生成文件中使用NOTPARALLEL phony目标,那么该命令仅对那些组件强制使用-j1吗?

I have a top-level makefile which specifies -jn for parallel build. This top level makefile calls many different component makefiles. Different components come from different repositories, and some of them support parallel build, while others do not. I could specify -j1 at the top level to make all components to work. But is there a way to specify -jn at the top level, let the flag cascade down to some components, but enforce -j1 for other components? If I use NOTPARALLEL phony target in selected lower-level makefiles, will that enforce -j1 only for those components?

推荐答案

是的.从GNU制定特殊目标页面:

Yes. From GNU Make Special Targets page:

如果提及.NOTPARALLEL作为目标,那么即使给出'-j'选项,make的调用也将连续运行.任何递归调用的make命令仍将并行运行配方(除非其makefile也包含此目标)

If .NOTPARALLEL is mentioned as a target, then this invocation of make will be run serially, even if the ‘-j’ option is given. Any recursively invoked make command will still run recipes in parallel (unless its makefile also contains this target)

值得一提的是,对于那些没有设置.NOTPARALLEL的讨厌的第三方库,有一种方法可以通过递归make命令传递多个文件来实现:

It's worth mentioning that for those pesky 3rd-party libraries that don't set .NOTPARALLEL themselves properly there is a way to do it by passing multiple files the the recursive make command:

  1. 创建内容为".NOTPARALLEL"的文件,例如notparallel.mk
  2. 在制作库的食谱中,执行 $(MAKE)-f lib.mk -f notparallel.mk

这将确保在不修改该库本身的情况下,将.NOTPARALLEL称为该make调用的目标.

That'll ensure .NOTPARALLEL is mentioned as a target for that make invocation, without you modifying that library per se.

这篇关于在递归制作中,防止-j级联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 03:47