The Raspberry Pi obviously isn't the fastest build host in the world. Probably not even in your house. So, in order to speed up builds one of the things you can do is use distcc and a cross compiler on your PC. The three basic steps are to build the cross-compiler, configure the distcc server, and the distcc client
Build the Cross-Compiler
The first thing to do is set up the cross compiler on your PC.
If you follow the steps exactly you should end up with 3 directories.
/opt/crosstool-ng
/opt/rpi-crosstool-ng
/opt/rpi-crosstool-ng-build
1.) Download crosstool-ng and extract somewhere, following the instructions from:
http://crosstool-ng.org/#download_and_usage
Version 1.19.0 appears to be the latest. That is what I used.
If you intend to follow along with this exactly, my --prefix was /opt/crosstool-ng
Once done with the crosstools-ng setup, you also need to add the new bin directory to you path. At this point my .bash_profile has:
export PATH=$PATH:~/bin:/opt/crosstool-ng/bin
2.) Create two more directories.
One is the build directory and one is where the armv6hl cross compiler will be installed.
I made /opt/rpi-crosstool-ng and /opt/rpi-crosstool-ng-build
3.) Copy the contents of the attached config.txt file to /opt/rpi-crosstool-ng-build/.config
4.) For whatever reason the installer wants to be able to delete /opt/rpi-crosstool-ng so I temporarily changed /opt to be owned by my user, i.e. 'chown joeuser:joeuser /opt'
5.) In /opt/rpi-crosstool-ng-build run 'ct-ng build'
6.) Once it's done fix permissions on /opt, 'chown root:root /opt'
7.) Create tuple-less links to the binaries, (i.e. gcc for armv6hl-unknown-linux-gnueabi-gcc):
cd /opt/rpi-crosstool-ng/bin && for i in $(ls -1 armv6hl*); do ln -s $i $(echo $i | cut -d "-" -f 5); done
Configure distcc on the server
On the distcc server (same host as you just set up your cross-compiler on),
1.) yum install distcc-server
2.) chkconfig distccd on #(if you want the service to start automatically
3.) Edit /etc/sysconfig/distccd. In the OPTIONS= line add a --allow option if it's not there with your host/subnet that should have access. Something like '--allow 192.168.1.0/24'
4.) Also add the path to the cross-compiler. (To do: confirm which is actually the one that's needed):
DISTCCPATH="/opt/rpi-crosstool-ng/bin"
DISTCC_PATH="/opt/rpi-crosstool-ng/bin"
PATH="/opt/rpi-crosstool-ng/bin"
5.) Open port 1234 in your firewall software of choice, so your client can access it. For iptables adding this to /etc/sysconfig/iptables, and issuing a 'service iptables restart' should do the trick
-A INPUT -m state --state NEW -m tcp -p tcp --dport 1234 -j ACCEPT
6.) Start the distccd service
service distccd start
Configure distcc on the Raspberry Pi
1.) yum install distcc
2.) Create links in your to distcc in your path.
I set them up in ~/bin,
mkdir ~/bin && cd ~/bin && for i in c++ cpp g++ gcc cc; do ln -s /bin/distcc $i; done
If you do use ~/bin, make sure to update your path in ~/.bash_profile or somewhere else appropriate
export PATH=~/bin:$PATH
3.) Edit /etc/distcc/hosts and add any distcc servers you've configured on a single line, space separated, in the format <ipaddress>:<port>. If you didn't change anything on the server setup the default on Fedora 19 is 1234.
4.) Add up all the CPU Cores on your servers and update your ~/.bash_profile, or whatever is appropriate for you, with the total
export RPM_BUILD_NCPUS=<your total here>
5.) Login and log out for your new environment variables to take effect or manually export them before testing.
5.) Test by compiling something (hello world for example) with the -c option, 'gcc -c hello.c -o hello.o'
#include<stdio.h>
main()
{
printf("Hello World");
}
You should see distcc output on your distcc server in /var/log/messages indicating it was able to successfully compile the o file.
If it worked, you should be able to rpmbuild using your PC to do the bulk of the work. Some things will still be slow, configure, checks, tests, etc, but in most cases they are a fraction of the time spent building a package.
Fixes/corrections/improvements welcome.