Introduction to GNU make105
clean:
rm *.o
Whenever you invoke
make
to build this target, the
rm
command is always executed. This
is because the target has no dependency. These types of targets are called phony targets.
However there is a problem with such targets. Sometimes if there is a file with the same
name as the phony target, the
make
utility may get confused while building it and execute the
command in the phony target when it is not required to do so. To avoid this problem, you can
specify which targets are phony targets in the makefile. The following line in the makefile
defines clean as a phony target.
.PHONY: clean
clean:
rm *.o
4.1.2Input Files
The
make
command, when invoked without a command line argument, expects certain
file names as input. These files names are searched in the current directory in the following
order.
1.
GNUmakefile
2.
makefile
3.
Makefile
If none of these files is present,
make
will not take any action and displays the following
error message:
[root@conformix make]# make
make: *** No targets specified and no makefile found. Stop.
[root@conformix make]#
However there is a way to specify files with non-standard names as explained later. The
common practice is to use “Makefile” as the name of the input file because it easy to distinguish
from other files due to upper case M.
N O T E If you have multiple input files in the same directory
with names
GNUmakefile
,
makefile
and
Makefile
,
only the
GNUmakefile
will be used. As a rule of thumb,
make
will use only the first available file in its priority list to build a
project. This means that if we have two files with names
make-
file
and
Makefile
, only the file named
makefile
will be
used.
Next Page >>
<< Previous Page
Back to the Table of Contents