Posts Tagged ‘Clang’

Compiling Gimp with LLVM/Clang and static analyse

Clang, which use LLVM infrastructure, is a compiler for the C language family. His goal is to offer a moder alternative to GCC. With Clang come a pretty cool static analyser. Here is how to use it for Gimp.

A small disclaimer before, I shamefully copied and adapted the procedure given by Campbell Barton, form the Blender team. (http://wiki.blender.org/index.php/User:Ideasman42/BlenderClang).

Step 1: compile LLVM/Clang

I first tried the LLVM provided by ArchLinux, but the compilation ended with a fatal error. It goes flawlessly with the development version. To fetch it, Campbell Barton’s script works well.

Step 2: configure Gimp’s compilation

First, we need to add  LLVM’s binary to the PATH:

export PATH=$PATH:/opt/llvm/bin

The only difference with a classic GCC compilation, is that we explicitly ask to use Clang’s compiler:

CC=ccc-analyzer ./autogen.sh --prefix=/opt/gimp/

Step 3: compile

If you just want to compile, the procedure doesn’t change.

make -j3

If you want to run a static analyse, you have to use scan-build:

scan-build -o clang make -j3

Just be aware that a static analyse will take a lot of time (3h40 with my Core 2 Duo E4500).

Etape 4: profit !

The static analyzer of Clang will probably find a lot of bug in the code. Yes, there is false positive, but it’s globally remarkably well done ! You can find here the result of the analyse of master i did today: http://pellelatarte.fr/dawa/gimp-llvm/