English 中文(简体)
2. 清洗中的禁止信息(Makefile保持沉默)
原标题:Suppress messages in make clean (Makefile silent remove)
  • 时间:2010-06-30 10:51:46
  •  标签:
  • makefile

我不禁要问,我如何能够避免在《马克思书》中重复一些内容:

clean:
    rm -fr *.o

本条细则将印刷如下:

$>make clean   
rm -fr *.o

$>

我如何能够避免这种情况?

最佳回答

事实上,我正在寻找其他东西,在马克茨:

.SILENT:clean

在执行“明确”目标的每一个步骤时,都保持沉默。

在有人对此表示某种挫折之前,我把这当作我的有利解决办法!

问题回答

首先:实际指挥必须是下行的(或至少是马克邦联的指挥,可能不同于其他马克斯——我不相信这一点)

clean:
    rm -rf *.o

(注:您需要TAB, 可在rm -rf *.o前按每一条填写)

可以通过预先确定<条码>@来保持沉默:

页: 1

clean:
    @rm -rf *.o

如无<代码>*>*:o文档,请删除。 为了消除这些障碍,添加以下内容:

clean:
    -@rm -rf *.o 2>/dev/null || true
  • 2>/dev/null pipes any error message to /dev/null - so you won t see any errors
  • the - in front of the command makes sure that make ignores a non-zero return code

我对这个古老专题作出了回应,因为它在搜索中占据了很高的位置,答案令人困惑。 仅靠用户想要做的是:

clean:
    @rm -f *.o

The @ means that make will not echo that command. The -f argument to rm tells rm to ignore any errors, like there being no *.o files, and to return success always.

我从欧佩斯的例子中删除了——因为这意味着收回,这里我们只是<代码>rming.o file,而不必再重复。

不需要<代码>2>&1 >/dev/null,因为<代码>-f将不印制任何错误。

.SILENT: clean

替代@的工程,但在Makfile的同一位置与它所影响的指挥相同,因此,后来维持该项目的人可能会被混淆。 为什么喜欢@。 更适合参考。

如果你在指挥前投放“@”,那就没有回声。 Try changing rm to @rm. (

手册:。 由于@更为灵活, 代码基本上过时。

更糟糕的是,make<>/em>印刷的信息太多。 警告/警报/私人信息被掩埋在产出中。 另一方面,<代码>-s()。 正式文件只字不提。 尤其是“不做什么”和“直到现在”的信息可能是痛苦的。 没有任何办法加以压制。 你们必须积极过滤或使用colormake。 这里的解决办法是grep:

make | egrep -hiv  nothing to be done|up to date 

但产出将有线数。 因此,Perl办法较好,因为它抑制了线数和流 flu:

make | perl -ne  $|=1; print unless /nothing to be done|up to date/i 

http://www.conifersystems.com/whitepapers/gnu-make/“rel=“nofollow”> “?

The s a great article on using 。 SILENT,解释如何有条件启动。

我已利用这一信息将这一点列入我的马克文:

# Use `make V=1` to print commands.
$(V).SILENT:

# Example rule, only the @echo needs to be added to existing rules
*.o: %.c
    @echo " [CC]  $<"
    gcc ...

如果你操作<代码>make<>/code>,正常产出就会保持沉默,而代之以echo。 指挥工作:

$ make
 [CC]  test.c
 [CC]  test2.c

但它允许你通过<代码>来缓解问题。 V=1 para amount, which still show the [CC] information as it helps distinging the production, but the traditional Makfile production is alsoprofile:

$ make V=1
 [CC]  test.c
gcc ...
 [CC]  test2.c
gcc ...




相关问题
makefile: how to show line numbers for debugging?

Is there a way to have make display the line number where it declares an error? The -d switch doesn t seem to cut it. Updated: Example output: Reaping winning child 0x08aa8648 PID 9381 /bin/sh: ...

What is the reasoning behind the Makefile whitespace syntax?

I m revisiting Python after Michael Sparks s excellent walk through of Peter Norvig s Python spell checker at the SO DevDay in London. One of the points he highlighted was how clean Python is to look ...

Debugging GNU make

Is there a command line way in make to find out which of the prerequisites of a target is not updated?

How to add an all rule to this Makefile?

I want to just type make all and have the following Makefile do everything it s supposed to do: LEX = lex YACC = yacc CC = gcc calcu: y.tab.o lex.yy.o $(CC) -o calcu y.tab.o lex.yy.o -ly -lfl ...

How to discover number of *logical* cores on Mac OS X?

How can you tell, from the command line, how many cores are on the machine when you re running Mac OS X? On Linux, I use: x=$(awk /^processor/ {++n} END {print n+1} /proc/cpuinfo) It s not ...

Using extern in C doesn t work as expected

I have created two files: tunables.h #ifndef TUNABLES_H #define TUNABLES_H void tunables_load_conservative(); void tunables_load_aggressive(); extern int timer_x; #endif /*TUNABLES_H */ and ...