mario::konrad
programming / C++ / sailing / nerd stuff
How to build a cross GCC
© 2004 / Mario Konrad

Note: this tutorial may be a bit out of date. Please consider using the http://crosstool-ng.org

Introduction

This page describes how to build a cross compiler (GCC). I have done this under the Cygwin (1.3.22) environment as well as under Linux (2.4.20). The target architecture was powerpc-elf and powerpc-eabi.

Just follow the steps to get a working C and C++ cross compiler, library inclusive.

You will need the following packages in order to build the cross compiler:

Maybe the build procedure works for newer/other versions of those packages as well, but I haven't tested any other versions, yet.

Target: powerpc-elf

Step 1: Create some directories

$ mkdir src
$ mkdir build
$ mkdir build/binutils-2.13.92
$ mkdir build/gcc-2.95.3
$ mkdir build/newlib-1.11.0
$ mkdir prefix

Step 2: Unpack the packages

$ cd src
$ tar -xjf binutils-2.13.92-src.tar.bz2
$ tar -xzf gcc-2.95.3-src.tar.gz
$ tar -xzf newlib-1.11.0-src.tar.gz
$ cd ..

Step 3: Define some shell variables

$ export TARGET=powerpc-elf
$ export ROOT=`pwd`
$ export SRC=$ROOT/src
$ export BUILD=$BUILD/build
$ export PREFIX=$ROOT/prefix
$ export PATH=$PREFIX/bin:$PATH

Maybe you like to install the cross compiler in /usr/local, just define the variable

$ export PREFIX=/usr/local

You have to do that before the definition of the PATH variable. To build for an powerpc-eabi target (instead of powerpc-elf) just define the variable:

$ export TARGET=powerpc-eabi

Step 4: Build the binutils

$ cd $BUILD/binutils-2.13.92/
$ $SRC/binutils-2.13.92/configure \
    --prefix=$PREFIX \
    --target=$TARGET 2>&1 | tee configure.log
$ make all install 2>&1 | tee  make-install.log

Step 5: Build the bootstrap cross compiler

$ cd $BUILD/gcc-2.95.3/
$ $SRC/gcc-2.95.3/configure \
    --prefix=$PREFIX \
    --target=$TARGET \
    --with-newlib \
    --without-headers \
    --enable-languages=c,c++ 2>&1 | tee configure.log
$ make all-gcc 2>&1 | tee make-gcc.log
$ make install-gcc 2>&1 | tee install-gcc.log

Step 6: Build the library

$ cd $BUILD/newlib-1.11.0/
$ $SRC/newlib-1.11.0/configure \
    --prefix=$PREFIX \
    --target=$TARGET \
    --enable-newlib-hw-fp 2>&1 | tee configure.log
$ make 2>&1 | tee make.log
$ make install 2>&1 | tee install.log

Step 7: Build the final cross compiler

$ cd $BUILD/gcc-2.95.3/
$ make 2>&1 | tee make.log
$ make install 2>&1 | tee install.log