PSAS/ DebianCrossCompilerHowto
  1. Installing pre-built cross-compilation toolchain from Emdebian
  2. Debian Cross-Compiler HOWTO
    1. Build a cross-compilation toolchain
      1. Create a working directory
      2. Get the source for binutils and GCC
      3. Install Build-Depends
      4. Install fakeroot
      5. Install dpkg-cross
      6. Build binutils
      7. Install the new binutils package
      8. Convert library packages
      9. Build GCC
      10. Install the new GCC packages
    2. Test the cross-compile environment
      1. Test compilation
      2. Install qemu
      3. Run the test program with qemu
  3. Shell script for this process

Installing pre-built cross-compilation toolchain from Emdebian

Commands you need to run as root assume you have already set up sudo on your system.

Note: this HOWTO provides a procedure for building a cross-compilation toolchain by hand. It might even still work. However, you can now install pre-built cross-compiler packages from Emdebian, and you should do so if at all possible, rather than following the rest of this guide. To use the Emdebian cross-compiler packages, add the following line to /etc/apt/sources.list:

deb stable main

Then, run the following commands:

sudo apt-get install emdebian-archive-keyring
sudo apt-get update
sudo apt-get install gcc-4.4-powerpc-linux-gnu libc6-dev-powerpc-cross

(Change 4.4 to the current version of GCC available from Emdebian.)

This should work perfectly on Debian and on the most recent versions of Ubuntu. Older versions of Ubuntu might need to manually install some libraries from newer versions; for instance, you might need to download and install libmpfr4.

If these packages work for you, you can ignore the remainder of this guide.

Debian Cross-Compiler HOWTO

This HOWTO will help you build Debian packages of a cross-compilation toolchain. The example commands assume the PowerPC architecture, since the PSAS flight computer uses PowerPC; however, the same procedure should work to build a cross-compilation toolchain for any supported architecture.

As of this writing, the latest version of GCC in Debian is 4.0, so you will be building a cross-compiler from the gcc-4.0 package. Ignore the gcc package; it simply provides metapackages which depend on the standard version of GCC in Debian and provide unversioned symlinks (such as from gcc to gcc-4.0).

Specific version numbers for packages are listed as VERSION; substitute the version number of the latest package in unstable (or testing).

Build a cross-compilation toolchain

Create a working directory

This process will create many files and directories; you will want to work in a separate working directory to avoid cluttering your home directory.

mkdir -p ~/src/cross-toolchain
cd ~/src/cross-toolchain

Get the source for binutils and GCC

In order to build a cross-compilation toolchain, you need to get the source for the Debian binutils and GCC packages. Note that you need binutils 2.16.1cvs20060413-1 or newer to build cross packages; if for some reason you want an older version, use or adapt one of the patches from Debian bug 231707.

apt-get source binutils gcc-4.0

Install Build-Depends

GCC and binutils require several other packages in order to build; you can install all of them using "apt-get build-dep"; this will also install build-essential.

sudo apt-get build-dep binutils gcc-4.0

Note that gcc-4.0 may have build-dependencies that apt-get can't figure out; this is not a problem, just make sure you install all the ones that apt-get understands. Unfortunately, apt-get build-dep may give an error if such a situation arises; in this case, take the list of packages apt-get provided before giving an error, and install them using "sudo aptitude install pkg1 pkg2 pkg3 ...".

Install fakeroot

fakeroot allows you to build packages without being root.

sudo aptitude install fakeroot

Install dpkg-cross

dpkg-cross adds cross-compilation support to some of the basic Debian package tools. dpkg-cross can also convert packages designed for the target architecture into packages usable for cross-compilation to that architecture.

sudo aptitude install dpkg-cross

Build binutils

While still in the binutils directory:

TARGET=powerpc-linux-gnu fakeroot debian/rules binary-cross > ../ 2>&1 || echo 'Build error'

Install the new binutils package

The binutils package must be installed in order to build the GCC package.

cd ..
sudo dpkg -i binutils-powerpc-linux-gnu_VERSION_HOSTARCH.deb

Convert library packages

You will need cross-compilation packages for various libraries; dpkg-cross can convert native packages for the target architecture into packages usable for cross-compilation.

wget ''
wget ''
wget ''
dpkg-cross -a powerpc -b l*.deb
sudo dpkg -i l*powerpc-cross*.deb

Build GCC

Now that you have all the necessary prerequisites, you can build a cross-compiling GCC.

cd gcc-VERSION
export GCC_TARGET=powerpc
debian/rules control
dpkg-buildpackage -us -uc -rfakeroot -b > ../ 2>&1 || echo 'Build error'

Install the new GCC packages

cd ..
sudo dpkg -i *-4.0-powerpc-linux-gnu*.deb *-powerpc-cross_4.0*.deb

Test the cross-compile environment

Test compilation

Create a file "hello.c", containing the following code:

#include <stdio.h>

int main()
    printf("Hello cross-compiling world!\n");
    return 0;

Compile it statically with the new cross-compiler.

powerpc-linux-gnu-gcc -static hello.c -o hello

Check the binary's type with "file".

file hello

You should see something like:

hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), for GNU/Linux 2.2.0, statically linked, not stripped

Install qemu

qemu is an emulator for various architectures. It supports both whole-system emulation as well as single-program emulation with system-call conversion.

sudo aptitude install qemu

Run the test program with qemu

To run the test program with qemu, just prefix it with "qemu-ppc" (or the appropriate version of qemu for your target architecture).

qemu-ppc ./hello

You should see:

Hello cross-compiling world!

Shell script for this process