While the procedure for compiling our
sample program is relatively simple,
the procedure for compiling larger projects
can be considerably more complex.
Fortunately, the Development System provides a tool
to automate the procedure.
There are a number of reasons for using the
utility to automate compilation.
The manual page the
describes a large number of options for the
In some instances,
the appropriate assortment
of libraries, indicated with the -l option, needs
to be selected each time a program is compiled.
Remembering all the options can become tedious;
that is one reason for creating a makefile
to use when compiling and linking the program.
Another advantage of a makefile is that
when several files are linked together into one executable file,
only recompiles those files that have been modified
(or ``touched'') since the last link.
This reduces the time required to recompile code.
We can use the following makefile to automate the compilation of testcase.c:
# # Makefile for testcase.c #The above makefile provides two ways of compiling testcase.c. Invoking the makefile with the following command line compiles the file with no debugging information contained in the binary:
# Compile testcase.c normally
testcase: testcase.c cc -o testcase testcase.c
# Compile testcase.c with debugging information
testcasedb: testcase.c cc -otestcasedb -g testcase.c
However, if make is invoked with the command line below,
debugging information is included.
For more information, see