Faster FreeBSD Ports Collection Compiles with ccache and tmpfs
ccache
is a compiler cache. It speeds up recompilation by caching previous
compilations and detecting when the same compilation is being done again.
Sounds like something you would want to have if you’re compiling most software
from source, as I do. As a bonus, we’re setting the work directory to a
ramdisk, so all compile activity is done in memory instead of on disk. Here’s
how you do it.
Install ccache
:
cd /usr/ports/devel/ccache
make install clean
Add a couple of lines to /etc/make.conf
:
WRKDIRPREFIX=/ram
CCACHE_DIR=/var/cache/ccache
WITH_CCACHE_BUILD=yes
Create a /ram
folder for the tmpfs
mountpoint. We’re using a size of 2 GB here, adjust to taste:
mkdir /ram
echo 'none /ram tmpfs rw,size=2147483648 0 0' >> /etc/fstab
mount /ram
Set some defaults in ~/.ccache/ccache.conf
:
max_size = 5G
cache_dir = /var/cache/ccache
Enjoy faster compiles.
To check space usage of the cache and other stats:
ccache -s