Waiting for unit compilations to finish during development, particularly with G++ and heavy optimizations can be quite time consuming. A run of make distcheck escalates the problem, because all files during a dist need to be rebuilt. Small errors triggered late in the dist build might require several time consuming restarts of the build process.

With ccache, a tool exists that can majorly speed up this process. I’ve been using it successfully for several years now. A related development aid is colorgcc which is a colorization wrapper for gcc. This also is under heavy use for my development. It turns out that some tweaks are needed to get it working together with ccache though.

Here’s how to use the tools in combination to speed up regular project builds and also distcheck:

Get and install ccache.
Wrapping compiler invocations with ccache will cache recompilations of the same units. ccache needs a directory to store the cache contents; this defaults to ~/.ccache which might not be the best choice for network homes or encrypted homes. Using /tmp is also suboptimal since it is usually cleaned upon reboots. So I’d recommend to put this into your .bashrc:

export CCACHE_DIR="/var/tmp/ccache-$USER"

This will retain the compiler cache across reboots in /var/tmp.

Get and install colorgcc.
Then some patching is in order, especially if you use multiple versions of gcc and need ccache integration. Based on colorgcc from Ubuntu-9.10, I’ve prepared a patch for this (it has been sent to Jamie Moyers some while ago) to be found here: http://testbit.eu/~timj/blogstuff/xyv-colorgcc.diff

To briefly summarize its effects:

This allows colorgcc to be used through a bunch of links, e.g. by creating: