For example, your Makefile might look something like the Makefile below, which belongs to the Code Coverage example project included with the IDE (although, this example includes additional comments):
DEBUG = -g CC = qcc LD = qcc CFLAGS += -Vgcc_ntox86 $(DEBUG) -c -Wc,-Wall -I. -O0 -Wc,-ftest-coverage -Wc,-fprofile-arcs LDFLAGS+= -Vgcc_ntox86 $(DEBUG) -ftest-coverage -fprofile-arcs -p # CC refers to the program for compiling C programs (the default is # qcc. Use # CXX as the program for compiling C++ programs. # CFLAGS are additional flags to give to the C compiler. Use CFLAGS # for the C++ compiler. # -c compiles or assemble the source files, but doesn't link, and the # -Wc captures the warning messages. The linking stage isn't done. # The ultimate output is in the form of an object file for each # source file. # -Wall turns on all optional warnings that are desirable for normal # code. -I. adds the current directory to the list of directories to # search for header files. Directories named by -I are searched before # the standard system include directories. # -O0 is an optimization flag that indicates 'Do not optimize.' # LDFLAGS are additional flags to give to compilers when they invoke # the ld linker. # -ftest-coverage -Wc means that Code Coverage is enabled for your # project, and the data is used for test coverage analysis. # -fprofile-arcs adds code so that program flow arcs are instrumented. # During execution, the program records how many times each branch and # call is executed and how many times it is taken or returns, and it # saves this data to a file with the extension .gcda for each source # file. # # For Code Coverage, you'll need the -fprofile-arcs -ftest-coverage # options in both the compile and link lines, as well as the -p option # in the link line. -p is used to generate extra code to write profile # information for the analysis program. You must use the -p option when # compiling source files that you want data about, and you must also # use it when linking. dir := $(shell pwd) BINS = rbt_client rbt_server # This next line is the rule for <cmd>all</cmd> that # incrementally builds your system by performing a <cmd>make</cmd> # of all the top-level targets the Makefile knows about. It does this by # expressing a dependency on the results of that system, which in turn # have their own rules and dependencies. all: $(BINS) # The following line shows a simple rule for cleaning your build # environment. It cleans your build environment by deleting all files # that are normally created by running make. # It has a Target named <cmd>clean</cmd> to left of the colon, # no dependencies (to the right of the colon), and two commands that are # indented by tabs on the lines that follow. clean: rm -f *.o *.img *.gcno *.gcda $(BINS) # The following lines are Dependency Rules, which are rules without any # command. If any file to the right of the colon changes, the target to # the left of the colon is no longer considered current (out of date). # Dependency Rules are often used to capture header file dependencies. rbt_server: rbt_server.o # Alternatively, to manually capture dependencies, several automated # dependency generators exist. rbt_server.o : rbt_server.c rbt_server.h $(CC) $(CFLAGS) $(dir)/$< rbt_client: rbt_client.o rbt_client.o: rbt_client.c rbt_server.h $(CC) $(CFLAGS) $(dir)/$< profileCPP-std: $(objects) $(CC) -Vgcc_ntox86 $^ -g -p -o $@ -lcpp
To enable Code Coverage for your project, you must use the options -fprofile-arcs -ftest-coverage when compiling and linking.
For example, in the Makefile, you'll have the following gcc options set for Code Coverage:
CFLAGS += -g -fprofile-arcs -ftest-coverage LDFLAGS+=-p -g -fprofile-arcs -ftest-coverage