world leader in high performance signal processing
Trace: » ccache


ccache is a compiler cache. It acts as a caching pre-processor to C/C++ compilers, using the -E compiler switch and a hash to detect when a compilation can be satisfied from cache. This often results in a 5 to 10 times speedup in common compilations. For more information, visit the ccache homepage.

For our purposes, we'll cover how to integrate ccache with the Blackfin toolchain so as to speed up rebuilds of things like the kernel or the uClinux distribution.

Installing ccache

Your distribution probably includes this package, but if not, the build/install follows the normal configure/make path.

sudo make install

Integrating with Blackfin Toolchain

While you can execute ccache directly like so:

ccache bfin-uclinux-gcc ...

It would require modifying all of the build systems which can be quite troublesome. Instead, we can create some symlinks and tweak our PATH to get ccache support transparently.

First you'll need to set up an empty directory for this full of symlinks. You can place this anywhere, but we'll just pick an easy location here.

mkdir ~/bfin-ccache
cd ~/bfin-ccache
tuples="bfin-elf bfin-uclinux bfin-linux-uclibc"
compilers="gcc g++ c++"
for t in $tuples ; do
    for c in $compilers ; do
        ln -s `which ccache` ${t}-${c}

We need to create a symlink for every gcc compiler we have. In this case, three toolchains and three compiler frontends.

The last step is to add this directory to your PATH before the directory of the real compilers. This is important; the ccache symlinks have to be found first in order for things to work.

export PATH="~/bfin-ccache:$PATH"

Now when you compile the same exact code twice, the result should be cached automatically thus making the second compile utilize the cached object code from the first compile.

Common ccache tweaks

Since the ccache is automatically invalidated when the compiler itself is updated, it can often be useful to maintain a cache for each major version. For example, a cache for the 2006R1 toolchain, the 2006R2 toolchain, and the 2007R1 toolchain can be quite useful when having to switch between them thus preventing cache thrashing. You can accomplish this by changing the CCACHE_DIR environment variable.

export CCACHE_DIR="$HOME/.ccache-bfin/2007R1"

You can also control the size of individual caches by using ccache -M.

For more options, see the ccache(1) man page.