Programming Utilities Guide

Running Commands Silently

You can inhibit the display of a command line within a rule by inserting an @ as the first character on that line. For example, the following target:

quiet: 
       	@echo you only see me once 

produces:

$ make quiet 
         you only see me once

If you want to inhibit the display of commands during a particular make run, you can use the -s option. If you want to inhibit the display of all command lines in every run, add the special target .SILENT to your makefile.

.SILENT:
quiet: 
         echo you only see me once

Special-function targets begin with a dot (.). Target names that begin with a dot are never used as the starting target, unless specifically requested as an argument on the command line. make normally issues an error message and stops when a command returns a nonzero exit code. For example, if you have the target:

rmxyz: 
     rm xyz 

and there is no file named xyz, make halts after rm returns its exit status.

$ ls xyz 
xyz not found
$ make rmxyz 
rm xyz
rm: xyz: No such file or directory
*** Error code 1
make: Fatal error: Command failed for target `rmxyz' 

Note -

If - and @ are the first two such characters, both take effect.


To continue processing regardless of the command exit code, use a dash character (-) as the first non-TAB character:

rmxyz:
        -rm xyz

In this case you get a warning message indicating the exit code make received:

$make rmxyz  
rm xyz 
rm: xyz: No such file or directory 
*** Error code 1 (ignored)

Note -

Unless you are testing a makefile, it is usually a bad idea to ignore non-zero error codes on a global basis


Although it is generally ill-advised to do so, you can cause make to ignore error codes entirely with the -i option. You can also cause make to ignore exit codes when processing a given makefile, by including the .IGNORE special target, though this too should be avoided.

If you are processing a list of targets, and you want make to continue with the next target on the list rather than stopping entirely after encountering a non-zero return code, use the -k option.