108Chapter4 Using GNU make
4.1.4Running
make
In its basic and most widely used form, simply entering
make
on the command line
invokes the
make
program. Upon invocation, it reads its input file, in a priority order as
explained earlier, and executes different commands in it to build the default goal. In this chapter,
we are using a hypothetical project that builds three applications:
ftp
,
tftp
and
dnsre-
solver
. Reference to this project will be used in many parts of the remaining chapter. See sec-
tion 4.4 for a complete listing of the makefiles used.
Building a Default Goal
If we have a Makefile in the current directory and the default goal is to build all of the
ftp
,
tftp
, and
dnsresolver
, specified by all rule, a typical session will be as follows:
[root@rr2 test]# make
gcc -g -O2 -c ftp.c
gcc -g -O2 -c common.c
gcc -static ftp.o common.o -o ftp
gcc -g -O2 -c tftp.c
gcc -static tftp.o common.o -o tftp
gcc -g -O2 -c dnsresolver.c
gcc -static dnsresolver.o common.o -o dnsresolver
[root@rr2 test]#
Building a Non-Default Goal
If you have multiple goals in a Makefile and you dont want to build a default goal, you
have to specify the goal you want to build on the command line. The following line builds only
the ftp server.
[root@rr2 test]# make ftp
gcc -g -O2 -c ftp.c
gcc -g -O2 -c common.c
gcc -static ftp.o common.o -o ftp
[root@rr2 test]#
When a Target is Updated
There are certain rules about when a target will be built or rebuilt. These are as listed below.
Target is not present
. If a target is not present and a rule is executed, the target will
always be rebuilt.
Target is outdated
. This means that one or more dependencies of a target are newer than
the target. This happens when someone changed a dependency after the target was built
last time.
Target is forced to be rebuilt
. You can define rules to force a target to be rebuilt
whether a dependency has changed or not. This is also true for phony targets.