Makefile - 将作业参数传递给子 makefile
我有一个 makefile 调用多个其他 makefile。
我想将 -j 参数传递给其他 makefile 调用。
类似于 (make -j8):
all:
make -f libpng_linux.mk -j$(J)
其中 $(J) 是 -j8 中的值 8。我绝对发誓我以前做过这个,但我找不到我的例子。
$(MAKEFLAGS) 似乎包含 --jobserver-fds=3,4 -j 无论 -j2 或 -j8
编辑:可能的解决方案:
很快就会将此作为答案发布。
这似乎是一种不用担心的解决方案。调用主 makefile 时包括 -j8。对 make 的子调用应如下所示:
all:
+make -f libpng_linux.mk -j$(J)
注意 make 前面的“+”。当我尝试并行构建时,我注意到 make 抛出了一个警告: make[1]: warning: jobserver unavailable: using -j1.将“+”添加到父 make 规则中。
I have a makefile which calls multiple other makefiles.
I'd like to pass the -j param along to the other makefile calls.
Something like (make -j8):
all:
make -f libpng_linux.mk -j$(J)
Where $(J) is the value 8 from -j8. I absolutely swear I've done this before but I cannot locate my example.
$(MAKEFLAGS) seems to contain --jobserver-fds=3,4 -j regardless of what -j2 or -j8
Edit: Possible Solution:
Will post this as an answer soon.
It appears one solution to not worry about it. Include -j8 when you call the main makefile. The sub calls to make should look like this:
all:
+make -f libpng_linux.mk -j$(J)
Notice the "+" in front of make. I noticed make tossing a warning when I tried parallel builds: make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只有某些标志进入
$(MAKEFLAGS)
。不包括-j
,因为子制造商相互通信以确保发生适当数量的作业此外,您应该使用
$(MAKE)
而不是 < code>make,因为$(MAKE)
始终会计算出正确的可执行文件名称(可能不是make
)。Only certain flags go into
$(MAKEFLAGS)
.-j
isn't included because the sub-makes communicate with each other to ensure the appropriate number of jobs are occuringAlso, you should use
$(MAKE)
instead ofmake
, since$(MAKE)
will always evaluate to the correct executable name (which might not bemake
).“不要这样做”并不总是答案,但在这种情况下,至少对于 GNU
make
来说是这样。GNU make 父进程有一个内部 jobserver。如果顶级
Makefile
使用-j
运行,则子进程make
将与作业服务器通信并从中读取并行级别,而无需明确的-j
。与父作业服务器的持续协调对于核心利用率来说要好得多。例如,在使用
-j6
进行相同构建期间,父级可以运行 2 个作业,子级可以再运行 4 个作业,下一刻两者都可以分别运行 3 个作业,然后父级将运行 1 个作业,子级将运行 5 个作业。"Do not do that" is not always the answer, but in this case it is, at least for GNU
make
.GNU make parent process has an internal jobserver. If top-level
Makefile
is run with-j
, subprocessmake
s will talk to the jobserver and read a parallelism level from it, without an explicit-j
.Ongoing coordination with parent's jobserver is much better for core utilization. For example, during the same build with
-j6
, parent could be running 2 jobs and the child 4 more, next moment both could be running 3 jobs each, then a parent would run 1 and the child 5.