<bodystyle="background-color: rgb(255, 255, 255);"><h3><aname="title"href="http://www.eluaproject.net/en/Building_GCC_for_i386"class="local">Building GCC for i386</a></h3>
<divclass="content">
<p>At first, the idea of an i386 "cross" compiler under Linux seems
strange. After all, you're already running Linux on a i386 compatible
architecture. But the compiler is sometimes tied in misterious ways
with the operating system it's running on (see for example <ahref="http://wiki.osdev.org/GCC_Cross-Compiler">this page</a>
for some possible symptoms). And after all, you want to use Newlib, not
libc, and to customize your development environment as much as
possible. This tutorial will show you how to do that.</p>
<p><strong>DISCLAIMER: I'm by no means a specialist in the
GCC/newlib/binutils compilation process. I'm sure that there are better
ways to accomplish what I'm describing here, however I just wanted a
quick and dirty way to build a toolchain, I have no intention in
becoming too intimate with the build process. If you think that what I
did is wrong, innacurate, or simply outrageously ugly, feel free to <ahref="http://www.giga.puc-rio.br/cgi-bin/elua.cgi?p=Contact">contact me</a> and I'll make the necessary corrections. And of course, this tutorial comes without any guarantees whatsoever.</strong></p>
<h2>› Prerequisites</h2>
<p>To build your toolchain you'll need:</p>
<ul><li>a computer running Linux: I use Ubuntu 8.04, but any Linux
will do as long as you know how to find the equivalent of "apt-get" for
your distribution. I won't be going into details about this, google it
and you'll sure find what you need. It is also assumed that the Linux
system already has a "basic" native toolchain installed (gcc/make and
related). This is true for Ubuntu after installation. Again, you might
need to check your specific distribution.</li><li>GNU binutils: get it from <ahref="http://ftp.gnu.org/gnu/binutils/">here</a>.
At the moment of writing this, the latest versions is 2.18, which for
some weird reason refuses to compile on my system, so I'm using 2.17
instead.</li><li>GCC: version 4.3.0 or newer is recommended. As
I'm writing this, the latest GCC version is 4.3.1 which I'll be using
for this tutorial. Download it from <ahref="http://gcc.gnu.org/mirrors.html">here</a> after choosing a suitable mirror.</li><li>Newlib: as I'm writing this, the latest official Newlib version is 1.16.0. Download it from the <ahref="ftp://sources.redhat.com/pub/newlib/index.html">Newlib FTP directory</a>.</li><li>Also,
the tutorial assumes that you're using bash as your shell. If you use
something else, you might need to adjust some shell-specific commands. </li></ul>
<p>Also, you need some support programs/libraries in order to compile the toolchain. To install them:</p>
<ul><li><code>--disable-newlib-supplied-syscalls:</code> this deserves a page of its own, but I won't cover it here. For an explanation, see for example <ahref="http://openhardware.net/Embedded_ARM/NewLib_Stubs/">this page</a>.</li><li><code>-D__PREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__:</code> compile Newlib for size, not for speed (these are Newlib specific).</li><li><code>-Os -fomit-frame-pointer:</code> tell GCC to optimize for size, not for speed.</li><li><code>-D__BUFSIZ__=256:</code>
again Newlib specific, this is the buffer size allocated by default for
files opened via fopen(). The default is 1024, which I find too much
for an eLua, so I'm using 256 here. Of course, you can change this
value.</li></ul>
<h2>› Step 4: full GCC</h2>
<p>Finally, in the last step of our tutorial, we complete the GCC
build. In this stage, a number of compiler support libraries are built
(most notably libgcc.a). Fortunately this is simpler that the Newlib
compilation step:</p>
<p><br></p>
<tableclass="table_cod">
<tbody><tralign="left">
<th>$ cd gcc-4.3.1/build</th>
</tr>
<tralign="left">
<th>$ make all</th>
</tr>
<tralign="left">
<th>$ sudo make install</th>
</tr>
</tbody></table>
<h2>› Step 5: all done!</h2>
<p>Now you can finally enjoy your i386 toolchain, and compile eLua with
it :) After you do, you'll be able to boot eLua directly on your PC, as
described <ahref="http://www.giga.puc-rio.br/cgi-bin/elua.cgi?p=Booting_your_PC_in_eLua">here</a>, but you won't need to download the ELF file from the eLua project page, since you just generated it using your own toolchain!
If you need further clarification, or if the above instructions didn't work for you, feel free to <ahref="http://www.giga.puc-rio.br/cgi-bin/elua.cgi?p=Contact">contact me</a>.</p>