<?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.14 2004/01/19 15:36:31 blubber 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="Reviewer">
  <mail link="swift@gentoo.org">Sven Vermeulen</mail>
</author>
<author title="Reviewer, Editor">
  <mail link="blubber@gentoo.org">Tiemo Kieft</mail>
</author>

<license/>

<version>1.4</version>
<date>January 19, 2004</date>

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

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

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

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

<pre caption="Distcc dependencies (2.8 through 2.10)">
&gt;=sys-apps/portage-2.0.46-r11
<codenote>Distcc-2.11 and on require &gt;=sys-apps/portage-2.0.49-r6</codenote>
&gt;=sys-devel/gcc-config-1.3.1
sys-apps/shadow
<codenote>(As of version 2.8 and up until 2.11) And the following optional dependencies when you have <i>gtk</i> in your <i>USE</i> flags</codenote>
&gt;=x11-libs/gtk+-2.2.1
</pre>

<pre caption="Distcc Dependencies (post 2.11.1)">
&gt;=sys-apps/portage-2.0.49-r6
&gt;=sys-devel/gcc-config-1.3.1
sys-apps/shadow
<codenote>In this revision you may chose between a Gnome and GTK GUI monitor, they have the following added dependencies</codenote>
<codenote>For GTK:</codenote>
&gt;=x11-libs/gtk+-2.0.0
&gt;=gnome-base/libglade-2.0.0
x11-libs/pango
<codenote>For Gnome:</codenote>
&gt;=x11-libs/gtk+-2.0.0
&gt;=gnome-base/libglade-2.0.0
x11-libs/pango
&gt;=gnome-base/libgnomeui-2.0.0.0
&gt;=gnome-base/libgnome-2.0.0
</pre>

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

<p>
Installing Distcc is very easy.  Simply set your USE flags and <c>emerge 
distcc</c>.  But, there's a couple of options you should know about.
</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>

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

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

<pre caption="Integrating Distcc and Portage">
# <i>emerge distcc</i>
# <i>nano -w /etc/make.conf</i>
</pre>

<impo>
If you use distcc-2.11.1 or greater with &gt;=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 <path>/etc/make.conf</path>, and add 'distcc' to FEATURES in 
<path>/etc/make.conf</path>.
</impo>

<note>
Edit your FEATURES flags to include &quot;distcc&quot;
</note>

<p>
Next you have to specify what hosts you want to use.  To do this you can 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
<codenote>There are also several other methods of setting up hosts. </codenote>
<codenote>See the distcc manpage for more details.</codenote>
</pre>

<p>
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 <c>/n</c>).  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>
A sample command to set the hosts (for line 1) is:
</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>
The final step to integrating distcc into Portage is to re-open your 
<path>/etc/make.conf</path> and edit <c>MAKEOPTS</c> to include <c>-jN</c> 
(where N is an integer).  Typically you will want to set this to the total 
number of processors in your network plus one.
</p>

<pre caption="Final steps in make.conf">
# <i>nano -w /etc/make.conf</i>
MAKEOPTS=-jN
</pre>

<impo>
Don't forget to start the distcc daemon! <c>/etc/init.d/distccd start</c>
</impo>

<note>
You will likely have to find a suitable 'N' for your particular setup. Another
strategy is 2 x #number of CPUs + 1.
</note>

</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> environmental variable to include 
<path>/usr/lib/distcc/bin</path> before where gcc (<path>/usr/bin</path>).  
However, there is a caveat.  If you use ccache you have to put distcc after 
the ccache part.  Like so:
</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).  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.
</p>

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

<chapter>
<title>Using Distcc to Bootstrap</title>
<section>
<title>Step 1: Setup on New Box</title>
<body>

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

<pre caption="Preliminary Setup">
<codenote>Here we add distcc to FEATURES</codenote>
# <i>nano -w /etc/make.conf</i>
<codenote>Add &quot;distcc&quot; to FEATURES</codenote>
<codenote>Modify MAKEOPTS in <path>/etc/make.conf to include -jN (as described above)</path></codenote>
</pre>

<p>
Then add the distcc user to your <path>/etc/passwd</path>:
</p>

<pre caption="Add the distcc user to /etc/passwd">
# <i>echo "distcc:x:240:2:distccd:/dev/null:/bin/false" &gt;&gt;/etc/passwd</i>
<codenote>Do not forget the `<i>&gt;&gt;</i>'</codenote>
</pre>

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

<p>
Next you will want to issue the following command inside the chroot on the new 
box.
</p>

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

<note>
According to <uri link="http://bugs.gentoo.org/show_bug.cgi?id=34262">bug
34262</uri>, if the command mentioned above fails with an error like
'pkg-config: command not found', you should issue <c>emerge --nodeps
pkgconfig</c> and then try the above emerge again.
</note>

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

<p>
Now set up distcc itself...
</p>

<pre caption="Final distcc setup">
# <i>/usr/bin/distcc-config --install</i>
# <i>/usr/bin/distcc-config --set-hosts "localhost host1 host2 host3 ..."</i>
</pre>  

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

<note>
It is important to note that during bootstrap and <c>emerge system</c> 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.
</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 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.
</p>

<p>
That isn't to say that sometimes distcc will cause a package to fail to compile.
</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="http://www.gentoo.org/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 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.
</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>A Personal Note on Cross-compiling</title>
<body>

<p>
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 <e>in 
theory</e>, but I have to rely on other people to test what I write.  That 
works to an extent, but it's tough. ;-)
</p>

<p>
In the near future I hope to acquire a Sparc of some type to put Gentoo on so 
I can play around in-house.
</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, it 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 and runs in an X environment,
and it is quite lovely.
</p>

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

<pre caption="Starting the monitors">
# <i>DISTCC_DIR=/path/to/distccdir distccmon-text N</i>
<codenote>Or you can start the graphical monitor...</codenote>
# <i>DISTCC_DIR=/path/to/distccdir distccmon-gnome</i>
</pre>

<impo>
If you are using Portage and used the above example, this will be 
<c>DISTCC_DIR=/var/tmp/portage/.distcc</c>.
</impo>

<note>
If you aren't using Portage you do not need to specify DISTCC_DIR (i.e., just 
type distccmon-text N).
</note>

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

<chapter>
<title>Future Plans for Distcc and Gentoo</title>
<section>
<title>distcc-subnetscan</title>
<body>

<p>
<c>distcc-subnetscan</c> 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 
<c>CHOST</c> setting to make cross-compiling easier.
</p>

<p>
The perl script is being kept at <uri link="http://dev.gentoo.org/~lisa/distcc/distcc-subnetscan/distcc-subnetscan.pl">
right here</uri> until a more formal home can be found.
</p>

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