116Chapter4 • Using GNU make
[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]#
The default target is "
all"
which has dependency upon the variable
$(TARGETS)
. This
variable has three words:
ftp
,
tftp
and
dnsresolver
. First
make
tries to verify that
ftp
is up-to-date. For this it finds that ftp file does not exist so it tries to build it using some other
rule. It finds the following rule to build ftp:
ftp: $(FTPOBJS) $(FTPHDRS)
$(CC) $(LDFLAGS) $(FTPOBJS) -o ftp
Now it tries to find if dependencies of this rule are up-to-date. The object files are not
present, so first it tries to build the object file. To build the object files, it looks for another rule
and finds the following rule to build two object files (
ftp.o
and
common.o
) in the depen-
dency list.
$(OBJS): $(SRCS)
$(CC) $(CFLAGS) -c $(@:.o=.c)
When
make
executes the command in this rule, you see the following two lines in the out-
put of the
make
command.
gcc -g -O2 -c ftp.c
gcc -g -O2 -c common.c
Now it has all of the dependencies for the
ftp
target up-to-date and it builds
ftp
using
the corresponding rule. At this point you see the following line in the output of the
make
com-
mand:
gcc -static ftp.o common.o -o ftp
By building
ftp
,
make
has satisfied one dependency in the default goal. Now it will try to
meet the second dependency, which is
tftp
. Since the
tftp
file is not present, it will locate a
rule that can be used to build
tftp
. In the
tftp
rule dependencies, the
common.o
file is
already up-to-date, so it will not recompile it. However since it does not find
tftp.o
, it will
rebuild
tftp.o
. At this point you see the following line in the output:
gcc -g -O2 -c tftp.c
Now it has successfully built dependencies for
tftp
and it will build the
tftp
target and
display the following line in the output:
gcc -static tftp.o common.o -o tftp
Next Page >>
<< Previous Page
Back to the Table of Contents