<?xml version='1.0' encoding="UTF-8"?>
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/distcc.xml,v 1.23 2004/11/09 11:37:30 swift Exp $ -->

<guide link="/doc/en/distcc.xml">

<title>Gentoo Distcc Documentation</title>

<author title="Author">
  <mail link="lisa@gentoo.org">Lisa Seelye</mail>
</author>

<author title="Editor">
  <mail link="vapier@gentoo.org">Mike Frysinger</mail>
</author>

<author title="Editor">
  <mail link="erwin@gentoo.org">Erwin</mail>
</author>

<author title="Editor">
  <mail link="swift@gentoo.org">Sven Vermeulen</mail>
</author>

<author title="Editor">
  <mail link="pylon@gentoo.org">Lars Weiler</mail>
</author>

<author title="Reviewer">
  <mail link="blubber@gentoo.org">Tiemo Kieft</mail>
</author>

<abstract>
This document serves as a HOWTO for using distcc with Gentoo.
</abstract>

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/1.0 -->
<license/>

<version>1.9</version>
<date>November 09, 2004</date>

<chapter>
<title>Introduction</title>
<section>
<title>What is distcc?</title>
<body>

<p>
Distcc is a program designed to distribute compiling tasks across a network to 
participating hosts.	It is comprised of a server, <c>distccd</c> and a client
program, <c>distcc</c>.  Distcc can work transparently with <uri 
link="http://ccache.samba.org">ccache</uri> and  Portage with a little work.
</p>

</body>
</section>
<section>
<title>Using distcc to bootstrap</title>
<body>

<p>
If you are planning on using distcc to help you bootstrap a Gentoo installation,
make sure you read the part on <uri link="#bootstrapping">Using distcc to 
Bootstrap</uri> which is situated further down in this document.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Setup</title>
<section>
<title>Dependencies</title>
<body>

<p>
To start off with, to use Distcc all of the computers on your network need to 
have the same GCC versions.  Mixing 3.3.x (where the x varies) is okay, but 
mixing 3.3.x and 3.2.x is not: your programs <b>will</b> have errors in it.
</p>

</body>
</section>
<section>
<title>Installing Distcc</title>
<body>

<p>
There are a couple of options you should know about before you start 
installing distcc.
</p>

<p>
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.
</p>

<pre caption="Installing distcc">
# <i>emerge distcc</i>
</pre>

</body>
</section>
<section>
<title>Setting up Portage to use Distcc</title>
<body>

<p>
Setting up distcc is easy to do with Portage. Execute the following steps on 
each system that should participate in the distributed compiling:
</p>

<pre caption="Integrating Distcc and Portage">
# <i>emerge distcc</i>
# <i>nano -w /etc/make.conf</i>
<comment>(Set N to a suitable number for your particular setup)</comment>
<comment>(A common heuristic strategy is twice the number of total CPUs + 1)</comment>
MAKEOPTS="-jN"
<comment>(Add distcc to your FEATURES variable)</comment>
FEATURES="distcc"
</pre>

<p>
Next you have to specify what hosts you want to use.  Use the 
<c>distcc-config</c> command to set the list of hosts. Here is an example of 
some hosts that might be in your list:
</p>

<pre caption="Examples of host definitions">
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
<comment>(There are also several other methods of setting up hosts.  See the 
distcc manpage for more details.)</comment>
</pre>

<p>
It may all look complicated, but in most cases a variant of line 1 or 2 will 
work.
</p>

<ul>
  <li>Line 1 is just a space-delimited list of hosts</li>
  <li>
    Line 2 is a list of hosts that specifies the maximum amount of jobs (by 
    defining the <c>/N</c> setting) to send that host at any given time
  </li>
</ul>

<p>
Since most people won't be using lines 3 or 4, I'll <uri 
link="http://distcc.samba.org/man/distcc_1.html">point you to</uri> the distcc 
docs for more information.
</p>

<p>
For instance, to set the first line in the previous example:
</p>

<pre caption="Sample command to set the hosts">
# <i>/usr/bin/distcc-config --set-hosts "192.168.0.1 192.168.0.2 192.168.0.3"</i>
</pre>

<p>
Edit <path>/etc/conf.d/distccd</path> to your needs and be sure to set the
<c>--allow</c> directive to allow only hosts you trust. For more information
please see the <uri link="http://distcc.samba.org/security.html">Distcc Security
Design</uri>.
</p>

<p>
Now start the distcc daemon on all the participating computers:
</p>

<pre caption="Starting the distcc daemon">
<comment>(Add distccd to the default runlevel)</comment>
# <i>rc-update add distccd default</i>
<comment>(Start the distcc daemon)</comment>
# <i>/etc/init.d/distccd start</i>
</pre>

</body>
</section>
<section>
<title>Setting up Distcc to Work With Automake</title>
<body>

<p>
This is in some cases easier than the Portage setup.  What you have to do is 
update your <c>PATH</c> variable to include <path>/usr/lib/distcc/bin</path>
in front of the directory that contains <c>gcc</c> (<path>/usr/bin</path>). 
However, there is a caveat.  If you use ccache you have to put distcc after 
the ccache part:
</p>

<pre caption="Setting your path">
# <i>export PATH="/usr/lib/ccache/bin:/usr/lib/distcc/bin:${PATH}"</i>
</pre>

