/[gentoo]/xml/htdocs/doc/en/cross-compiling-distcc.xml
Gentoo

Contents of /xml/htdocs/doc/en/cross-compiling-distcc.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download) (as text)
Wed Jan 25 08:56:36 2006 UTC (8 years, 7 months ago) by neysx
Branch: MAIN
Changes since 1.2: +2 -3 lines
File MIME type: application/xml
sparc-unknown-linux-gnu-cc symlink should have been removed

1 neysx 1.1 <?xml version="1.0" encoding="UTF-8"?>
2     <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
3 neysx 1.3 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/cross-compiling-distcc.xml,v 1.2 2006/01/25 05:24:18 vanquirius Exp $ -->
4 neysx 1.1
5     <guide link="/doc/en/cross-compiling-distcc.xml">
6     <title>DistCC Cross-compiling Guide</title>
7    
8     <author title="Author">
9     <mail link="agaffney@gentoo.org">Andrew Gaffney</mail>
10     </author>
11     <author title="Editor">
12     <mail link="jackdark@gmail.com">Joshua Saddler</mail>
13     </author>
14    
15     <abstract>
16     This guide shows you how to set up distcc for cross-compiling across different
17     processor architectures.
18     </abstract>
19    
20     <!-- The content of this document is licensed under the CC-BY-SA license -->
21     <!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
22     <license/>
23    
24 neysx 1.3 <version>1.2</version>
25 vanquirius 1.2 <date>2006-01-25</date>
26 neysx 1.1
27     <chapter>
28     <title>Cross-compiling with distcc</title>
29     <section>
30     <title>Introduction</title>
31     <body>
32    
33     <p>
34     <c>distcc</c> is a tool that lets you share the burden of software compiling
35     across several networked computers. As long as the networked boxes are all using
36     the same toolchain built for the same processor architecture, no special
37     <c>distcc</c> setup is required. But what do you do if you need to compile for a
38     different architecture using differing computers? This guide will show you how
39     to configure <c>distcc</c> to compile for different architectures.
40     </p>
41    
42     </body>
43     </section>
44     <section>
45     <title>Emerge the needed utilities</title>
46     <body>
47    
48     <p>
49     First, you will need to emerge <c>crossdev</c> on all the machines that will be
50     involved in the compiling process. <c>crossdev</c> is a tool that makes building
51     cross-architecture toolchains easy. It was originally written by <mail
52     link="kumba@gentoo.org">Joshua Kinard</mail> and was re-written from the ground
53     up by <mail link="vapier@gentoo.org">Mike Frysinger</mail>. Its usage is
54     straightforward: <c>crossdev -t sparc</c> will build a full cross-toolchain
55     targetting the Sparc architecture. This includes binutils, gcc, glibc, and
56     linux-headers. If you need more help, try running <c>crossdev --help</c>.
57     Obviously, you will need to emerge the proper cross-toolchain on all the helper
58     boxes.
59     </p>
60    
61     <p>
62     Next, you will need to emerge <c>distcc</c> on all the machines that will be
63     involved in the process. This includes the box that will run emerge and the
64     boxes with the cross-compilers. Please see the <uri
65     link="/doc/en/distcc.xml">Gentoo Distcc Documentation</uri> for more
66     information on setting up and using <c>distcc</c>.
67     </p>
68    
69     </body>
70     </section>
71     <section>
72     <title>Arch-specific notes</title>
73     <body>
74    
75     <p>
76     If you are cross-compiling between different subarchitectures for Intel x86
77     (e.g. i586 and i686), you must still build a full cross-toolchain for the
78     desired CHOST, or else the compilation will fail. This is because i586 and i686
79     are actually different CHOSTs, despite the fact that they are both considered
80     "x86." Please keep this in mind when you build your cross-toolchains. For
81     example, if the target box is i586, this means that you must build i586
82     cross-toolchains on your i686 helper boxes.
83     </p>
84    
85     </body>
86     </section>
87     <section>
88     <title>Configuring distcc to cross-compile correctly</title>
89     <body>
90    
91     <p>
92     In the default distcc setup, cross-compiling will <e>not</e> work properly. The
93     problem is that many builds just call <c>gcc</c> instead of the full compiler
94     name (e.g. <c>sparc-unknown-linux-gnu-gcc</c>). When this compile gets
95     distributed to a distcc helper box, the native compiler gets called instead of
96     your shiny new cross-compiler.
97     </p>
98    
99     <p>
100     Fortunately, there is a workaround for this little problem. All it takes is a
101     wrapper script and a few symlinks on the box that will be running
102     <c>emerge</c>. I'll use my Sparc box as an example. Wherever you see
103     <c>sparc-unknown-linux-gnu</c> below, you will want to insert your own CHOST
104     (<c>x86_64-pc-linux-gnu</c> for an AMD64 box, for example). When you first
105     emerge distcc, the <path>/usr/lib/distcc/bin</path> directory looks like this:
106     </p>
107    
108     <note>
109     The following instructions are to be performed only on the box running the
110     emerge. Do not perform these steps on the helper boxes.
111     </note>
112    
113     <pre caption="Available compilers">
114     # <i>cd /usr/lib/distcc/bin</i>
115     # <i>ls -l</i>
116     total 0
117     lrwxrwxrwx 1 root root 15 Dec 23 20:13 c++ -&gt; /usr/bin/distcc
118     lrwxrwxrwx 1 root root 15 Dec 23 20:13 cc -&gt; /usr/bin/distcc
119     lrwxrwxrwx 1 root root 15 Dec 23 20:13 g++ -&gt; /usr/bin/distcc
120     lrwxrwxrwx 1 root root 15 Dec 23 20:13 gcc -&gt; /usr/bin/distcc
121     lrwxrwxrwx 1 root root 15 Dec 23 20:13 sparc-unknown-linux-gnu-c++ -&gt; /usr/bin/distcc
122     lrwxrwxrwx 1 root root 15 Dec 23 20:13 sparc-unknown-linux-gnu-g++ -&gt; /usr/bin/distcc
123     lrwxrwxrwx 1 root root 15 Dec 23 20:13 sparc-unknown-linux-gnu-gcc -&gt; /usr/bin/distcc
124     </pre>
125    
126     <p>
127     Here is what you want to do:
128     </p>
129    
130     <pre caption="Modifying distcc">
131     # <i>rm c++ g++ gcc cc</i>
132     </pre>
133    
134     <p>
135     Next, we'll create the new script on this box. Fire up your favorite editor and
136     create a file with the following text in it, then save it as
137     <path>sparc-unknown-linux-gnu-wrapper</path>. Remember to change the CHOST (in
138     this case, <c>sparc-unknown-linux-gnu</c>) to the actual CHOST of the box that
139     will be running the emerge.
140     </p>
141    
142     <pre caption="The new wrapper script">
143     #!/bin/bash
144 vanquirius 1.2 exec /usr/lib/distcc/bin/sparc-unknown-linux-gnu-g${0:$[-2]} "$@"
145 neysx 1.1 </pre>
146    
147     <p>
148     Next, we'll make the script executable and create the proper symlinks:
149     </p>
150    
151     <pre caption="Creating the symlinks">
152     # <i>chmod a+x sparc-unknown-linux-gnu-wrapper</i>
153 vanquirius 1.2 # <i>ln -s sparc-unknown-linux-gnu-wrapper cc</i>
154 neysx 1.1 # <i>ln -s sparc-unknown-linux-gnu-wrapper gcc</i>
155 vanquirius 1.2 # <i>ln -s sparc-unknown-linux-gnu-wrapper g++</i>
156 neysx 1.1 # <i>ln -s sparc-unknown-linux-gnu-wrapper c++</i>
157     </pre>
158    
159     <p>
160     When you're done, <path>/usr/lib/distcc/bin</path> will look like this:
161     </p>
162    
163     <pre caption="A proper set of compilers">
164     # <i>ls -l</i>
165     total 4
166     lrwxrwxrwx 1 root root 25 Jan 18 14:20 c++ -&gt; sparc-unknown-linux-gnu-wrapper
167     lrwxrwxrwx 1 root root 25 Jan 18 14:20 cc -&gt; sparc-unknown-linux-gnu-wrapper
168     lrwxrwxrwx 1 root root 25 Jan 18 14:20 g++ -&gt; sparc-unknown-linux-gnu-wrapper
169     lrwxrwxrwx 1 root root 25 Jan 18 14:20 gcc -&gt; sparc-unknown-linux-gnu-wrapper
170     lrwxrwxrwx 1 root root 15 Nov 21 10:42 sparc-unknown-linux-gnu-c++ -&gt; /usr/bin/distcc
171     lrwxrwxrwx 1 root root 15 Nov 21 10:42 sparc-unknown-linux-gnu-g++ -&gt; /usr/bin/distcc
172     lrwxrwxrwx 1 root root 15 Jul 27 10:52 sparc-unknown-linux-gnu-gcc -&gt; /usr/bin/distcc
173     -rwxr-xr-x 1 root root 70 Jan 18 14:20 sparc-unknown-linux-gnu-wrapper
174     </pre>
175    
176     <p>
177     Congratulations; you now have a (hopefully) working cross-distcc setup.
178     </p>
179    
180     </body>
181     </section>
182     <section>
183     <title>How this works</title>
184     <body>
185    
186     <p>
187     When <c>distcc</c> is called, it checks to see what it was called as (e.g.
188     <c>i686-pc-linux-gnu-gcc</c>, <c>sparc-unknown-linux-gnu-g++</c>, etc.) When
189     distcc then distributes the compile to a helper box, it passes along the name
190     it was called as. The distcc daemon on the other helper box then looks for a
191     binary with that same name. If it sees just <c>gcc</c>, it will look for
192     <c>gcc</c>, which is likely to be the native compiler on the helper box, if it
193     is not the same architecture as the box running <c>emerge</c>. When the
194     <e>full</e> name of the compiler is sent (e.g.
195     <c>sparc-unknown-linux-gnu-gcc</c>), there is no confusion.
196     </p>
197    
198     </body>
199     </section>
200     </chapter>
201     </guide>

  ViewVC Help
Powered by ViewVC 1.1.20