Editing the makefile

In the simplest scenario for a kwwrap-based build integration, you are doing a make build, and your makefile defines several widely used variations on the name of your C compiler, C++ compiler, and linker/librarian.

Inserting kwwrap into your makefile causes kwwrap to execute for every compile and link command in your build, and generate a build trace while your build runs. A build trace is a file that contains the sequence of process calls that took place during your build (for example, the make command).

Note that you must always specify the full path to the trace file, so that kwwrap is always writing to the same file. In addition, if you run the kwwrap-enabled build more than once with the same settings, delete the previously generated build trace before running the build again. Otherwise, the trace file will contain commands from multiple builds.

For distributed builds, you must run the following procedure on all build machines and merge the resultant build trace files.

To integrate kwwrap with your build:

  1. Edit your makefile, inserting the kwwrap command line before your compiler and linker names. For example, the following lines in our makefile:
    CC = gcc
    CXX = g++
    AR = ar
    

    are replaced by:

    CC = kwwrap -o <path_to_kwwrap_trace_file> gcc
    CXX = kwwrap -o <path_to_kwwrap_trace_file> g++
    AR = kwwrap -o <path_to_kwwrap_trace_file> ar

    where <path_to_kwwrap_trace_file> is the full path to the build trace file that will be generated by kwwrap.

  2. Run your build command (for example, make).

    kwwrap generates a build trace while your build runs. It is stored in the location specified in the make file.

  3. Convert the build trace into a build specification with kwinject.
    kwinject --trace-in <path_to_kwwrap_trace_file> --output <path_to_kwinject_output_file>
    

    For example:

    kwinject --trace-in C:/temp/kwwrap.trace --output C:Klocwork/temp/kwinject.out
    

Example

Zlib is a small open-source project that uses GNU make to build on UNIX. The makefile defines the environment variables CC, AR and LDSHARED to define the tools used to compile and generate static and dynamic libraries. You can edit the makefile to use a wrapped version of the compiler and linker by adding kwwrap:

$ cd /path/to/zlib-1.2.2
... configure and generate Makefile
$ ./configure
... now edit the Makefile
-- file: zlib-1.2.2/Makefile
...
CC=kwwrap -o /path/to/kwwrap.trace gcc
LDSHARED=kwwrap -o /path/to/kwwrap.trace gcc
AR=kwwrap -o /path/to/kwwrap.trace ar rc
...
-- cut
... run the build using wrapped compiler/linker; kwwrap.trace will be generated
$ make
... convert the raw build trace to a build specification
$ kwinject -t /path/to/kwwrap.trace -o kwinject.out
If you cannot substitute your compiler with a command plus options

For situations where the compiler must be substituted with a single command (that is, without options such as -o), on Windows, you can create a configuration file for kwwrap. The file must be named kwwrap.conf, and it must be located in the same directory as kwwrap.

Each line of the kwwrap configuration file has the following format:<executable_name>=<options_list>

where

  • <executable_name> is the name of the compiler or linker executable
  • <options_list> is the list of kwwrap options

Notes

  • There should be no spaces before and after the equal sign (=).
  • Use double quotes (") to specify a variable value that includes spaces.

Example kwwrap.conf file

cl.exe=-o "C:\My traces\mozilla.trace" "C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin\cl.exe"
link.exe=-o "C:\My traces\mozilla.trace" "C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin\link.exe"