Using programming tools

Using make

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 make(CP) utility to automate compilation. The manual page the cc(CP) describes a large number of options for the compilers. 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, make(CP) 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

# 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

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:

make testcase

However, if make is invoked with the command line below, debugging information is included.

make testcasedb

For more information, see ``make'' and make(CP).

Next topic: Testing the code
Previous topic: Compiling the code

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003