#!/bin/bash # # Build a gcc + uClibc toolchain # # References: # http://gcc.gnu.org/ml/gcc/2007-08/msg00327.html # http://busybox.net/~vda/HOWTO/i486-linux-uclibc/HOWTO.txt # http://wiki.osdev.org/GCC_Cross-Compiler set -ex arch=$1 sysroot=$2 uclibc=$3 binutils=$4 gcc=$5 gmp=$6 mpfr=$7 kernel_headers=$8 unset CPATH LIBRARY_PATH INSTALL PATH=/usr/lib/ccache:/bin:/usr/bin rm -rf ${sysroot} mkdir ${sysroot} ln -s . ${sysroot}/usr # Link target-specific usr directory to usr, otherwise gcc has trouble finding ld ln -s . ${sysroot}/usr/${arch}-linux-uclibc # Install kernel headers mkdir ${sysroot}/usr/include cp -pLR ${kernel_headers}/{asm,linux,asm-generic} ${sysroot}/usr/include/ # Build binutils mkdir binutils-${arch} ( cd binutils-${arch}; ${binutils}/configure --prefix=/usr --target=${arch}-linux-uclibc --with-gmp-include=${gmp} --with-gmp-lib=${gmp}/.libs --with-mpfr-include=${mpfr} --with-mpfr-lib=${mpfr}/.libs --with-sysroot=${sysroot} --program-prefix=${arch}-linux-uclibc- ) make -C binutils-${arch} all install DESTDIR=${sysroot} # Build stage 1 gcc (required to build uClibc) mkdir gcc-stage1-${arch} ( cd gcc-stage1-${arch}; ${gcc}/configure --prefix=/usr --target=${arch}-linux-uclibc --enable-languages=c --with-gmp-include=${gmp} --with-gmp-lib=${gmp}/.libs --with-mpfr-include=${mpfr} --with-mpfr-lib=${mpfr}/.libs --disable-shared --disable-nls --disable-multilib --disable-threads --disable-libmudflap --disable-libssp --disable-libgomp --disable-decimal-float --disable-tls --without-headers --with-build-time-tools=${sysroot}/usr/bin --with-gnu-ld ) make -C gcc-stage1-${arch} all-gcc all-target-libgcc install-gcc install-target-libgcc DESTDIR=${sysroot} # Build uClibc cp -a ${uclibc} uclibc-${arch} cp uclibc-${arch}.config uclibc-${arch}/.config make -C uclibc-${arch} oldconfig make -C uclibc-${arch} extra/scripts/unifdef PATH=${sysroot}/usr/bin:${PATH} make -C uclibc-${arch} CROSS=${arch}-linux-uclibc- KERNEL_HEADERS=${sysroot}/usr/include PREFIX=${sysroot} RUNTIME_PREFIX=/ DEVEL_PREFIX=/ RUNTIME_PREFIX_LIB_FROM_DEVEL_PREFIX_LIB= V=1 all install PATH=${sysroot}/usr/bin:${PATH} make -C uclibc-${arch}/utils CROSS=${arch}-linux-uclibc- KERNEL_HEADERS=${sysroot}/usr/include PREFIX=${sysroot} RUNTIME_PREFIX=/ DEVEL_PREFIX=/ RUNTIME_PREFIX_LIB_FROM_DEVEL_PREFIX_LIB= V=1 hostutils utils_install # Build final gcc targeting uClibc mkdir gcc-final-${arch} ( cd gcc-final-${arch}; ${gcc}/configure --prefix=/usr --target=${arch}-linux-uclibc --enable-languages=c --with-sysroot=${sysroot} --with-gmp-include=${gmp} --with-gmp-lib=${gmp}/.libs --with-mpfr-include=${mpfr} --with-mpfr-lib=${mpfr}/.libs --disable-nls --disable-multilib --disable-threads --disable-libgomp --disable-decimal-float --with-build-time-tools=${sysroot}/usr/bin --with-gnu-ld ) make -C gcc-final-${arch} all install DESTDIR=${sysroot}