+export PATH="${PREFIX}/bin:${PATH}"
+
+SUMMON_DIR=$(pwd)
+SOURCES=${SUMMON_DIR}/sources
+STAMPS=${SUMMON_DIR}/stamps
+
+
+##############################################################################
+# Tool section
+##############################################################################
+TAR=tar
+
+##############################################################################
+# OS and Tooldetection section
+# Detects which tools and flags to use
+##############################################################################
+
+case "$(uname)" in
+ Linux)
+ echo "Found Linux OS."
+ ;;
+ Darwin)
+ echo "Found Darwin OS."
+
+ # darwin dependencies
+ DARWINDEPS="gnu-tar wget mpfr libmpc gmp"
+ DARWINDEPSCOUNT=4
+
+ echo "Installing dependencies ..."
+ if ! which brew > /dev/null; then
+ echo "Homebrew not installed."
+ else
+ brew install ${DARWINDEPS} | (grep -v '^Warning: Formula already installed: ' || true)
+ fi
+
+ GCCFLAGS="${GCCFLAGS} \
+ --with-gmp=$(brew --prefix gmp) \
+ --with-mpfr=$(brew --prefix mpfr) \
+ --with-mpc=$(brew --prefix mpc)
+ -with-libiconv-prefix=$(brew --prefix libiconv)"
+
+ TAR=gnutar
+
+ OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
+ OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
+ ;;
+ CYGWIN*)
+ echo "Found CygWin that means Windows most likely."
+ ;;
+ *)
+ echo "Found unknown OS. Aborting!"
+ exit 1
+ ;;
+esac
+
+##############################################################################
+# Building section
+# You probably don't have to touch anything after this
+##############################################################################
+
+# Fetch a versioned file from a URL
+function fetch {
+ if [ ! -e ${STAMPS}/$1.fetch ]; then
+ log "Downloading $1 sources..."
+ wget -c $2
+ touch ${STAMPS}/$1.fetch
+ fi
+}
+
+# Log a message out to the console
+function log {
+ echo "******************************************************************"
+ echo "* $*"
+ echo "******************************************************************"
+}
+
+# Unpack an archive
+function unpack {
+ log Unpacking $*
+ # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
+ ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
+ case ${ARCHIVE} in
+ *.bz2)
+ echo "archive type bz2"
+ TYPE=j
+ ;;
+ *.gz)
+ echo "archive type gz"
+ TYPE=z
+ ;;
+ *)
+ echo "Unknown archive type of $1"
+ echo ${ARCHIVE}
+ exit 1
+ ;;
+ esac
+ ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
+}
+
+# Install a build
+function install {
+ log $1
+ ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
+}
+
+
+mkdir -p ${STAMPS} ${SOURCES}
+
+cd ${SOURCES}
+
+fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
+fetch ${GCC} ${GCCURL}
+fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
+fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
+
+if [ ${OOCD_EN} != 0 ]; then
+if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
+ log "Cloning OpenOCD sources..."
+ git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
+ cd openocd-${OOCD}
+ ./bootstrap
+ cd ..
+ tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
+ #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
+ # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
+ rm -rf openocd-${OOCD}
+fi