I wrote last year that ccache 3 allows you to share object files between trees. It's true, and it's great! (ccache 3.1 is available in macports, but Ubuntu 10.10 still has 2.4. Thankfully it's easy to build from source.)
But in my original post, I neglected to mention that in order to make this
work, you need to set the CCACHE_BASEDIR
environment variable. ccache uses
this environment variable to determine which paths to rewrite into relative
paths and which paths to leave as absolute. You just need to set it to some
directory which contains all your source code but doesn't include system
headers; $HOME
is probably a good bet.
As proof that this actually works, here are my (abbreviated) ccache stats after clearing my cache and then compiling two identical Firefox trees:
$ ccache -s
cache hit (direct) 3515
cache hit (preprocessed) 102
cache miss 3623
called for link 60
compile failed 38
preprocessor error 20
files in cache 10356
cache size 1.3 Gbytes
max cache size 5.0 Gbytes
We have 3623 cache misses (from the first compile) and 3515 + 102 = 3617 cache hits (from the second compile). Not bad!