2.2. How to Recompile

In the previous chapter we compiled and linked a program that consisted of one source file. We will now look at building a program from more than one source file.

The easiest way to build a program is to name all the relevant files on the compile command line. The compiler will compile each file in turn, and call the linker to link all the object code files and any default library files.

When recompiling you may have changed just one file, and are sure that none of the other files need recompiling. You may save compilation time by using the previous object files. The best way to do this is using the make command and a Makefile. Most versions of make include definitions for the C and C++ programming languages, but not for Coral 66. So the first task is to declare the filename suffixes .cor and .c66 as identifying Coral 66 source files, and the program m68k-coff-c66 as the program that translates Coral 66 source files into object code.

This is what you need to add to your Makefile for Coral 66.


#
# Makefile fragment for compiling Coral 66 programs
#
CC = m68k-coff-gcc
C66FLAGS = -O2 -g -m68020 -m68881
LDLIBS = -lc

COMPILE.cor = $(CC) $(C66FLAGS) $(TARGET_ARCH) -c
LINK.cor = $(CC) $(C66FLAGS) $(LDFLAGS) $(TARGET_ARCH)

.SUFFIXES: .cor .o

.cor.o:
        $(COMPILE.COR) $(OUTPUT_OPTION) $<
.cor:
        $(LINK.cor) $^ $(LOADLIBES) $(LDLIBS) -o $@

You may then add dependencies for your program, as follows:


hello2: hello2.cor coralio.cor

Then to compile or recompile the program hello2 you type make hello2.