获取 Quiet Make 以在错误时回显命令行
我有一个 Makefile,使用很长的命令行构建许多 C 文件,并且我们通过以下规则清理了输出:
.c${MT}.doj:
@echo "Compiling $<";\
$(COMPILER) $(COPTS) -c -o $@ $<
现在这很棒,因为 @ 抑制了发出的编译行。 但是当我们遇到错误时,我们得到的只是错误消息,没有命令行。 谁能想到一种“简洁”的方式来发出命令行? 我能想到的就是将其回显到文件中,并使用更高级别的 make 捕获错误并捕获文件。 哈基我知道。
I have a Makefile building many C files with long long command lines and we've cleaned up the output by having rules such as:
.c${MT}.doj:
@echo "Compiling lt;";\
$(COMPILER) $(COPTS) -c -o $@ lt;
Now this is great as the @ suppresses the compilation line being emitted.
But when we get an error, all we get is the error message, no command line.
Can anyone think of a "neat" way to emit the command line?
All I can think of doing is echoing it to a file and have a higher level make catch the error and cat the file. Hacky I know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
测试成功(Linux 中的 GNU make):
Tested and it worked (GNU make in Linux):
这个问题已经很老了,但是对于那些谷歌搜索的人来说,我想在这种情况下我会做的是将
make
别名为make -s
(静默模式) shell,并且仅在调用echo
或其他诊断命令的行之前放置@
前缀。 当我想要make
的完整输出时,我将通过将其称为\make
来覆盖我的别名。另请注意,在这种情况下,您需要执行典型操作,将
@echo
放在自己的行上,将实际的规则命令放在单独的行上,并且不使用@
的。This question is pretty old, but for those of you Googling, I think what I’ll do in this situation is alias
make
tomake -s
(silent mode) in my shell, and only put the@
prefix before lines whereecho
or other diagnostic commands are being invoked. When I want the full output frommake
, I will override my alias by calling it as\make
.Also note that in this situation that you’ll need to do the typical thing and put the
@echo
on its own line, with the actual rule commands on separate lines and without@
’s.一个简单的解决方案是使用一个简单的脚本
abc
,如下所示:然后您可以编写
abc $(COMPILER) $(COPTS) -c -o $@ $<
> 在您的Makefile
中。 请注意,当您有管道或重定向时,这不起作用(因为它们将应用于abc
而不是您要运行的命令)。如果愿意的话,您也可以直接将类似的代码放入
Makefile
中。A simple solution would be to use a simple script
abc
like the following:Then you can write
abc $(COMPILER) $(COPTS) -c -o $@ $<
in yourMakefile
. Do note that this does not work when you have pipes or redirects (as they will be applied toabc
instead of the command you want to run).You can also just put similar code directly in the
Makefile
if that's preferable.我最近使用了一个名为 logtext 的实用程序,用于跟踪在过程中发生的输出正在执行一个bat文件。 检查一下,如果您想知道在哪里发生了什么错误,您可能会发现这非常有用。
I recently used a utility called logtext for the likes of tracking what output had occurred during the course of a bat file executing. Check it out, you may find this pretty useful if you want to know what error occurred where.