包含生成的makefile,而没有警告消息 [英] Include generated makefile without warning message

查看:85
本文介绍了包含生成的makefile,而没有警告消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的一个项目,我会自动生成makefile并将其包括在内,

For a project of mine I am automatically generating makefiles and including them, like this:

all:
    @echo 'SUCCESS is $(SUCCESS)'

clean:
    rm depend.mk

depend.mk:
    @echo 'Creating $@'
    @echo 'SUCCESS := 1' > $@

.PHONY: all clean

include depend.mk

这可行,但是包含行会生成警告消息:

This works, but the include line generates a warning message:

$ make
Makefile:13: depend.mk: No such file or directory
Creating depend.mk
SUCCESS is 1

我想让那条第一条警告线沉默,那就是depend.mk不存在.我知道它不存在,因为我已经编写了一条规则来生成它,所以警告是不必要的(除非当然没有规则).我不想忽略包含文件不存在且没有规则的错误,因此对include加上-前缀以忽略该错误对我不起作用.我想要类似于bash的将stderr管道输送到/dev/null的约定,例如some_cmd 2>/dev/null,但是要包含在make中.

I would like to silence that first warning line saying that depend.mk doesn't exist. I know it doesn't exist since I have a rule written to generate it, so the warning is unnecessary (unless of course there isn't a rule for it). I do NOT want make to ignore the error where the included file doesn't exist and there is no rule for it, so prefixing include with a - to ignore the error will not work for me. I'd like something similar to bash's convention of piping stderr to /dev/null like some_cmd 2>/dev/null but for including in make.

上面的示例是这种情况的非常简化的示例.在我的实际项目中,包含了许多自动生成的生成文件(通过clang的自动依赖项生成),这意味着重新运行make会将这些警告消息淹没在我的屏幕上.

The sample above is a very simplified example of this case. In my actual project there are a lot of automatically generated makefiles (via clang's automatic dependency generation) being included, meaning a fresh run of make will flood my screen with these warning messages.

是否可能发生这种情况?还是我只需要处理恼人的警告消息?

Is anything like this possible, or am I just going to have to deal with the annoying warning messages?

推荐答案

我自己遇到并(多次)解决了这个问题.确实,问题在于思考和生成依赖文件的时间.

I've encountered and (re-re-re-re-)solved this problem a number of times myself. Really, the problem is in the thinking surrounding when the dependency files are generated and used.

此链接包含分辨率"的详细说明: http ://make.mad-scientist.net/papers/advanced-auto-dependency-generation/

This link has the detailed description of the "resolution": http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/

基本上可以归结为以下事实:依赖文件实际上仅是重建所必需的,而不是库/可执行文件的初始构建.结果,您不需要预先生成依赖文件的规则(实际上效率较低),而应该在目标文件步骤中将它们生成为标记为珍贵的中间文件(因此,它们是作为副文件进行创建和跟踪的) -永远不会自动清除的效果文件).随后的构建将具有可用的文件,而这正是您要总体上实现的目标.然后,您可以将其设置为依赖文件上的"-include",这可以预见,如果依赖文件生成失败,则目标文件的构建步骤将失败,这会立即产生错误(如您所提到的那样),而不是晦涩难懂后来又间接了.

Basically it comes down to the fact that dependency files are really only necessary for rebuilding, not the initial building of your library/executable. Resultantly you don't need to have a rule for generating dependency files up front (which is in fact less efficient), you instead should generate them during the object file step as intermediate files marked precious (so they're created and tracked as side-effect files that should never be cleaned up automatically). Subsequent builds will then have the files available, which is exactly what you were trying to achieve overall. You can then make it a "-include" on the dependency files, with the foreknowledge that your object file build step will fail if the dependency file generation fails, giving an immediate error, as you've mentioned is preferred, rather than an obscure and indirect one much later.

我实际上已经完成了几个实施此方法的大型构建系统,并且运行良好,包括使用非GNU工具链的系统.对于外部用户来说,它看起来是相同的,但是在内部它却能更有效地执行操作,并且没有隐藏潜在的重要错误.

I've actually done a couple rather large build systems implementing this method, and it does work quite well, including ones that used non-GNU toolchains. To an outside user it appears identical, but internally it performs more efficiently and isn't hiding potentially important errors.

这篇关于包含生成的makefile,而没有警告消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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