Building a Linux Cross-Compiler Toolchain
Build and Install Binutils
apt-get source binutils
cd binutils-<version>
fakeroot debian/rules TARGET=m68k binary-cross
cd ..
dpkg -i binutils-m68k-linux-gnu_<version>_amd64.deb
Prepare a GCC for Bootstrapping Purposes
- Kernel headers are tricky:
apt-get source linux-2.6
cd linux-2.6-<version>
debian/rules source-all
cd debian/build/source_m68k_none
sudo mkdir -p /usr/local/stow/m68k-bootstrap/m68k-linux-gnu/include
sudo make ARCH=m68k INSTALL_HDR_PATH=/usr/local/stow/m68k-bootstrap/m68k-linux-gnu
- [E]glibc headers are even trickier:
apt-get source eglibc
cd eglibc-<version>
debian/rules patch
mkdir BUILD; cd BUILD
(cd /usr/local/stow; sudo stow m68k-bootstrap)
../configure --build=x86_64-linux-gnu --host=m68k-linux-gnu --target=m68k-linux-gnu --prefix=/usr/local --with-headers=/usr/local/m68k-linux-gnu/include --disable-sanity-checks
sudo make cross-compiling=yes cross-build-friendly=yes install-bootstrap-headers=yes install_root=/tmp/eglibc-headers install-headers
(cd /usr/local/stow; sudo stow -D m68k-bootstrap)
rsync -rlt /tmp/eglibc-headers/usr/local/include/ /usr/local/stow/m68k-bootstrap/m68k-linux-gnu/include
- Gcc is impossible:
apt-get source gcc-4.4
cd gcc-4.4-<version>
debian/rules unpack; debian/rules patch
mkdir src/BUILD; cd src/BUILD
(cd /usr/local/stow; sudo stow m68k-bootstrap)
../configure --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=m68k-linux-gnu --prefix=/usr/local --enable-languages=c --disable-threads --enable-tls --disable-shared
make all-gcc all-target-libgcc
(cd /usr/local/stow; sudo stow -D m68k-bootstrap)
sudo make DESTDIR=/usr/local/stow/m68k-bootstrap install-gcc install-target-libgcc
cd /usr/local/stow/m68k-bootstrap
sudo rsync -rlt usr/local/ .
sudo rm -r usr/local
sudo mv man share
sudo ln -s /usr/m68k-linux-gnu/bin m68k-linux-gnu/bin
sudo find . -name 'libgcc.a' -exec sh -c 'ln -s libgcc.a `dirname {}`/libgcc_eh.a' \;
(cd /usr/local/stow; sudo stow m68k-bootstrap)
Build Headers and Libraries for Cross-compiling
- We're building m68k packages
eval `dpkg-architecture -am68k -s`
- Modern [e]glibc doesn't support m68k; old glibc doesn't like modern kernel headers
wget http://archive.debian.org/debian/pool/main/l/linux-kernel-headers/linux-kernel-headers_2.6.18-7.dsc
dpkg-source -x linux-kernel-headers_2.6.18-7.dsc
cd linux-kernel-headers-2.6.18
fakeroot debian/rules binary
cd ..
sudo dpkg-cross -a m68k -i linux-kernel-headers_2.6.18-7_m68k.deb
- Apparently there's some sort of sad story about m68k and [e]glibc; something about m68k just getting TLS in 2.6.32 and linuxthreads being long deprecated
wget http://archive.debian.org/debian/pool/main/g/glibc/glibc_2.3.6.ds1-13etch10.dsc
wget http://archive.debian.org/debian/pool/main/g/glibc/glibc_2.3.6.ds1.orig.tar.gz
wget http://archive.debian.org/debian/pool/main/g/glibc/glibc_2.3.6.ds1-13etch10.diff.gz
dpkg-source -x glibc_2.3.6.ds1-13etch10.dsc
cd glibc-2.3.6.ds1
debian/rules patch
- Need the following to fix a few compilation issues:
patch -l -p0 << 'EOF' --- build-tree.old/glibc-2.3.6/configure.in 2011-02-21 15:27:02.000000000 -0500 +++ build-tree/glibc-2.3.6/configure.in 2011-02-21 15:26:46.000000000 -0500 @@ -737,12 +737,12 @@ AC_SUBST(MIG)dnl Needed by sysdeps/mach/configure.in # Accept binutils 2.13 or newer. -AC_CHECK_PROG_VER(AS, $AS, --version, - [GNU assembler.* \([0-9]*\.[0-9.]*\)], - [2.1[3-9]*], AS=: critic_missing="$critic_missing as") -AC_CHECK_PROG_VER(LD, $LD, --version, - [GNU ld.* \([0-9][0-9]*\.[0-9.]*\)], - [2.1[3-9]*], LD=: critic_missing="$critic_missing ld") +AC_CHECK_PROG_VER(AS, $AS, --version, + [GNU assembler.* \([0-9]*\.[0-9.]*\)], + [2.1[3-9]*|2.2[0-9]*], AS=: critic_missing="$critic_missing as") +AC_CHECK_PROG_VER(LD, $LD, --version, + [GNU ld.* \([0-9][0-9]*\.[0-9.]*\)], + [2.1[3-9]*|2.2[0-9]*], LD=: critic_missing="$critic_missing ld") # We need the physical current working directory. We cannot use the # "pwd -P" shell builtin since that's not portable. Instead we try to @@ -809,7 +809,7 @@ # thing on a system that doesn't need fixincludes. (Not presently a problem.) if test -n "$sysheaders"; then ccheaders=`$CC -print-file-name=include` - SYSINCLUDES="-nostdinc -isystem $ccheaders \ + SYSINCLUDES="-nostdinc -isystem $ccheaders -isystem ${ccheaders}-fixed \ -isystem `echo $sysheaders | sed 's/:/ -isystem /g'`" fi AC_SUBST(SYSINCLUDES) --- build-tree.old/glibc-2.3.6/elf/Makefile 2011-02-21 15:48:04.000000000 -0500 +++ build-tree/glibc-2.3.6/elf/Makefile 2011-02-21 15:48:21.000000000 -0500 @@ -289,7 +289,7 @@ $(LDFLAGS-rtld) -Wl,-z,defs -Wl,--verbose 2>&1 | \ LC_ALL=C \ sed -e '/^=========/,/^=========/!d;/^=========/d' \ - -e 's/\. = 0 + SIZEOF_HEADERS;/& _begin = . - SIZEOF_HEADERS;/' \ + -e 's/\. = .* + SIZEOF_HEADERS;/& _begin = . - SIZEOF_HEADERS;/' \ > $@.lds $(LINK.o) -nostdlib -nostartfiles -shared -o $@ \ $(LDFLAGS-rtld) -Wl,-z,defs $(z-now-$(bind-now)) \ EOF
(cd build-tree/glibc-2.3.6; autoconf2.59)
debian/rules CFLAGS="-g -O2 -fgnu89-inline" LDFLAGS="-fgnu89-inline" binary-arch
cd ..
sudo dpkg-cross -a m68k -X tzdata -i libc6_2.3.6.ds1-13etch10_m68k.deb
sudo dpkg-cross -a m68k -i libc6-dev_2.3.6.ds1-13etch10_m68k.deb libc6-pic_2.3.6.ds1-13etch10_m68k.deb
- We're done building m68k packages
eval `dpkg-architecture -am68k -u`
Build Full-Fledged Cross-Compiling GCC
- The bootstrapping compiler is no longer need, and could cause us problems
(cd /usr/local/stow; sudo stow -D m68k-bootstrap)
- We do a pretty normal Debian build now, much easier than the bootstrapping
rm -rf ./gcc-4.4-4.4.5
dpkg-source -x gcc-4.4_4.4.5-8.dsc
cd gcc-4.4-4.4.5
sed -i~ -r debian/rules.conf -e 's/(libc_ver.*)2\.5/\12.3.5-1/'
fakeroot debian/rules DEB_TARGET_ARCH=m68k binary
cd ...
- Install whatever of the generated .deb files interest you