Monday, March 14, 2011

distcc and ccache in FreeBSD

Install software first
cd /usr/local/bin/distcc && make install clean
cd /usr/local/bin/ccache && make install clean
cd /usr/ports/sysutils/bsdadminscripts && make install clean

Enable distcc in /etc/rc.conf
distccd_enable="YES"
distccd_flags="--allow 192.168.1.0/24 --listen 192.168.1.1 --port 3632 --user distcc --log-file=/var/log/distccd.log --daemon -P /var/run/distccd.pid"

export variables
export DISTCC_DIR=/usr/local/etc/distcc
export CCACHE_DIR=/data/ccache
export CCACHE_NOLINK=yes
export CCACHE_UMASK=002
export CCACHE_PREFIX=distcc_wrapper

dmake() {
    make CC="ccache gcc" CXX="ccache g++" "$@"
}


prepare distcc & ccache structucre
mkdir -p /usr/local/etc/distcc
mkdir -p /data/ccache && chmod 770 /data/ccache

## define distcc cluserr nodes by hostname or ip
echo "localhost 192.168.1.2" > /usr/local/etc/distcc/hosts


Modify /etc/make.conf
# /usr/local/etc/buildflags.conf
BUILDFLAGS= /usr/local/share/bsdadminscripts/buildflags.mk
.if exists(${BUILDFLAGS})
.include "${BUILDFLAGS}"
.endif

Adjust number of threads in for ports in /usr/local/etc/buildflags.conf
(made from /usr/local/etc/buildflags.conf.sample)
(...)
# ---< configure ports >-------------------------------------------------------
/usr/ports/*{
        # Clustering
        FORCE_MAKE_JOBS
        MAKE_JOBS_NUMBER=       8   ## total number of cores in cluster x 2
        USE_DISTCC
        USE_CCACHE

(...)

Restart distccd daemon and go compile something!

#check cluster members:
distcc --show-hosts
#monitor current job distribution
distccmon-text 1

#dispay ccache stats
ccache -s
#clean cache
ccache -C

No comments:

Post a Comment