how to enable and use ccache on FreeBSD 8.2

ccache is a software development tool that caches the output of C/C++ compilation so that the next time, the same compilation can be avoided and the results can be taken from the cache. This can greatly speed up recompiling time.

The following is a step by step guide to how to enable and use ccache on FreeBSD 8.2.

Install ccache by running the following command:

1 [[email protected] ~]#make install clean -C /usr/ports/devel/ccache

Update /etc/make.conf by adding the following lines:

#CCACHE
.if !defined(NO_CCACHE)
CC= /usr/local/libexec/ccache/world/cc
CCX= /usr/local/libexec/ccache/world/c++
.endif

.if ${.CURDIR:M*/ports/devel/ccache}
NO_CCACHE=yes
.endif

Basically we’ve started by installing ccache and proceeded by editing /etc/make.conf as to enable ccache on builds.

Now we need to update the environment.

If you are using csh/tcsh shell add the following to /root/.cshrc:

setenv PATH /usr/local/libexec/ccache:$PATH
setenv CCACHE_PATH /usr/bin:/usr/local/bin
setenv CCACHE_DIR /var/tmp/ccache
setenv CCACHE_LOGFILE /var/log/ccache.log

If you are using zsh add the following to your /root/.zshrc file:

export PATH=/usr/local/libexec/ccache:$PATH
export CCACHE_PATH=/usr/bin:/usr/local/bin
export CCACHE_DIR=/var/tmp/ccache
export CCACHE_LOGFILE=/var/log/ccache.log

If you are using bash add the following to your /root/.profile file:

export PATH=/usr/local/libexec/ccache:$PATH
export CCACHE_PATH=/usr/bin:/usr/local/bin
export CCACHE_DIR=/var/tmp/ccache
export CCACHE_LOGFILE=/var/log/ccache.log

After updating the dotfiles we update the environment. Users of csh/tcsh shells can update by:

1 [[email protected] ~]#source /root/.cshrc

Users of zsh can update the environment by running the following command:

1 [[email protected] ~]#source /root/.zshrc

Anyone using bash can update the environment by running the following command:

1 [[email protected] ~]#source /root/.profile

ccache is installed and the environment is updated. Your next build will be performed with ccache enabled.

To display statistics summary:

1 [[email protected] ~]#ccache -s

To zero statistics:

1 [[email protected] ~]#ccache -z

To set ccache temp size (for example 512MB):

1 [[email protected] ~]#/usr/local/bin/ccache -M 512m

To check out the help file for a list of ccache options:

1 [[email protected] ~]#ccache -h

If you come across a port that fails to build, disable ccache and try again:

1 [[email protected] ~]#make NO_CCACHE=yes install clean

You can find more information regarding ccache through:

1 [[email protected] ~]#man ccache
1 [[email protected] ~]#ccache -h
1 [[email protected] ~]#less /usr/local/share/doc/ccache/ccache-howto-freebsd.txt
1 [[email protected] ~]#links /usr/local/share/doc/ccache/index.html
原文链接:,转发请注明来源!

发表评论