setting up gcc as a cross-compiler

This page describes how to build and install gcc as a cross-compiler on a linux PC (or any linux system, really). This means that you could, for example, build programs on your [probably much faster] PC and then run them on your ps2 linux system.

Most people would probably be happier installing pre-built tarballs.

which version?

First you'll need to decide which version of gcc to build.

Getting the source

2.95.2

The gcc source rpm should be on disc 2:/SRPMS. After installing it with 'rpm -i' the gcc source tarball and several patches will be in /usr/src/RPM/SOURCES. Copy these onto the PC you'll be using to develop.

3.0.3

before we begin

gcc needs a few programs to build that are part of the binutils package, so you'll need to build and install the binutils package.

gcc's executables depend on several system libraries and headers, so we'll need to make them available before building gcc. This will be true for pretty much anything that you'll build for your ps2 linux system, so now is a good time to bring over a bunch of libraries and headers from your ps2.

gcc will, by default, look in the directory /usr/local/ps2/mipsEEel-linux/sys-include for headers, so I do a recursive copy of /usr/include on my ps2 into this directory. To be honest, I don't know what the minimum set of headers is to get gcc to build.

As for libraries, I like to put them in /usr/local/ps2/mipsEEel-linux/lib. Here's what you'll need to bring over to your PC:

from /usr/lib:

  • crt*.o
  • libc.a
  • libc_nonshared.a
  • libc.so -> modify (see below)
  • libm.so
  • libstdc++*
libc.so is actually a text file pointing to a few others. You'll need to modify the path (i.e., '/lib' becomes '/usr/local/ps2/mipsEEel-linux/lib').

from /lib

  • ld.so.1
  • libc.so.6
  • libm.so.6
This is a mostly minimal set of libraries needed to get gcc to build. Eventually you'll want access to other libs usually found on a linux system. Copying them in the same manner as the headers is one option, but libraries can take up quite a bit of space, so you might want to nfs mount or something...

configure and build

Once you've got headers and libraries you're almost ready to build. Before doing so, gcc needs to be able to find the binutils binaries, so add '/usr/local/ps2/bin' to your path. So, let's build:

gcc 2.95.2

2.95.2 comes with libstdc++ and builds it as part of the gcc build process, but since it was just copied over from the ps2 system it isn't needed. I've also found it problematic to build, so I recommend removing the 'libstdc++' from the gcc source tree as below.
  1. tar xvzf gcc-2.95.2.tar.gz
  2. cd gcc-2.95.2
  3. mv libstdc++ ../ or rm -fr libstdc++ (see above)
  4. patch -p1 < ../gcc-2.95.2-frankengcc-patches.patch
  5. patch -p1 < ../gcc-2.95.2-single-float-const.patch
  6. patch -p1 < ../gcc-ps2linux-1.0.0.patch
  7. patch -p1 < [path_to_ps2stuff]/linux/patches/gcc-2.95.2-ps2stuff.patch **optional-but-recommended (see above)**
  8. mkdir build
  9. cd build/
  10. ../configure --prefix=/usr/local/ps2 --host=i386-pc-linux-gnu --target=mipsEEel-linux --enable-shared --disable-nls
  11. make
  12. make install
Now we'll need to link the c++ headers and libraries copied from the ps2 side somewhere this installation of gcc can find them. Go to /usr/local/ps2/include/g++- and link the copied g++ headers here like this:
ln -s ../../mipsEEel-linux/sys-include/g++-3/* .
There will be a few errors, but don't worry about them. Now the c++ standard library:
  1. cd ../../mipsEEel-linux/lib/
  2. ln -s libstdc++-libc6.2-2.a.3 libstdc++.a
  3. ln -s libstdc++-libc6.2-2.so.3 libstdc++.so

gcc 3.0.3

  1. tar xvzf gcc-3.0.3-ps2linux-src.tgz
  2. patch -p0 < [path_to_ps2stuff]/linux/patches/gcc-3.0.3-ps2stuff.patch **optional-but-recommended (see above)**
  3. cd gcc-3.0.3
  4. mkdir build
  5. cd build
  6. ../configure --prefix=/usr/local/ps2 --host=i386-pc-linux-gnu --target=mipsEEel-linux --enable-shared --disable-nls
  7. make
  8. make inst
Since gcc 3 built some new c++ shared libraries, you'll need to copy them to your linux system if you plan on linking with them. They're here: /usr/local/ps2/mipsEEel-linux/lib/libstdc++*.so*.

and last of all..

As with binutils, I like to refer to gcc as 'ee-gcc' not 'mipsEEel-linux-gcc' and use this line to add aliases for the binaries in /usr/local/ps2/bin:
find . -name 'mipsEE*' -exec bash -c 'ln -s {} `echo {} | sed s,\./mipsEEel\-linux,ee,`' \;