Chapter 5: Writing Recipes in Rules 49
modes). For example, many programs that can display colorized output will not do so
if they determine they are not writing to a terminal. If your makefile invokes a program
like this then using the output synchronization options will cause the program to believe
it’s running in “non-interactive” mode even though the output will ultimately go to the
terminal.
5.4.2 Input During Parallel Execution
Two processes cannot both take input from the same device at the same time. To make
sure that only one recipe tries to take input from the terminal at once, make will invalidate
the standard input streams of all but one running recipe. If another recipe attempts to read
from standard input it will usually incur a fatal error (a ‘Broken pipe’ signal).
It is unpredictable which recipe will have a valid standard input stream (which will come
from the terminal, or wherever you redirect the standard input of make). The first recipe
run will always get it first, and the first recipe started after that one finishes will get it next,
and so on.
We will change how this aspect of make works if we find a better alternative. In the
mean time, you should not rely on any recipe using standard input at all if you are using
the parallel execution feature; but if you are not using this feature, then standard input
works normally in all recipes.
5.5 Errors in Recipes
After each shell invocation returns, make looks at its exit status. If the shell completed
successfully (the exit status is zero), the next line in the recipe is executed in a new shell;
after the last line is finished, the rule is finished.
If there is an error (the exit status is nonzero), make gives up on the current rule, and
perhaps on all rules.
Sometimes the failure of a certain recipe line does not indicate a problem. For example,
you may use the mkdir command to ensure that a directory exists. If the directory already
exists, mkdir will report an error, but you probably want make to continue regardless.
To ignore errors in a recipe line, write a ‘-’ at the beginning of the line’s text (after the
initial tab). The ‘-’ is discarded before the line is passed to the shell for execution.
For example,
clean:
-rm -f *.o
This causes make to continue even if rm is unable to remove a file.
When you run make with the ‘-i’ or ‘--ignore-errors’ flag, errors are ignored in all
recipes of all rules. A rule in the makefile for the special target .IGNORE has the same effect,
if there are no prerequisites. These ways of ignoring errors are obsolete because ‘-’ is more
flexible.
When errors are to be ignored, because of either a ‘-’ or the ‘-i’ flag, make treats an
error return just like success, except that it prints out a message that tells you the status
code the shell exited with, and says that the error has been ignored.
When an error happens that make has not been told to ignore, it implies that the
current target cannot be correctly remade, and neither can any other that depends on it
Comentários a estes Manuais