Abstract
(1) How to make the output of 'make' more readable(.SILENT)?
(2) Why can't I understand some strange makefiles(Multiple Rules for One Target)?
(3) How to boost make performance(-j nr_jobs)?
4.9 Special Built-in Target Names
Certain names have special meanings if they appear as targets.
.PHONY
- The prerequisites of the special target
.PHONY
are considered to be phony targets. When it is time to consider such a target,make
will run its commands unconditionally, regardless of whether a file with that name exists or what its last-modification time is. See Phony Targets. .SUFFIXES
- The prerequisites of the special target
.SUFFIXES
are the list of suffixes to be used in checking for suffix rules. See Old-Fashioned Suffix Rules. .DEFAULT
- The commands specified for
.DEFAULT
are used for any target for which no rules are found (either explicit rules or implicit rules). See Last Resort. If.DEFAULT
commands are specified, every file mentioned as a prerequisite, but not as a target in a rule, will have these commands executed on its behalf. See Implicit Rule Search Algorithm. .SILENT
- If you specify prerequisites for
.SILENT
, thenmake
will not print the commands to remake those particular files before executing them. The commands for.SILENT
are not meaningful.If mentioned as a target with no prerequisites,
.SILENT
says not to print any commands before executing them. This usage of `.SILENT' is supported only for historical compatibility. We recommend you use the more selective ways to silence specific commands. See Command Echoing. If you want to silence all commands for a particular run ofmake
, use the `-s' or `--silent' option (see Options Summary). .EXPORT_ALL_VARIABLES
- Simply by being mentioned as a target, this tells
make
to export all variables to child processes by default. See Communicating Variables to a Sub-make
. .NOTPARALLEL
- If
.NOTPARALLEL
is mentioned as a target, then this invocation ofmake
will be run serially, even if the `-j' option is given. Any recursively invokedmake
command will still be run in parallel (unless its makefile contains this target). Any prerequisites on this target are ignored.
Any defined implicit rule suffix also counts as a special target if it appears as a target, and so does the concatenation of two suffixes, such as `.c.o'. These targets are suffix rules, an obsolete way of defining implicit rules (but a way still widely used). In principle, any target name could be special in this way if you break it in two and add both pieces to the suffix list. In practice, suffixes normally begin with `.', so these special target names also begin with `.'. See Old-Fashioned Suffix Rules.
4.11 Multiple Rules for One Target
One file can be the target of several rules. All the prerequisites mentioned in all the rules are merged into one list of prerequisites for the target. If the target is older than any prerequisite from any rule, the commands are executed.There can only be one set of commands to be executed for a file. If more than one rule gives commands for the same file,
make
uses the last set given and prints an error message. (As a special case, if the file's name begins with a dot, no error message is printed. This odd behavior is only for compatibility with other implementations of make
... you should avoid using it). Occasionally it is useful to have the same target invoke multiple commands which are defined in different parts of your makefile; you can use double-colon rules (see Double-Colon) for this.5.4 Parallel Execution
GNU make
knows how to execute several commands at once. Normally, make
will execute only one command at a time, waiting for it to finish before executing the next. However, the `-j' or `--jobs' option tells make
to execute many commands simultaneously.
5.5 Errors in Commands
To ignore errors in a command line, write a `-' at the beginning of the line's text (after the initial tab). The `-' is discarded before the command is passed to the shell for execution.
For example,
clean:
-rm -f *.o
This causes rm
to continue even if it is unable to remove a file.
When you run make
with the `-i' or `--ignore-errors' flag, errors are ignored in all commands 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 command 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 either directly or indirectly. No further commands will be executed for these targets, since their preconditions have not been achieved.
没有评论:
发表评论