仅禁止显示实际的 make 命令和最终打印语句
Suppress only the actual make command and final print statement
我有一个程序,可以将东西 - 数字 - 输出到stdout。
该程序在自动评分器中与make run input.txt 0.87 > output_file
一起运行(这是针对作业的)。程序必须以这种方式运行(即使它实际上不应该用于 make 文件)。
但是,我在这里的一个 SO 问题的帮助下让它工作。这是我的制作文件:
pr.exe : main.cpp
g++ -std=c++11 $^ -o $@
run:
@./pr.exe $(filter-out $@,$(MAKECMDGOALS))
%:
@:
compile : pr.exe
.PHONY : compile
只有一个问题:命令make run input.txt 0.87
输出,除了程序输出之外,最后一行:
make: 'input.txt' is up to date.
如何在 make 文件中取消此行,以便仅将程序输出重定向到文件中?
它必须仅使用以下命令正常运行(没有 make 参数,nada):
make run input.txt 0.87 > some_output_file.txt
message
的打印被-s
make选项禁用:
https://github.com/mturk/gnumake/blob/9c3fecf4dd76a8c802055d9bd3689d0c6c5d6167/remake.c#L229
if (!rebuilding_makefiles
/* If the update_status is zero, we updated successfully
or not at all. G->changed will have been set above if
any commands were actually started for this goal. */
&& file->update_status == 0 && !g->changed
/* Never give a message under -s or -q. */
&& !silent_flag && !question_flag)
message (1, ((file->phony || file->cmds == 0)
? _("Nothing to be done for '%s'.")
: _("'%s' is up to date.")),
file->name);
silent_flag
由 make-s
命令行选项设置:
https://github.com/mturk/gnumake/blob/9c3fecf4dd76a8c802055d9bd3689d0c6c5d6167/main.c#L412
/* Nonzero means do not print commands to be executed (-s). */
int silent_flag;
{ 's', flag, &silent_flag, 1, 1, 0, 0, 0, "silent" },
而且它设置在 https://github.com/mturk/gnumake/blob/9c3fecf4dd76a8c802055d9bd3689d0c6c5d6167/file.c#L752
f = lookup_file (".SILENT");
if (f != 0 && f->is_target)
{
if (f->deps == 0)
silent_flag = 1;
else
for (d = f->deps; d != 0; d = d->next)
for (f2 = d->file; f2 != 0; f2 = f2->prev)
f2->command_flags |= COMMANDS_SILENT;
}
这是对 https://www.gnu.org/software/make/manual/html_node/Special-Targets.html 中记录.SILENT
特殊目标的解析
.SILENT
如果为 指定先决条件。静音,然后制作不会打印 配方用于在执行这些特定文件之前重新制作它们。 的配方 .静默被忽略。
如果作为没有先决条件的目标提及,.沉默说不要 在执行之前打印任何配方。这种用法".沉默'是 仅支持历史兼容性。我们建议您使用 更有选择性的方式来沉默特定的食谱。请参阅配方回声。 如果您想使特定制作的所有配方静音,请使用 "-s"或"--silent"选项(请参阅选项摘要)。
因此,请尝试将.SILENT
特殊目标添加到您的 Makefile,而无需任何其他先决条件。(解决方案未经我测试。
.SILENT:
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 为什么无论输入如何,所有 if-else 语句都会打印?
- 为什么这个 IF 语句在循环内不打印
- 二叉搜索树使用最常用的节点来打印出某些语句
- 自动打印出哪个 EXPECT 语句失败
- 我的 if 语句打印在我的 while 循环中的每个 if 语句上,无论它是否为假
- 所有类实例方法的打印语句最后都在打印吗?
- 如何在没有打印语句的情况下报告用户输入错误
- 面临在 if 语句之外打印变量数据的问题 完成使用 Qt 编程
- 为什么返回语句和打印语句返回不同的答案?
- 仅禁止显示实际的 make 命令和最终打印语句
- 我的 for 循环之后的代码不起作用,for 循环后的打印语句不会被打印
- C++ to_string函数根据额外打印语句的先见之明,为浮点数和整数转换提供不同的结果
- 删除"超出矢量误差范围"的打印语句后输出不同的根本原因
- Arduino 项目需要打印语句才能工作
- 多线程程序只适用于打印语句
- 高斯的FFT;不确定在何处/如何插入值的打印语句
- Clang中漂亮的打印语句到字符串
- 程序不起作用,添加打印语句它有效,为什么?
- 有人能解释一下这个特殊的打印语句在for循环中做了什么吗