Using HP Code Advisor in Application Builds: [HP Code Advisor] White Paper
3
Introduction
HP Code Advisor (cadvise), is a static analysis tool for C and C++ programs. It reports various coding
errors in the source code. Cadvise analyses the source code using the same language mode, defines,
header files etc. as used by your compiler. Therefore, cadvise requires an entire build line as the
input. This is achieved by prefixing cadvise to the regular build line. Cadvise also does extensive
cross-file analysis to find defects across files, in order to do this cadvise must be used with the link line
also.
Cadvise first executes the build line to which it has been prefixed and then performs its own code
analysis. A build that is performed using cadvise does not change anything in the actual compilation
or link process. Cadvise performs the code analysis only after the regular build passes, thereby
providing an interface to facilitate integration of cadvise with an existing build environment. This
document describes techniques to incorporate cadvise into the build environment of an application.
Using cadvise with the builds
Figure1 shows a sample makefile that captures the common elements of a makefile used to build an
application.
Figure 1: A Sample makefile
The elements of the sample makefile are as follows:
# This is a sample Makefile
# This is used to illustrate how Cadvise can be #incorporated into
application builds
# List of source code files
SOURCES = source1.c source2.c
# Create a list of the object files using macro #substitutions
OBJECTS = $(SOURCES:.c=.o)
# Build tools and options
# Use aCC as the default C compiler
CC = aCC
# Flags
CFLAGS = -c -Ae -O -I.
# Use aCC as the linker
LD = aCC
LDFLAGS = -o
# Application target and dependencies
YourApplication: $(OBJECTS)
$(LD) $(LDFLAGS) $@ $(OBJECTS) $(LIBS)
# .o files depend on .c files
$(OBJECTS): includes.h
$(CC) $(CFLAGS) $(SOURCES)
# Clean built files
clean:
rm -rf *.o *~ YourApplication core