How to enable ccache
- Audience: All users
- Requires: MacPorts >=1.6.0
This HOWTO covers how to enable building with ccache. It 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 compile 5-10 times faster than they would otherwise.
Step 1: Install ccache
$ sudo port install ccache
Step 2: Edit macports.conf
Open /opt/local/etc/macports/macports.conf in your favorite editor. Find the line
and change it to
And you are done. From now on, MacPorts will use ccache for building.
Please note that cache files are stored in .ccache in your home directory. To see some statistics how useful ccache is for you and how much disk space it takes, use
$ ccache -s
If you believe ccache takes up too much disk space for you, there is the possibility to set a maximum by using something like
$ ccache -M 2G
This makes ccache occupy a maximum of 2 GiB disk space to store cached files.
If you want to free some space, do a cleanup with
$ ccache -c
Use ccache outside MacPorts
To use ccache also outside MacPorts you have to edit your PATH which is set in your .profile or .bash_profile.
First, locate the file you are using. If there is a .bash_profile edit this file, if there is only .profile you want to edit this. There will be this line in there:
Now add the ccache binary path /opt/local/ccache/bin in front of already existing paths:
Important: Reopen your Terminal afterwards.
If you now use commands like gcc they automatically go through ccache.