<p>
Then, as you would normally type <c>make</c>, you would type <c>make -jN</c>
(where N is an integer). The value of N depends 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 compiles everything for my desktop (a 1200MHz Athlon
Thunderbird) and I use -j5.  Test your own settings to find the number that
yields the best performance.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Cross-Compiling</title>
<section>
<title>A Note on Cross-Compiling</title>
<body>

<p>
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.
</p>

</body>
</section>
<section>
<title>An Introduction to Cross-compiling</title>
<body>

<p>
If you want to give Cross-compiling a try you can emerge the crossdev package.
I can't support it since I didn't write it, but that's a good way to start
cross-compiling.
</p>

</body>
</section>
</chapter>

<chapter id="bootstrapping">
<title>Using Distcc to Bootstrap</title>
<section>
<title>Step 1: Configure Portage </title>
<body>

<p>
Boot your new box with a Gentoo Linux LiveCD and follow the <uri 
link="/doc/en/handbook/handbook-x86.xml?part=1">installation instructions</uri> 
up until the bootstrapping part. Then configure Portage to use distcc:
</p>

<pre caption="Preliminary Setup">
# <i>nano -w /etc/make.conf</i>
<comment>(Add distcc to the FEATURES variable)</comment>
FEATURES="distcc"
<comment>(Modify MAKEOPTS to include -jN with N an appropriate integer)</comment>
MAKEOPTS="-jN"
</pre>

<pre caption="Setting your path">
# <i>export PATH="/usr/lib/ccache/bin:/usr/lib/distcc/bin:${PATH}"</i>
</pre>

</body>
</section>
<section>
<title>Step 2: Getting Distcc</title>
<body>

<p>
Before the installation of distcc, a user called distcc must be added to the
<path>/etc/passwd</path>:
</p>

<pre caption="Create user distcc">
# <i>echo "distcc:x:240:2:distccd:/dev/null:/bin/false" &gt;&gt; /etc/passwd</i>
</pre>

<p>
Install distcc:
</p>

<pre caption="Getting Distcc on the new box">
# <i>USE='-*' emerge --nodeps distcc</i>
</pre>

</body>
</section>
<section>
<title>Step 3: Setting Up Distcc</title>
<body>

<p>
Run <c>distcc-config</c> to setup distcc:
</p>

<pre caption="Final distcc setup">
<comment>(Substitute host1, host2, ... with the IP number(s) of the participating hosts)</comment>
# <i>/usr/bin/distcc-config --set-hosts "localhost host1 host2 host3 ..."</i>
<comment>An example: <i>/usr/bin/distcc-config --set-hosts "localhost 192.168.0.4 192.168.0.6"</i></comment>
</pre>	

<p>
distcc is now set up to bootstrap! Continue the official installation 
instructions and <e>don't forget</e> to re-emerge distcc after <c>emerge 
system</c>.  This is to make sure that all of the dependencies you want are 
installed as well.
</p>

<note>
During bootstrap and <c>emerge system</c> Distcc may not appear to be used.  
This is expected as some ebuilds do not work well with distcc, so they 
intentionally disable it.
</note>

</body>
</section>
</chapter>

<chapter>
<title>Troubleshooting</title>
<section>
<title>Mozilla and Xfree</title>
<body>

<p>
As you emerge various packages, you'll notice that some of them aren't being 
distributed (and aren't being built in parallel).  This is because the 
developers of the Mozilla and Xfree ebuilds intentionally disable parallel 
building because it is known to cause problems.
</p>

<p>
Sometimes distcc might cause a package to fail to compile. If this happens 
for you, please <uri link="http://bugs.gentoo.org">report</uri> it to us.
</p>

</body>
</section>
<section>
<title>A Mixture of hardened-gcc and non-hardened-gcc Hosts Will Be Faulty</title>
<body>

<p>
With such a long title any explanation here is almost irrelevent.  However, if 
you plan to use distcc across hosts that have the <uri 
link="/proj/en/hardened/etdyn-ssp.xml">PaX/hardened-gcc</uri> and some that do 
not, you will run into problems.
</p>

<p>
The solution requires a little foresight on your part; you have to run 
<c>hardened-gcc -R</c> on the host that has PaX/hardened-gcc, or you have to 
enable PaX protections in your kernel and <c>emerge hardened-gcc</c>.  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.
</p>

</body>
</section>
<section>
<title>Mixed GCC Versions</title>
<body>

<p>
If you have different GCC versions on your hosts, there will likely be very 
weird problems.  The solution is to make certain all hosts have the same GCC 
version.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Distcc Extras</title>
<section>
<title>Distcc Monitors</title>
<body>

<p>
Distcc ships with two monitors.  The text-based one is always built and is 
called <c>distccmon-text</c>.  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.
</p>

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

<pre caption="Starting the monitors">
# <i>distccmon-text N</i>
<comment>(Or)</comment>
# <i>distccmon-gnome</i>
<comment>To monitor Portage's distcc usage you can use:</comment>
# <i>DISTCC_DIR=`portageq envvar DISTCC_DIR` distccmon-text N</i>
<comment>(Or)</comment>
# <i>DISTCC_DIR=`portageq envvar DISTCC_DIR` distccmon-gnome</i>
</pre>

<impo>
Notice the backticks above. <c>portageq</c> is a part of Portage that will
return a piece of information (in this case what DISTCC_DIR is set to).  For
simplicity, most users can use <c>DISTCC_DIR=/var/tmp/portage/.distcc
distccmon-text N</c>
</impo>

</body>
</section>
</chapter>
</guide>
