- Installing pre-built cross-compilation toolchain from Emdebian
- Debian Cross-Compiler HOWTO
- Build a cross-compilation toolchain
- Test the cross-compile environment
- Shell script for this process
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 http://emdebian.org/debian/ 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.
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).
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
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
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 ...".
fakeroot allows you to build packages without being root.
sudo aptitude install fakeroot
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
While still in the binutils directory:
TARGET=powerpc-linux-gnu fakeroot debian/rules binary-cross > ../binutils.build 2>&1 || echo 'Build error'
The binutils package must be installed in order to build the GCC package.
sudo dpkg -i binutils-powerpc-linux-gnu_VERSION_HOSTARCH.deb
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.
dpkg-cross -a powerpc -b l*.deb
sudo dpkg -i l*powerpc-cross*.deb
Now that you have all the necessary prerequisites, you can build a cross-compiling GCC.
dpkg-buildpackage -us -uc -rfakeroot -b > ../gcc.build 2>&1 || echo 'Build error'
sudo dpkg -i *-4.0-powerpc-linux-gnu*.deb *-powerpc-cross_4.0*.deb
Create a file "hello.c", containing the following code:
printf("Hello cross-compiling world!\n");
Compile it statically with the new cross-compiler.
powerpc-linux-gnu-gcc -static hello.c -o hello
Check the binary's type with "file".
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
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
To run the test program with qemu, just prefix it with "qemu-ppc" (or the appropriate version of qemu for your target architecture).
You should see:
Hello cross-compiling world!