从 make 文件中禁用 make 内置规则和变量
我想根据传递 禁用内置规则和变量GNU make 的 -r
和 -R
选项,来自 make 文件内部。也欢迎其他允许我隐式且透明地执行此操作的解决方案。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想根据传递 禁用内置规则和变量GNU make 的 -r
和 -R
选项,来自 make 文件内部。也欢迎其他允许我隐式且透明地执行此操作的解决方案。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
禁用内置规则是通过 为 < 编写一个空规则来完成的code>.SUFFIXES:
删除了内置规则后,我不确定删除内置变量对您的帮助不仅仅是记住自己设置它们或不使用它们,但是你可以使用类似
......这无疑是相当疯狂的。如果有一种方法可以从 make 中获取已定义变量的列表(而不是转移到另一个 make),那么它是可行的。事实上,它并不比
Disabling the built-in rules is done by writing an empty rule for
.SUFFIXES
:Having erased the built-in rules, I'm not sure that erasing the built-in variables helps you much more than just remembering to set them yourself or not use them, but you could use something like
...which is admittedly fairly crazy. If there is a way to get a list of the defined variables from within make (instead of shelling out to another make), it would be viable. As it is, it's not really much better than
@hseldon 有正确的想法,因为 .SUFFIXES 不涵盖匹配所有内容的内置隐式规则。但是,我认为他的语法并不完全正确。
请参阅 http://www.gnu.org/software/make/ Manual/make.html#Match_002dAnything-Rules 和 http://www.gnu.org/software/make/manual/make.html#index-g_t_002eSUFFIXES-998
@hseldon has the right idea because .SUFFIXES doesn't cover the match-everything built-in implicit rules. However, I don't think his syntax is exactly right.
See http://www.gnu.org/software/make/manual/make.html#Match_002dAnything-Rules and http://www.gnu.org/software/make/manual/make.html#index-g_t_002eSUFFIXES-998
https://www.gnu.org/software/make/manual /make.html#取消规则
https://www.gnu.org/software/make/manual/make.html#Canceling-Rules
如果随后编写另一个
.SUFFIXES
规则来添加先前已知的后缀,则通过为.SUFFIXES
编写空规则来禁用内置规则将不起作用 - 内置规则已重新启用。示例:想要为.ci
和.io
定义规则,并禁用内置规则.co
。写入不起作用 - 它不会阻止应用内置规则
.co
。该解决方案是 Marc Eaddy 采用的解决方案,并记录在 GNU make 手册中,10.5.6 取消隐式规则:
Disabling of built-in rules by writing an empty rule for
.SUFFIXES
does not work if one then writes another.SUFFIXES
rule to add previously known suffixes - the built-in rules are re-enabled. Example: One wants to define rules for.c.i
and.i.o
, and to disable the built-in rule.c.o
. Writingdoes not work - it does not prevent the built-in rule
.c.o
from being applied.The solution is the one employed by Marc Eaddy and documented in the GNU make manual, 10.5.6 Canceling Implicit Rules:
这对我有用:
将其放入名为disable_implicit_rules.mk 的文件中,并将其包含在每个makefile 中。
This works for me:
Put this in a file named disable_implicit_rules.mk and
include
it in every makefile.您可以使用
#!
启动Makefile
并将其命名为不同的名称,这样人们就不会尝试直接使用make
:这会导致可怕的后果如果 GNU make 不是系统
make
,则会出现问题。也许是一个包装脚本?您还可以阅读
$(MAKEFLAGS)
并确保存在所需的标志。You could start the
Makefile
with a#!
and call it something different so people don't try to usemake
directly:This will cause horrific problems if GNU make is not the system
make
. Maybe a wrapper script?You can also read
$(MAKEFLAGS)
and make sure the required flags are present.执行此操作:
这里,
rR
相当于--no-builtin-rules --no-builtin-variables
。--no-builtin-rules
似乎工作正常,但--no-builtin-variables
很不稳定。--no-builtin-variables
阻止配方看到变量,但如果您尝试在配方之外访问它们,它们仍然存在。这就是第二行的用途。它手动取消定义所有内置变量。 (与 @JohnMarshall 的回答中的想法相同,但没有 shell 调用。)
它会删除
$( origin
)
报告default
,但它会忽略SHELL
、CURDIR
以及以 < 开头的变量code>. 和MAKE
(MAKEINFO
除外),因为它们看起来很有用。Do this:
Here,
rR
is equivalent to--no-builtin-rules --no-builtin-variables
.--no-builtin-rules
seems to work properly, but--no-builtin-variables
is wonky.--no-builtin-variables
prevents the recipes from seeing the variables, but if you try to access them outside of a recipe, they are still there.That's what the second line is for. It manually undefines all built-in variables. (Same idea as in @JohnMarshall's answer, but without shell invocations.)
It removes all variables for which
$(origin
)
reportsdefault
, except that it ignoresSHELL
,CURDIR
, and variables starting with.
andMAKE
(exceptMAKEINFO
), since those look useful.