Using HP Code Advisor in Application Builds: [HP Code Advisor] White Paper
4
• The application in consideration has two .c files and a .h file.
• The makefile uses conventionally named variables, CC and LD, to define the compiler and linker.
• The makefile has two target definitions as listed below:
– A default target called YourApplication, which is used to build the application.
– A clean target, which is used to remove objects generated during the build.
• Building using this makefile results in the following output:
$ make
aCC -c -Ae -O -I. source1.c source2.c
source1.c:
source2.c:
aCC -o YourApplication source1.o source2.o
$
In the methods described below, the default kind of build for the application never changes, that is,
executing a make command always builds the application without cadvise.
Method 1: Controlling use of cadvise through makefile variables
Change the CC and LD variables to prefix cadvise specific variables, which can be defined in the
command line, to the compiler and linker. An example is shown in Figure 2 below.
NOTE: If a build has autogenerated makefiles, changes to the makefiles are lost every time it is
regenerated. In such circumstances, cadvise-specific changes must be made in template files, which
generate makefiles.
Figure 2: Invoking CC and LD variables using cadvise options
# 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)
# Introducing cadvise options in the build tools and options
# Use aCC as the default C compiler
CC = $(CADVISE) $(CADVISE_OPTS) aCC
# Flags
CFLAGS = -c -Ae -O -I.
# Use aCC as the linker
LD = $(CADVISE) $(CADVISE_OPTS) 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