#!/bin/bash # Hackish script that builds a uMPS (bare MIPS ELF) toolchain # # Usage: # 1. Modify {BINUTILS,GCC}_REL and XT_{PREFIX,TARGET} below as desired. # The script will install the toolchain under $XT_PREFIX. # 2. Run this script! # # Written by Tomislav Jonjic , released as public domain. BINUTILS_REL=ftp://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2 GCC_REL=ftp://ftp.gnu.org/gnu/gcc/gcc-4.6.2/gcc-core-4.6.2.tar.bz2 XT_PREFIX=$HOME/umpsxt XT_TARGET=mipsel-elf export PATH=$XT_PREFIX/bin:$PATH set -e fatal () { echo "Error: $1" exit 1 } get_compres_type () { case $1 in *.gz) echo 'z' ;; *.bz2) echo 'j' ;; *) fatal "Unknown compression" esac } prg_name () { tar $(get_compres_type $1)tf "$1" | head -1 | cut -d/ -f1 } # Download, unpack, configure, build, install a package build_pkg () { local pkg_rel=$1 local conf_opts="$2" local make_target="${3:-all}" local mkinst_target="${4:-install}" local pkg_name # Download and unpack test -f $(basename $pkg_rel) || wget $pkg_rel pkg_name=$(prg_name $(basename $pkg_rel)) if [ ! -d $pkg_name ]; then tar $(get_compres_type $pkg_rel)xf $(basename $pkg_rel) fi # Configure if [ -d ${pkg_name}-bld ] ; then rm -rf ${pkg_name}-bld fi mkdir ${pkg_name}-bld cd ${pkg_name}-bld ../$pkg_name/configure $conf_opts # Build make $make_target # Install make $mkinst_target cd .. } build_pkg $BINUTILS_REL \ "--prefix=$XT_PREFIX --target=$XT_TARGET --disable-nls" build_pkg $GCC_REL \ "--prefix=$XT_PREFIX --target=$XT_TARGET --enable-languages=c --without-headers --disable-nls" \ 'all-gcc' \ 'install-gcc'