控制 make 命令的输出不那么冗长,不要回显每个命令

发布于 2024-12-20 19:13:31 字数 357 浏览 2 评论 0原文

目前,我正在使用 Makefile 来跟踪项目的所有依赖项和编译。问题是 make 只是输出它正在执行的所有操作,这使得很难发现(甚至读取)更重要的信息(例如编译器警告)。

有没有办法控制终端上显示哪些信息?我知道有一个 -s 选项可以使 make 静音,但这不是我想要的。我需要一些更精致的东西,也许显示编译目标而不显示整个编译命令。

有什么办法可以控制吗?

注意:有一个关于 automake 和 autoconf 命令的类似问题。但我不使用这些,而且我专门在 make 上寻找一些东西。

Currently, I'm using a Makefile to keep track of all dependencies and copilation of my project. The problem is that make simply outputs everything it's doing, and that makes it hard to spot (or even read) more important information (such as compiler warnings).

Is there a way to control what information is displayed on the terminal? I know there's a -s option that silences make, but that's not what I want. I need something a little more refined, perhaps showing the compilation target without showing the entire compilation command.

Is there any way to control that?

Note: There's a similar question regarding the automake and autoconf commands. But I don't use those, and I'm specifically looking for something on make.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜吻♂芭芘 2024-12-27 19:13:31

好吧,这是通常的事情

target: dependency1 dependency2
    @echo Making $@
    @$(CC) -o $@ $(OPTIONS) $^

领先的 @ 的抑制回显操作的通常行为,而不抑制其输出

可以通过将其重定向到 /dev/null 来抑制各种操作的输出。如果您希望一行真正保持安静,请记住也要对标准错误进行评分。

Well there's the usual business

target: dependency1 dependency2
    @echo Making $@
    @$(CC) -o $@ $(OPTIONS) $^

The leading @'s suppress the usual behavior of echoing the action without suppressing its output.

The output of various actions can be suppressed by redirecting it to /dev/null. Remember to grad the standard error too if you want a line to be really silent.

李不 2024-12-27 19:13:31

标准 Unix 答案(毕竟 `make`` 是一个 Unix 工具):

make (...) | grep (whatever you want to see)

为什么这不是一个合适的解决方案?

您还可以在 Makefile 本身中进行过滤,例如通过调整 SHELL 变量
或添加一个调用 $(MAKE) | 的目标grep

主要思想是允许根据调用者的意愿打开和关闭过滤。

The standard Unix answer (`make`` is a Unix tool, after all):

make (...) | grep (whatever you want to see)

Why is that not an appropriate solution here?

You could also put filtering within the Makefile itself, e.g. by tweaking the SHELL variable
or adding a target that calls $(MAKE) | grep.

The main idea is to allow the filtering to be switched on and off as the caller pleases.

玩套路吗 2024-12-27 19:13:31

(太晚了,仅为登陆此处的 Google 员工添加)
这对我有用。在 Makefile 中,您可以使用以下命令控制每个命令的详细程度:

BRIEF = CC HOSTCC HOSTLD AS YASM AR LD
SILENT = DEPCC DEPHOSTCC DEPAS DEPYASM RANLIB RM STRIP

(Too late, Adding just for Googlers landing here)
This works for me. On your Makefile you can control verbosity for each command using something like:

BRIEF = CC HOSTCC HOSTLD AS YASM AR LD
SILENT = DEPCC DEPHOSTCC DEPAS DEPYASM RANLIB RM STRIP
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文