How to build GNU cross-compilers

From HW wiki
Jump to: navigation, search

Toolchain preparation and kernel build information

by Pavel Píša

Debian PowerPC GCC build log

Debian GCC-4.3 build logs

Kernel headers install

mkdir src
cd src
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
mkdir -p build/{arm,powerpc,i386,x86_64}/linux
cd build/powerpc/linux

Copy and adapt File:How to build GNU cross-compilers-GNUmakefile.txt to override ARCH and select kernel source directory

Run

make headers_install

The header-files for building GCC nd GLIB are prepared in usr/include directory. Copy files found there to the directory /usr/powerpc-linux-gnu/sys-include

Glibc

The required files are glibc-2.7ds1.tar.bz2 glibc-linuxthreads-20071023.tar.bz2 glibc-libidn-2.7.tar.bz2 glibc-ports-2.7.tar.bz2

mkdir -p src
cd src
tar -xjf ../glibc-2.7ds1.tar.bz2
tar -xjf ../glibc-linuxthreads-20071023.tar.bz2
tar -xjf ../glibc-libidn-2.7.tar.bz2
( cd glibc-2.7 ; mv glibc-libidn-2.7 libidn )
tar -xjf ../glibc-ports-2.7.tar.bz2
( cd glibc-2.7 ; mv glibc-ports-2.7 ports )
ln -s glibc-2.7 glibc

Prepare directory to build PowerPC version of GLIBC

mkdir -p build/powerpc-linux/glibc

If there is no previous install of GLIBC, use next dummy build to install headers. They are required to build GCC later

libc_cv_ppc_machine=yes \
libc_cv_mabi_ibmlongdouble=yes \
libc_cv_mlong_double_128=yes \
libc_cv_forced_unwind=yes \
libc_cv_c_cleanup=yes \
CC=gcc \
../../../src/glibc/configure --prefix=/usr \
       --build=x86_64-linux-gnu \
       --host=powerpc-linux-gnu \
       --prefix=/usr \
       --without-cvs \
       --enable-add-ons=libidn,nptl \
       --enable-profile \
       --without-selinux \
       --with-headers=/usr/powerpc-linux-gnu/sys-include \
       --enable-kernel=2.6.26 \
       --enable-hacker-mode \
       --without-cvs --disable-sanity-checks
make DESTDIR=/usr-pkg/glibc-linux-powerpc-2.7-1 \
      inst_includedir=/usr-pkg/glibc-linux-powerpc-2.7-1/include \
      install-headers

Build binutils

../../../binutils/configure \
       --prefix=/usr \
       --disable-nls \
       --build=x86_64-linux-gnu \
       --host=x86_64-linux-gnu \
       --target=powerpc-linux-gnu \
       --enable-targets=powerpc64-linux-gnu
make && make DESTDIR=/usr-pkg/binutils-powerpc-linux-gnu_2.18-2_amd64 install

Build GCC

../../../gcc-4.3/configure -v \
        --enable-languages=c,c++ \
        --prefix=/usr \
        --enable-shared \
        --with-system-zlib \
        --without-included-gettext \
        --enable-threads=posix \
        --disable-nls \
        --enable-clocale=gnu \
        --enable-libstdcxx-debug \
        --enable-objc-gc \
        --enable-mpfr \
        --enable-softfloat \
        --enable-tls \
        --enable-secureplt \
        --enable-targets=powerpc-linux,powerpc64-linux \
        --with-cpu=default32 \
        --with-long-double-128 \
        --enable-checking=release \
        --build=x86_64-linux-gnu \
        --host=x86_64-linux-gnu \
        --target=powerpc-linux-gnu \
        --enable-version-specific-runtime-libs \
        --disable-libgomp \
        --disable-libmudflap

Finally build GLIBC

../../../src/glibc/configure \
       --build=x86_64-linux-gnu \
       --host=powerpc-linux-gnu \
       --prefix=/usr \
       --without-cvs \
       --enable-add-ons=libidn,nptl \
       --enable-profile \
       --without-selinux \
       --with-headers=/usr/powerpc-linux-gnu/sys-include \
       --enable-kernel=2.6.20
make
make install_root=/usr-pkg/glibc-2.7-powerpc install

Bare (xxx-elf) and RTEMS builds with NewLib

Download latest or matching NewLib from ftp://sourceware.org/pub/newlib/index.html

tar -xzf newlib-2.0.0.tar.gz
cd gcc-4.8.1
ln -s ../newlib-2.0.0/newlib

When configuring GCC, use

configure --with-newlib ...

More detailed instructions for RTEMS toolchain preparation can be found at http://www.rtems.org/wiki/index.php/Building_Tools