bootmii-utils/buildtoolchain/buildit.sh

181 lines
4.2 KiB
Bash
Raw Normal View History

2009-05-15 16:01:01 +02:00
#!/bin/sh
# Copyright (C) 2007 Segher Boessenkool <segher@kernel.crashing.org>
# Copyright (C) 2009 Hector Martin "marcan" <hector@marcansoft.com>
# Copyright (C) 2009 Andre Heider "dhewg" <dhewg@wiibrew.org>
# Released under the terms of the GNU GPL, version 2
2010-07-11 13:44:05 +02:00
SCRIPTDIR=`dirname $PWD/$0`
2009-05-15 16:01:01 +02:00
BINUTILS_VER=2.21.1
2009-05-15 16:01:01 +02:00
BINUTILS_DIR="binutils-$BINUTILS_VER"
BINUTILS_TARBALL="binutils-${BINUTILS_VER}a.tar.bz2"
2009-05-15 16:01:01 +02:00
BINUTILS_URI="http://ftp.gnu.org/gnu/binutils/$BINUTILS_TARBALL"
GMP_VER=4.3.2
2009-05-15 16:01:01 +02:00
GMP_DIR="gmp-$GMP_VER"
GMP_TARBALL="gmp-$GMP_VER.tar.bz2"
GMP_URI="http://ftp.gnu.org/gnu/gmp/$GMP_TARBALL"
MPFR_VER=2.4.2
2009-05-15 16:01:01 +02:00
MPFR_DIR="mpfr-$MPFR_VER"
MPFR_TARBALL="mpfr-$MPFR_VER.tar.bz2"
MPFR_URI="http://ftp.gnu.org/gnu/mpfr/$MPFR_TARBALL"
2009-05-15 16:01:01 +02:00
GCC_VER=4.4.7
2009-05-15 16:01:01 +02:00
GCC_DIR="gcc-$GCC_VER"
GCC_TARBALL="gcc-core-$GCC_VER.tar.bz2"
GCC_URI="http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VER/$GCC_TARBALL"
2009-05-15 16:01:01 +02:00
BUILDTYPE=$1
ARM_TARGET=armeb-eabi
POWERPC_TARGET=powerpc-elf
2010-07-11 13:44:05 +02:00
if [ -z $MAKEOPTS ]; then
MAKEOPTS=-j3
fi
2009-05-15 16:01:01 +02:00
# End of configuration section.
case `uname -s` in
*BSD*)
MAKE=gmake
;;
*)
MAKE=make
esac
export PATH=$WIIDEV/bin:$PATH
die() {
echo $@
exit 1
}
cleansrc() {
[ -e $WIIDEV/$BINUTILS_DIR ] && rm -rf $WIIDEV/$BINUTILS_DIR
[ -e $WIIDEV/$GCC_DIR ] && rm -rf $WIIDEV/$GCC_DIR
}
cleanbuild() {
[ -e $WIIDEV/build_binutils ] && rm -rf $WIIDEV/build_binutils
[ -e $WIIDEV/build_gcc ] && rm -rf $WIIDEV/build_gcc
}
download() {
DL=1
if [ -f "$WIIDEV/$2" ]; then
echo "Testing $2..."
tar tf "$WIIDEV/$2" >/dev/null 2>&1 && DL=0
2009-05-15 16:01:01 +02:00
fi
if [ $DL -eq 1 ]; then
echo "Downloading $2..."
wget "$1" -c -O "$WIIDEV/$2" || die "Could not download $2"
fi
}
extract() {
echo "Extracting $1..."
tar xf "$WIIDEV/$1" -C "$2" || die "Error unpacking $1"
2009-05-15 16:01:01 +02:00
}
makedirs() {
mkdir -p $WIIDEV/build_binutils || die "Error making binutils build directory $WIIDEV/build_binutils"
mkdir -p $WIIDEV/build_gcc || die "Error making gcc build directory $WIIDEV/build_gcc"
}
buildbinutils() {
TARGET=$1
(
cd $WIIDEV/build_binutils && \
$WIIDEV/$BINUTILS_DIR/configure --target=$TARGET \
2012-06-15 00:51:10 +02:00
--prefix=$WIIDEV --disable-nls --disable-werror \
--disable-multilib && \
2010-07-11 13:44:05 +02:00
nice $MAKE $MAKEOPTS && \
2009-05-15 16:01:01 +02:00
$MAKE install
) || die "Error building binutils for target $TARGET"
}
buildgcc() {
TARGET=$1
(
cd $WIIDEV/build_gcc && \
$WIIDEV/$GCC_DIR/configure --target=$TARGET --enable-targets=all \
--prefix=$WIIDEV --disable-multilib \
--enable-languages=c --without-headers \
--disable-nls --disable-threads --disable-shared \
--disable-libmudflap --disable-libssp --disable-libgomp \
--disable-decimal-float \
--enable-checking=release && \
2010-07-11 13:44:05 +02:00
nice $MAKE $MAKEOPTS && \
2009-05-15 16:01:01 +02:00
$MAKE install
2011-09-07 16:13:03 +02:00
) || die "Error building gcc for target $TARGET"
2009-05-15 16:01:01 +02:00
}
buildarm() {
cleanbuild
makedirs
echo "******* Building ARM binutils"
buildbinutils $ARM_TARGET
echo "******* Building ARM GCC"
buildgcc $ARM_TARGET
echo "******* ARM toolchain built and installed"
}
buildpowerpc() {
cleanbuild
makedirs
echo "******* Building PowerPC binutils"
buildbinutils $POWERPC_TARGET
echo "******* Building PowerPC GCC"
buildgcc $POWERPC_TARGET
echo "******* PowerPC toolchain built and installed"
}
if [ -z "$WIIDEV" ]; then
die "Please set WIIDEV in your environment."
fi
case $BUILDTYPE in
arm|powerpc|both|clean) ;;
"")
die "Please specify build type (arm/powerpc/both/clean)"
;;
*)
die "Unknown build type $BUILDTYPE"
;;
esac
if [ "$BUILDTYPE" = "clean" ]; then
cleanbuild
cleansrc
exit 0
fi
download "$BINUTILS_URI" "$BINUTILS_TARBALL"
download "$GMP_URI" "$GMP_TARBALL"
download "$MPFR_URI" "$MPFR_TARBALL"
download "$GCC_URI" "$GCC_TARBALL"
2009-05-15 16:01:01 +02:00
cleansrc
extract "$BINUTILS_TARBALL" "$WIIDEV"
extract "$GCC_TARBALL" "$WIIDEV"
2009-05-15 16:01:01 +02:00
extract "$GMP_TARBALL" "$WIIDEV/$GCC_DIR"
extract "$MPFR_TARBALL" "$WIIDEV/$GCC_DIR"
2010-07-11 13:44:05 +02:00
# http://sourceware.org/bugzilla/show_bug.cgi?id=12964
patch -d $WIIDEV/$BINUTILS_DIR -u -p1 -i $SCRIPTDIR/binutils-2.21.1.patch || die "Error applying binutils patch"
2010-07-11 13:44:05 +02:00
# in-tree gmp and mpfr
mv "$WIIDEV/$GCC_DIR/$GMP_DIR" "$WIIDEV/$GCC_DIR/gmp" || die "Error renaming $GMP_DIR -> gmp"
2009-05-15 16:01:01 +02:00
mv "$WIIDEV/$GCC_DIR/$MPFR_DIR" "$WIIDEV/$GCC_DIR/mpfr" || die "Error renaming $MPFR_DIR -> mpfr"
case $BUILDTYPE in
arm) buildarm ;;
powerpc) buildpowerpc ;;
both) buildarm ; buildpowerpc; cleanbuild; cleansrc ;;
esac