Use Testwell CTC++ with makefiles

With the small example from the basic tutorial, we describe one way how to use Testwell CTC++ with makefiles.

Assume we do the compilations and linking of the program with a makefile, which looks as follows:
# Makefile for building prime.exe
EXE = prime.exe
CMP = cl
LNK = link

all: $(EXE)
prime.obj: prime.c io.h calc.h
io.obj: io.c io.h
calc.obj: calc.c calc.h

.c.obj:
   $(CMP) /nologo -c $<

$(EXE): prime.obj io.obj calc.obj
   $(LNK) /nologo /out:$(EXE) prime.obj io.obj calc.obj

clean:
   del prime.exe
   del prime.obj
   del io.obj
   del calc.obj
If we first use nmake clean for deleting the .exe and .obj files and then
nmake "CMP=ctc -i m cl" "LNK=ctc link"
the following commands are emitted by the makefile
ctc -i m cl /nologo -c prime.c
ctc -i m cl /nologo -c io.c
ctc -i m cl /nologo -c calc.c
ctc link /nologo /out:prime.exe prime.obj io.obj calc.obj

First the source files are instrumented and compiled and then the instrumented objects are linked with the Testwell CTC++ run-time library.

If we change one of the source files and issue the same make command (with CMP and LNK redefined), we get instrumentation/compilation only of the changed source file and then linking of the instrumented target.

Note: If you want the original non-instrumented version of the program back, the instrumented objects must all be rebuilt and the target relinked. For example as follows:
nmake clean all