Control Structures and Directives131
[root@conformix make]# make clean
rm ftp
rm: cannot remove `ftp': No such file or directory
make: *** [clean] Error 1
[root@conformix make]#
Now you can see that
make
did not attempt to execute the second
rm
command. To over-
come this situation, you can use a hyphen at the start of the command whose result code should
not be checked. This way
make
displays an error message but continues to the next command.
The same rule with hyphen added to the first
rm
command will be as follows:
clean:
-rm ftp
rm ftp.o common.o
Now when you invoke this rule and
ftp
file is not present,
make
will do something like
the following:
[root@conformix make]# make clean
rm ftp
rm: cannot remove `ftp': No such file or directory
make: [clean] Error 1 (ignored)
rm ftp.o common.o
[root@conformix make]#
As you can see from the above output,
make
ignored the error and continued to the next
line to remove object files.
There are other ways to ignore errors during the
make
process. You can also use the
–i
command line switch to ignore errors during the
make
process. Another method is to use
.IGNORE
special built-in rule to ignore errors.
4.6Control Structures and Directives
Control structures inside makefiles enable you to make some logical decisions depending upon
certain conditions.
Make
supports four types of decision-making directives as listed below:
1.
The
ifeq
directive
2.
The
ifneq
directive
3.
The
ifdef
directive
4.
The
ifndef
directive
These directives are explained next. In addition to these directives, you can also use the
for
control structure to execute a loop a specified number of times. Let us have a look at each
of these.