130Chapter4 • Using GNU make
4.5Special Features of
make
In addition to the normal use of the
make
utility, it has some special features. Two of these fea-
tures are discussed here that may be of interest for a common user of
make
. These features are
running
make
commands in
parallel
and running
make
in
non-stop
mode.
Running multiple commands in parallel enhances the efficiency of
make
. Running
make
in non-stop mode is useful for very large projects where you want
make
to go through every-
thing while running a command without stopping, even in case of errors. You can redirect the
output of
make
to a log file which can be viewed later to find out what error occurred during the
make
processes of the whole project.
4.5.1Running Commands in Parallel
Usually
make
runs commands in serial fashion. This means that one command is exe-
cuted and when that command is finished, the next command is executed. You can ask
make
to
run many commands in parallel. This is especially useful in multi-processor systems to
make
execution fast. The only problem with this is that when multiple commands are running in paral-
lel, output from different commands is displayed simultaneously and can get mixed up. To run
multiple commands in parallel, use the
–j
(jobs) command line switch with
make
.
If you want to specify a maximum number of concurrent commands, a number with the
j
switch may be specified. For example,
-j5
on the command line will force
make
to
invoke at the maximum five commands simultaneously. It is useful to note that in general the
most efficient builds can be done with -
j
equal to one or two times the total number of proces-
sors on the system. Also note that
make
rules are followed such that all dependencies are sat-
isfied before a target is built. This means you won't always have the maximum number of jobs
running simultaneously, depending upon the way makefile is written.
4.5.2Non-Stop Execution
The
make
utility executes each command while building a target. After executing the
command, it checks the result of that command. If the command was executed successfully, it
goes to the next command and executes it. However if the command does not execute success-
fully,
make
exits without executing any further commands. It displays an error message to show
that the target can’t be built.
Sometime, however, it is not important that each command should succeed. As an exam-
ple, look at the following lines in the
clean rule.
clean:
rm ftp
rm ftp.o common.o
If the
ftp
file is not there, the
rm
command will return a failure code. However we still
want to remove other files using the
rm
command in the next line. If the rule is listed in this way
and the ftp file is not present, the output of the
make clean
will be as follows:
Next Page >>
<< Previous Page
Back to the Table of Contents