Building a Linux Cross-Compiler Toolchain

Build and Install Binutils

  1. apt-get source binutils

  2. cd binutils-<version>

  3. fakeroot debian/rules TARGET=m68k binary-cross

  4. cd ..

  5. dpkg -i binutils-m68k-linux-gnu_<version>_amd64.deb

Prepare a GCC for Bootstrapping Purposes

  1. Kernel headers are tricky:
    1. apt-get source linux-2.6

    2. cd linux-2.6-<version>

    3. debian/rules source-all

    4. cd debian/build/source_m68k_none

    5. sudo mkdir -p /usr/local/stow/m68k-bootstrap/m68k-linux-gnu/include

    6. sudo make ARCH=m68k INSTALL_HDR_PATH=/usr/local/stow/m68k-bootstrap/m68k-linux-gnu

  2. [E]glibc headers are even trickier:
    1. apt-get source eglibc

    2. cd eglibc-<version>

    3. debian/rules patch

    4. mkdir BUILD; cd BUILD

    5. (cd /usr/local/stow; sudo stow m68k-bootstrap)

    6. ../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

    7. sudo make cross-compiling=yes cross-build-friendly=yes install-bootstrap-headers=yes install_root=/tmp/eglibc-headers install-headers

    8. (cd /usr/local/stow; sudo stow -D m68k-bootstrap)

    9. rsync -rlt /tmp/eglibc-headers/usr/local/include/ /usr/local/stow/m68k-bootstrap/m68k-linux-gnu/include

  3. Gcc is impossible:
    1. apt-get source gcc-4.4

    2. cd gcc-4.4-<version>

    3. debian/rules unpack; debian/rules patch

    4. mkdir src/BUILD; cd src/BUILD

    5. (cd /usr/local/stow; sudo stow m68k-bootstrap)

    6. ../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

    7. make all-gcc all-target-libgcc

    8. (cd /usr/local/stow; sudo stow -D m68k-bootstrap)

    9. sudo make DESTDIR=/usr/local/stow/m68k-bootstrap install-gcc install-target-libgcc

    10. cd /usr/local/stow/m68k-bootstrap

    11. sudo rsync -rlt usr/local/ .

    12. sudo rm -r usr/local

    13. sudo mv man share

    14. sudo ln -s /usr/m68k-linux-gnu/bin m68k-linux-gnu/bin

    15. sudo find . -name 'libgcc.a' -exec sh -c 'ln -s libgcc.a `dirname {}`/libgcc_eh.a' \;

    16. (cd /usr/local/stow; sudo stow m68k-bootstrap)

Build Headers and Libraries for Cross-compiling

  1. We're building m68k packages
    1. eval `dpkg-architecture -am68k -s`

  2. Modern [e]glibc doesn't support m68k; old glibc doesn't like modern kernel headers
    1. wget http://archive.debian.org/debian/pool/main/l/linux-kernel-headers/linux-kernel-headers_2.6.18-7.dsc

    2. wget http://archive.debian.org/debian/pool/main/l/linux-kernel-headers/linux-kernel-headers_2.6.18.orig.tar.gz

    3. wget http://archive.debian.org/debian/pool/main/l/linux-kernel-headers/linux-kernel-headers_2.6.18-7.diff.gz

    4. dpkg-source -x linux-kernel-headers_2.6.18-7.dsc

    5. cd linux-kernel-headers-2.6.18

    6. fakeroot debian/rules binary

    7. cd ..

    8. sudo dpkg-cross -a m68k -i linux-kernel-headers_2.6.18-7_m68k.deb

  3. 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
    1. wget http://archive.debian.org/debian/pool/main/g/glibc/glibc_2.3.6.ds1-13etch10.dsc

    2. wget http://archive.debian.org/debian/pool/main/g/glibc/glibc_2.3.6.ds1.orig.tar.gz

    3. wget http://archive.debian.org/debian/pool/main/g/glibc/glibc_2.3.6.ds1-13etch10.diff.gz

    4. dpkg-source -x glibc_2.3.6.ds1-13etch10.dsc

    5. cd glibc-2.3.6.ds1

    6. debian/rules patch

    7. 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
    8. (cd build-tree/glibc-2.3.6; autoconf2.59)

    9. debian/rules CFLAGS="-g -O2 -fgnu89-inline" LDFLAGS="-fgnu89-inline" binary-arch

    10. cd ..

    11. sudo dpkg-cross -a m68k -X tzdata -i libc6_2.3.6.ds1-13etch10_m68k.deb

    12. sudo dpkg-cross -a m68k -i libc6-dev_2.3.6.ds1-13etch10_m68k.deb libc6-pic_2.3.6.ds1-13etch10_m68k.deb

  4. We're done building m68k packages
    1. eval `dpkg-architecture -am68k -u`

Build Full-Fledged Cross-Compiling GCC

  1. The bootstrapping compiler is no longer need, and could cause us problems
    1. (cd /usr/local/stow; sudo stow -D m68k-bootstrap)

  2. We do a pretty normal Debian build now, much easier than the bootstrapping
    1. rm -rf ./gcc-4.4-4.4.5

    2. dpkg-source -x gcc-4.4_4.4.5-8.dsc

    3. cd gcc-4.4-4.4.5

    4. sed -i~ -r debian/rules.conf -e 's/(libc_ver.*)2\.5/\12.3.5-1/'

    5. fakeroot debian/rules DEB_TARGET_ARCH=m68k binary

    6. cd ...

    7. Install whatever of the generated .deb files interest you

kbare at CLUB.CC.CMU.EDU/m68k Notes (last edited 2011-02-21 23:17:25 by kbare@CLUB.CC.CMU.EDU)