01.09.2014 Views

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CH04.fm Page 116 Monday, October 7, 2002 8:54 PM<br />

116 Chapter 4 • <strong>Using</strong> GNU make<br />

[root@rr2 test]# make<br />

gcc -g -O2 -c ftp.c<br />

gcc -g -O2 -c common.c<br />

gcc -static ftp.o common.o -o ftp<br />

gcc -g -O2 -c tftp.c<br />

gcc -static tftp.o common.o -o tftp<br />

gcc -g -O2 -c dnsresolver.c<br />

gcc -static dnsresolver.o common.o -o dnsresolver<br />

[root@rr2 test]#<br />

<strong>The</strong> default target is "all" which has dependency upon the variable $(TARGETS). This<br />

variable has three words: ftp, tftp <strong>and</strong> dnsresolver. First make tries to verify that ftp<br />

is up-to-date. For this it finds that ftp file does not exist so it tries to build it using some other<br />

rule. It finds the following rule to build ftp:<br />

ftp: $(FTPOBJS) $(FTPHDRS)<br />

$(CC) $(LDFLAGS) $(FTPOBJS) -o ftp<br />

Now it tries to find if dependencies of this rule are up-to-date. <strong>The</strong> object files are not<br />

present, so first it tries to build the object file. To build the object files, it looks for another rule<br />

<strong>and</strong> finds the following rule to build two object files (ftp.o <strong>and</strong> common.o) in the dependency<br />

list.<br />

$(OBJS): $(SRCS)<br />

$(CC) $(CFLAGS) -c $(@:.o=.c)<br />

When make executes the comm<strong>and</strong> in this rule, you see the following two lines in the output<br />

of the make comm<strong>and</strong>.<br />

gcc -g -O2 -c ftp.c<br />

gcc -g -O2 -c common.c<br />

Now it has all of the dependencies for the ftp target up-to-date <strong>and</strong> it builds ftp using<br />

the corresponding rule. At this point you see the following line in the output of the make comm<strong>and</strong>:<br />

gcc -static ftp.o common.o -o ftp<br />

By building ftp, make has satisfied one dependency in the default goal. Now it will try to<br />

meet the second dependency, which is tftp. Since the tftp file is not present, it will locate a<br />

rule that can be used to build tftp. In the tftp rule dependencies, the common.o file is<br />

already up-to-date, so it will not recompile it. However since it does not find tftp.o, it will<br />

rebuild tftp.o. At this point you see the following line in the output:<br />

gcc -g -O2 -c tftp.c<br />

Now it has successfully built dependencies for tftp <strong>and</strong> it will build the tftp target <strong>and</strong><br />

display the following line in the output:<br />

gcc -static tftp.o common.o -o tftp

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!