<?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.28 2005/07/01 22:42:42 smithj 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.13</version>
<date>2005-07-01</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>, Portage, and Automake with a
little setup.
</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 section <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>
In order to use Distcc, all of the computers on your network need to have the
same GCC versions. For example, mixing 3.3.x  (where the x varies) is okay, but
mixing 3.3.x with 3.2.x <b>may</b> result in compilation errors or runtime
errors.
</p>

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

<p>
There are a couple of options you should be aware of 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 Portage to use distcc is easy. 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 strategy is setting N as twice the number of total CPUs + 1
available)</comment>
MAKEOPTS="-jN"
<comment>(Add distcc to your FEATURES)</comment>
FEATURES="distcc"
</pre>

</body>
</section>
<section>
<title>Specifying Participating Hosts</title>
<body>

<p>
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>
<comment>If you wish to compile on the local machine you should put 'localhost'
in the hosts list.  Conversely if you do not wish to use the local machine to
compile (which is often the case) omit it from the hosts list.  On a slow
machine using localhost may actually slow things down. Make sure to test your
settings for performance.</comment>
</pre>

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

<p>
Since most people won't be using lines 3 or 4, I'll <uri 
link="http://distcc.samba.org/man/distcc_1.html">refer to</uri> the distcc 
docs (man distcc) 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 added security,
you should also use the <c>--listen</c> directive to tell the distcc daemon
what IP to listen on (for multi-homed systems). More information on distcc
security can be found at <uri
link="http://distcc.samba.org/security.html">Distcc Security Design</uri>.
</p>

<impo>
It is important to use --allow and --listen.  Please read the distccd manpage
or the above seurity document for more information.
</impo>


<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>
<comment>You can put this in your .bashrc or equivelant file to have the PATH
set every time you log in</comment>
</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.  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 to follow <uri 
link="http://dev.gentoo.org/~vapier/CROSS-COMPILE-HOWTO">The Cross Compile 
HOWTO</uri>; Crossdev is deprecated.
</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</comment>
FEATURES="distcc"
<comment>(Modify MAKEOPTS to include -jN, where N is twice the number of CPUs
+1 available)</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>

<impo>
It is important to note that adding users like this is very bad.  We only do 
it here because there is no <c>useradd</c> utility (which you normally use for
adding users) yet at this stage of installation.
</impo>

<p>
Install distcc:
</p>

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

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

<p>
Run <c>distcc-config --install</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 with the official installation 
instructions and <e>do not 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>

<p>
Recent Portage updates have made Portage use <c>${CHOST}-gcc</c> instead of 
<c>gcc</c>.  This means that if you're mixing i686 machines with other types
(i386, i586) you will run into problems.  A workaround for this may be to 
<c>export CC='gcc' CXX='c++'</c> or to put it in <path>/etc/make.conf</path>.
</p>

<impo>
Doing this explicitly redefines some behaviour of Portage and may have some
weird results in the future.  Only do this if you're mixing CHOSTs.
</impo>


</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.  For Gentoo the GUI monitor has been called
<c>distccmon-gui</c> for less confusion. Elsewhere it may be referred to as
<c>distccmon-gnome</c>.
</p>

<pre caption="Starting the monitors">
# <i>distccmon-text N</i>
<comment>(Or)</comment>
# <i>distccmon-gui</i>
<comment>To monitor Portage's distcc usage you can use:</comment>
# <i>DISTCC_DIR="/var/tmp/portage/.distcc/" distccmon-text N</i>
<comment>(Or)</comment>
# <i>DISTCC_DIR="/var/tmp/portage/.distcc/" distccmon-gui</i>
</pre>

<impo>
If your distcc directory is elsewhere, change the DISTCC_DIR variable
accordingly.
</impo>

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