ccache
From Gentoo Linux Wiki
ccache is a compiler cache. It uses the GCC -E switch and a hash to detect when a compilation can be satisfied from cache. The effect is that packages frequently recompile faster on the condition that GCCs output stays the same. ccache will for instance not speed up compile time if you change your CFLAGS or often even USE flags.
The first time that you emerge a package after setting up ccache, there will be a very slight increase in its compilation time, but thereafter when the compilation is cached you will notice significant reductions in completion times.
Contents |
[edit] Installation
Begin with emerging dev-util/ccache:
[edit] Portage
After you've emerged ccache, you'll need to add ccache to the FEATURE line in /etc/make.conf for emerge to use ccache:
... FEATURES="ccache" CCACHE_DIR="/var/tmp/ccache" CCACHE_SIZE="2G" ....
Also note the CCACHE_DIR and CCACHE_SIZE variables. They are optional, and are set to the defaults in the example above. See man make.conf for more information.
[edit] Userspace
There are two ways to configure ccache to work for the regular user. The first is to export the CC variable to point to the ccache symlink when you run the autotools configure script:
Alternatively, set the PATH variable to begin with ccache's symlink directory (/usr/lib/ccache/bin/) in your profile (~/.bash_profile):
...
PATH="/usr/lib/ccache/bin/:${PATH}"
export ${PATH}
[edit] ccache-config
The other way to enable ccache system-wide by default is to have ccache-config install ccaches symlinks. To do this you'll first need to know your systems CHOST:
This should output something similar to:
CHOST="i686-pc-linux-gnu"
Now run ccache-config with the --install-links argument followed by your CHOST. So, following our example above:
[edit] Statistics
To view ccache statistics, run ccache with the -s switch. This will report the users ccache usage, for example:
cache directory /home/gentoouser/.ccache cache hit 2500 cache miss 1311 called for link 10 compile failed 3 couldn't find the compiler 1 autoconf compile/link 98 no input file 87 files in cache 2622 cache size 114.0 Mbytes max cache size 976.6 Mbytes
If you want to see the statistics for another user, for example if you want to see the statistics for your regular user when you're superuser, you'll need to prefix ccache -s with the CCACHE_DIR variable, so:
[edit] Portage
To see the Portage ccache statistics, export the CCACHE_DIR variable you set in /etc/make.conf, if you didn't set this, the default is /var/tmp/ccache:
[edit] Troubleshooting
[edit] Genkernel
Genkernel doesn't use ccache by default, even when you've enabled it for root. You can easily fix this by appending the --kernel-cc option to your genkernel call:
You can configure the KERNEL_CC setting to always use ccache with genkernel by editing /etc/genkernel.conf as follows:
... KERNEL_CC="/usr/lib/ccache/bin/gcc" ...