
These instructions assume that your current directory starts out as the "demo"
directory within the package.


Building with CMake
==============================================

1. Create a new directory for building.
  e.g. mkdir ../callcounterbuild

2. Change into the new directory.
  e.g. cd ../callcounterbuild

3. Run CMake with the path to the LLVM source. For LLVM 3.5
and later, LLVM can be built with configure even if the demo is built
with CMake.
  e.g. cmake -DLLVM_DIR=</path/to/LLVM/build>/share/llvm/cmake/ ../demo

4. Run make inside the build directory.
  e.g. make

This produces a dynamic callcounter tool called
tools/callcounter/callcounter and a loadable library for printing out the
static number of calls in lib/callcounter-inst/callcounter-lib.so.

Running the dynamic call printer:
e.g.
clang -g -c -emit-llvm ../demo/test/simpletest.c -o calls.bc
tools/callcounter/callcounter calls.bc -o calls
./calls

Running the static call printer:
clang -g -c -emit-llvm ../demo/test/simpletest.c -o calls.bc
opt -load lib/callcounter-inst/callcounter-lib.so --callcounter --analyze calls.bc


Building with Autoconf / configure
==============================================

1. Download and build LLVM as per the standard instructions.
  (http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary)
  
2. Reconfigure the demo project to let it know where you built LLVM.
  e.g.
  cd autoconf
  ./AutoRegen.sh
  <Enter the paths to the LLVM source and build directories when asked>
  cd ..

  NOTE:
  For Ubuntu with llvm 3.5 or later you can use e.g.:
  /usr/lib/llvm-3.5/build/

3. Create a new directory for building.
  e.g. mkdir ../callcounterbuild

4. Change into the new directory.
  e.g. cd ../callcounterbuild

5. Run configure from the new build directory. NOTE: You must configure the
  project with the same debugging and assertion options as you configured LLVM.
  That is, if you enabled LLVM debugging with
  --disable-optimized --enable-debug-runtime --enable-assertions
  then you should do the same for the project
  e.g. ../demo/configure --with-llvmsrc=<path to llvm src dir> --with-llvmobj=<path to llvm build dir> --disable-optimized --enable-debug-runtime --enable-assertions

  Or for Ubuntu 14.10 in particular:
  ../demo/configure --with-llvmsrc=/usr/lib/llvm-3.5/build/ --with-llvmobj=/usr/lib/llvm-3.5/build/ --disable-optimized --enable-debugging --enable-zlib

6. Run make inside the build directory.
  e.g. make

This produces a dynamic callcounter tool in a folder that depends on your
configuration options. If you have assertions and debugging enabled, it will be
Debug+Asserts/bin/callcounter
If you have assertions enabled and debugging disabled, it will be
Release+Asserts/bin/callcounter
The static libraries can similarly be found in
Debug+Asserts/lib/ or Release+Asserts/lib/

Running the dynamic call printer:
e.g.
clang -g -c -emit-llvm ../demo/test/simpletest.c -o calls.bc
Debug+Asserts/bin/callcounter calls.bc -o calls
./calls

