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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

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

Let’s try to build the default target for the first time <strong>and</strong> see the output of these echo<br />

comm<strong>and</strong>s.<br />

[root@conformix make]# make<br />

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

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

ftp.o common.o ftp.h common.h<br />

ftp<br />

ftp.o<br />

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

[root@conformix make]#<br />

<strong>The</strong> first two lines in the output use implicit rules to build object files. <strong>The</strong> third line in the<br />

output is generated by the first echo comm<strong>and</strong> <strong>and</strong> it has a list of all the dependencies. <strong>The</strong> second<br />

echo comm<strong>and</strong> displays the fourth line in the output, which is just the name of the target, i.e.<br />

ftp. <strong>The</strong> last echo comm<strong>and</strong> prints the first dependency in the fifth line of the output.<br />

Now let us modify the common.c file <strong>and</strong> run make once again. <strong>The</strong> output will be as<br />

follows:<br />

[root@conformix make]# make<br />

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

common.o<br />

ftp<br />

ftp.o<br />

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

[root@conformix make]#<br />

This time make used an implicit rule to build common.o. <strong>The</strong> important thing to note is<br />

the second line in the output, which is displayed by the first echo comm<strong>and</strong> in the makefile.<br />

This time it displayed only one file in the dependency list because common.o is the only file<br />

that is changed in the dependencies.<br />

Automatic variables are very useful in control structures <strong>and</strong> in the decision-making process<br />

when you carry out an operation based upon the result of some comparison.<br />

4.4 Working with Multiple Makefiles <strong>and</strong> Directories<br />

Until now we have used simple makefiles to build projects or targets. We used only one makefile<br />

in the project <strong>and</strong> all of the source files were present in the same directory. In real-life software<br />

development projects, we have multiple directories containing different parts of a software product.<br />

For example, one directory may contain all library files, another header files <strong>and</strong> a third one<br />

common files used by different parts. Similarly every part of the software project may have its<br />

own subdirectory.<br />

This section deals with the same source files <strong>and</strong> targets that we used earlier in this chapter.<br />

<strong>The</strong> project contains three targets to be built. <strong>The</strong>se targets are ftp, tftp <strong>and</strong> dnsresolver.<br />

We are using the same set of source files. However to demonstrate the use of multiple<br />

directories <strong>and</strong> multiple makefiles, we have created each component in a separate directory. This

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

Saved successfully!

Ooh no, something went wrong!