Datasheet
Book VIII
Chapter 1
Programming
in Linux
537
Exploring the Software-Development Tools in Linux
The GNU make utility
When an application is made up of more than a few source files, compiling
and linking the files by manually typing the gcc command can get tiresome.
Also, you don’t want to compile every file whenever you change something
in a single source file. These situations are where the GNU make utility
comes to your rescue.
The make utility works by reading and interpreting a makefile — a text file
that describes which files are required to build a particular program as well as
how to compile and link the files to build the program. Whenever you change
one or more files, make determines which files to recompile — and it issues the
appropriate commands for compiling those files and rebuilding the program.
Makefile names
By default, GNU make looks for a makefile that has one of the following
names, in the order shown:
✦ GNUmakefile
✦ makefile
✦ Makefile
In UNIX systems, using Makefile as the name of the makefile is custom-
ary because it appears near the beginning of directory listings, where upper-
case names appear before lowercase names.
When you download software from the Internet, you usually find a
Makefile, together with the source files. To build the software, you only
have to type make at the shell prompt and make takes care of all the steps
necessary to build the software.
If your makefile doesn’t have a standard name (such as Makefile), you
have to use the -f option with make to specify the makefile name. If your
makefile is called myprogram.mak, for example, you have to run make
using the following command line:
make -f myprogram.mak
The makefile
For a program made up of several source and header files, the makefile
specifies the following:
✦ The items that make creates — usually the object files and the executable.
Using the term target to refer to any item that make has to create is common.
✦ The files or other actions required to create the target.
✦ Which commands to execute to create each target.
42_770191-bk08ch01.indd 53742_770191-bk08ch01.indd 537 8/6/10 9:51 AM8/6/10 9:51 AM