I know that the @
prefix suppresses output from a shell command in Makefiles, and also that the -
prefix will ignore errors from a shell command. Is there a way to combine the two, i.e. a prefix that suppresses output and ignores errors? I don't think @-
or -@
works.
相关问题
- CMakeList file to generate LLVM bitcode file from
- Makefile to compile lists of source files
- Have make fail if unit tests fail
- C++ - Compiling multiple files
- Trigger missing dependencies in (parallel) GNU mak
相关文章
- How to arrange a Makefile to compile a kernel modu
- Makefile and use of $$
- Makefile: all vs default targets
- Automake Variables to tidy up Makefile.am
- How do I check the exit status of a Makefile shell
- Marking a makefile dependency as optional or other
- How to instruct Makefile to use different compiler
- Why does this makefile execute a target on 'ma
Actually,
@-
and-@
both do work, but will print amake: [target] Error 1 (ignored)
warning.Instead, you can use
or, since
:
is shorthand fortrue
in shell,This often a better thing to do, because it avoid Make’s confusing warning that an error was ignored in an invisible command.
Consider the two most common cases where you might want to ignore the return value of a command:
For the second case, consider the example of grepping for warnings in the log file produced by a command.
grep
will return an error if it does not find a match, which is not what you want:produces:
Using
@-
produces a nonsensical ignored error warning when there is success, while|| true
handles both warnings and the absence of warnings without complaint.Theoretically using
|| true
is slower than using@-
, but this overhead is unlikely to be a bottleneck in well-designed and -maintained build systems. The vast majority of the time should be spent building, or checking timestamps when there is nothing to build, not in running the thousands of quick commands whose return values all get ignored that would be necessary for this to have a measurable performance impact.GNU make does allow you to combine both
@
and-
:Running this with gmake 3.81 produces this output:
As you can see, the command is not echoed, and the error is ignored as expected.