有gnu make的配置文件吗?
我想告诉 make 它应该始终使用 -j4
选项,即使我没有在命令行中指定它。通常我会在一些配置文件(即~/.makerc
)中执行此操作。
gnu make 是否存在这样的文件?
I want to tell make that it shall always use -j4
option even if I didn't specify it vie command line. Normally i would do this in some configuration file (i.e. ~/.makerc
).
Does such file exist for gnu make?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
阅读有关 $(MAKEFLAGS) 变量的信息:
然而,这个可能会干扰基于递归 make 的构建(无论如何,明智的人都不会使用递归 make!),通过干扰 GNU make 与其通信的能力子品牌。
因此,更明智的方法可能是包装脚本或别名或 shell 函数。
Have a read about the $(MAKEFLAGS) variable:
However this will likely interfere with recursive-make-based builds (not that sensible people are using recursive make anyway!), by interfering with GNU make's ability to communicate with its sub-makes.
So the more sensible approach is probably a wrapper script or an alias or shell function.
嗯,是和否——通常您会使用 包含文件。< /a> 将常用配置项放在一个文件中,例如
common.mk
并添加到 makefile 的顶部。如果该标志没有匹配的方法来从 make 文件内部配置它,您可以使用一个函数
Well, yes and no --- normally you would use an include file. Put your common configuration items together in a file, say
common.mk
and addat the top of your makefile. If the flag doesn't have a matching way to configure it from inside the make file, you can use a function
它不存在,但您可以通过递归调用 make 来完成此操作。
例如:
Makefile:
$(HOME)/.makerc:
It doesn't exist, but you can do this by having a recursive call into make.
For example:
Makefile:
$(HOME)/.makerc:
我想对约翰·马歇尔的答案中暗示的解决方案进行一些扩展。
您可以简单地将单行包装脚本放在
$PATH
中较早的位置,其中包含以下内容:(该脚本不必命名为
make
,这将使它更简单,但我发现它很方便。)我认为这比其他方法更好,原因如下:
MAKEFLAGS
方法不同,它不会破坏递归构建(这是实际上根据我的经验很常见)。include .makerc
方法不同,它可以在本地应用,而无需以任何方式更改任何现有的 makefile 或您的工作流程。I would like to expand a bit on the solution hinted in John Marshall's answer.
You can simply put a one-line wrapper script somewhere earlier in the
$PATH
with the following contents:(The script doesn't have to be named
make
, and that would make it simpler, but I find it convenient if it is.)I would argue that this is better than the other approaches for the following reasons:
MAKEFLAGS
approach, it does not break recursive builds (which are actually quite common in my experience).include .makerc
approach, it can be applied locally without changing any existing makefiles or your workflow in any way.我喜欢 John Marshall 建议的
MAKEFLAGS
方法来代替make
支持自动 .makerc 项目配置文件之类的东西。但是,我不想记住事先获取 .env 或类似的环境变量(然后取消设置它们)。解决方案是将
MAKEFLAGS
赋值放在Makefile
本身的顶部:运行它:
与不使用
MAKEFLAGS=...
运行相比代码>行:I like the
MAKEFLAGS
approach suggested by John Marshall in lieu ofmake
supporting something like an automatic .makerc project config file. However, I didn't want to have to remember to source a .env or similar environment variables beforehand (and unsetting them afterward).A solution to this is to put the
MAKEFLAGS
assignment at the top of theMakefile
itself:Run it:
Compared to running without the
MAKEFLAGS=...
line: