Gentoo Distcc Documentation Lisa Seelye Mike Frysinger Erwin Sven Vermeulen Tiemo Kieft 1.4 January 19, 2004 This document serves as a HOWTO for using distcc with Gentoo. Introduction
What is distcc?

Distcc is a program designed to distribute compiling tasks across a network to participating hosts. It is comprised of a server, distccd and a client program, distcc. Distcc can work transparently with ccache and Portage with a little set up.

Setup
Dependencies
>=sys-apps/portage-2.0.46-r11
Distcc-2.11 and on require >=sys-apps/portage-2.0.49-r6
>=sys-devel/gcc-config-1.3.1
sys-apps/shadow
(As of version 2.8 and up until 2.11) And the following optional dependencies when you have gtk in your USE flags
>=x11-libs/gtk+-2.2.1
>=sys-apps/portage-2.0.49-r6
>=sys-devel/gcc-config-1.3.1
sys-apps/shadow
In this revision you may chose between a Gnome and GTK GUI monitor, they have the following added dependencies
For GTK:
>=x11-libs/gtk+-2.0.0
>=gnome-base/libglade-2.0.0
x11-libs/pango
For Gnome:
>=x11-libs/gtk+-2.0.0
>=gnome-base/libglade-2.0.0
x11-libs/pango
>=gnome-base/libgnomeui-2.0.0.0
>=gnome-base/libgnome-2.0.0
Installing Distcc

Installing Distcc is very easy. Simply set your USE flags and emerge distcc. But, there's a couple of options you should know about.

Distcc ships with a graphical monitor to monitor tasks that your computer is sending away for compilation. If you use Gnome then put 'gnome' in your USE flags. However, if you don't use Gnome and would still like to have the monitor then you should put 'gtk' in your USE flags.

Setting up Portage to use Distcc

Setting up distcc is very easy to do with Portage. Follow these simple steps on each computer you want to use distcc on:

# emerge distcc
# nano -w /etc/make.conf
If you use distcc-2.11.1 or greater with >=portage-2.0.49-r6, then all you need to do as far as setup is to set your hosts (see next code block), modify MAKEOPTS in /etc/make.conf, and add 'distcc' to FEATURES in /etc/make.conf. Edit your FEATURES flags to include "distcc"

Next you have to specify what hosts you want to use. To do this you can use the distcc-config command to set the list of hosts. Here is an example of some hosts that might be in your list:

192.168.0.1          192.168.0.2                       192.168.0.3
192.168.0.1/2        192.168.0.2                       192.168.0.3/10
192.168.0.1:4000/2   192.168.0.2/1                     192.168.0.3:3632/4
@192.168.0.1         @192.168.0.2:/usr/bin/distccd     192.168.0.3
There are also several other methods of setting up hosts. 
See the distcc manpage for more details.

It may all look complicated, but in most cases a variant of line 1 or 2 will work. An explanation of each line is: Line 1 is just a space-delimited list of hosts that will use default everything. Line 2 is a list of hosts that specifies the maximum number of jobs (by use of the /N) to send that host at any given time (specified with the /n). Since most people won't be using lines 3 or 4, I'll point you to the distcc docs for more information.

A sample command to set the hosts (for line 1) is:

# /usr/bin/distcc-config --set-hosts "192.168.0.1 192.168.0.2 192.168.0.3"

The final step to integrating distcc into Portage is to re-open your /etc/make.conf and edit MAKEOPTS to include -jN (where N is an integer). Typically you will want to set this to the total number of processors in your network plus one.

# nano -w /etc/make.conf
MAKEOPTS=-jN
Don't forget to start the distcc daemon! /etc/init.d/distccd start You will likely have to find a suitable 'N' for your particular setup. Another strategy is 2 x #number of CPUs + 1.
Setting up Distcc to Work With Automake

This is in some cases easier than the Portage setup. What you have to do is update your PATH environmental variable to include /usr/lib/distcc/bin before where gcc (/usr/bin). However, there is a caveat. If you use ccache you have to put distcc after the ccache part. Like so:

# export PATH="/usr/lib/ccache/bin:/usr/lib/distcc/bin:${PATH}"

Then, as you would normally type make, you would type make -jN (where N is an integer). A safe number to use for N varies on your network and the types of computers you are using to compile. For me, I have a dual processor P3 and a K6-2/400 that compile everything for my desktop (a 1200MHz Athlon Thunderbird) and I use -j5. Test your own settings to find the right number.

Using Distcc to Bootstrap
Step 1: Setup on New Box

Next, you have to boot your new box with a Gentoo Linux LiveCD and follow all of the steps up until the bootstrapping. Then proceed with a little preliminary setup on the new box.

Here we add distcc to FEATURES
# nano -w /etc/make.conf
Add "distcc" to FEATURES
Modify MAKEOPTS in /etc/make.conf to include -jN (as described above)

Then add the distcc user to your /etc/passwd:

# echo "distcc:x:240:2:distccd:/dev/null:/bin/false" >>/etc/passwd
Do not forget the `>>'
Step 2: Getting Distcc

Next you will want to issue the following command inside the chroot on the new box.

# USE='-*' emerge --nodeps distcc
According to bug 34262, if the command mentioned above fails with an error like 'pkg-config: command not found', you should issue emerge --nodeps pkgconfig and then try the above emerge again.
Step 3: Setting Up Distcc Itself

Now set up distcc itself...

# /usr/bin/distcc-config --install
# /usr/bin/distcc-config --set-hosts "localhost host1 host2 host3 ..."

distcc should be set up now to bootstrap! Continue the official install guide, and don't forget to re-emerge distcc after emerge system.

It is important to note that during bootstrap and emerge system distcc may not appear to be being used. This is not to be unexpected. Some ebuilds or packages do not work well with distcc, so they intentionally disable distcc.
Troubleshooting
Mozilla and Xfree

As you emerge various packages, you'll notice that they aren't being distributed (and indeed aren't being built in parallel). This is because the developers of Mozilla and Xfree .ebuilds disabled parallel building because it is known to cause problems. This isn't necessarily a distcc problem.

That isn't to say that sometimes distcc will cause a package to fail to compile.

A Mixture of hardened-gcc and non-hardened-gcc Hosts Will Be Faulty

With such a long title any explanation here is almost irrelevent. However, if you plan to use distcc across hosts that have the PaX/hardened-gcc and some that do not, you will run into problems.

The solution requires a little foresight on your part; you have to run hardened-gcc -R on the host that has PaX/hardened-gcc, or you have to enable PaX protections in your kernel and emerge hardened-gcc. Both of which are a good thing to do since for the most part the protections offered by both packages is a good thing and is transparent to the user.

Mixed GCC Versions

If you have differing versions of GCC on your hosts, there will likely be very weird problems. The solution is to make certain all hosts have the same GCC version.

Cross-Compiling
A Note on Cross-Compiling

Cross-compiling is using one architecture to build programs for another architecture. This can be as simple as using an Athlon (i686) to build a program for a K6-2 (i586), or using a Sparc to build a program for a ppc.

A Personal Note on Cross-compiling

I'd love to be able to help out on the Gentoo Cross-compiling effort, but I don't have any non-x86 machines. I can create things that work in theory, but I have to rely on other people to test what I write. That works to an extent, but it's tough. ;-)

In the near future I hope to acquire a Sparc of some type to put Gentoo on so I can play around in-house.

Distcc Extras
Distcc Monitors

Distcc ships with two monitors. The text-based one is always built, it is called distccmon-text. Running it for the first time can be a bit confusing, but it is really quite easy to use. If you run the program with no parameter it will run once. However, if you pass it a number it will update every N seconds, where N is the argument you passed.

The other monitor is only turned on if you enabled gtk or gnome in your USE flags. This one is GTK+ based and runs in an X environment, and it is quite lovely.

There is a caveat to using these programs. If you want to monitor any emerge, you have to start the monitor like so:

# DISTCC_DIR=/path/to/distccdir distccmon-text N
Or you can start the graphical monitor...
# DISTCC_DIR=/path/to/distccdir distccmon-gnome
If you are using Portage and used the above example, this will be DISTCC_DIR=/var/tmp/portage/.distcc. If you aren't using Portage you do not need to specify DISTCC_DIR (i.e., just type distccmon-text N).
Future Plans for Distcc and Gentoo
distcc-subnetscan

distcc-subnetscan is a perl program in development that will scan a subnet for hosts that have a participating distcc daemon. Even this will be enhanced to test if the daemon on a remote host will conform to a specific CHOST setting to make cross-compiling easier.

The perl script is being kept at right here until a more formal home can be found.