#!/bin/sh

set -e

GDB_VERSION=6.2.1

[ "$GDB_MIRROR" ] || GDB_MIRROR="ftp://ftp.gnu.org/gnu/gdb/"

rm -rf gdb-$GDB_VERSION gdb-$GDB_VERSION-linux-i386-xen
[ -a gdb-$GDB_VERSION.tar.bz2 ] || wget -c "$GDB_MIRROR/gdb-$GDB_VERSION.tar.bz2"
tar xjf gdb-$GDB_VERSION.tar.bz2

cd gdb-$GDB_VERSION-xen-sparse
bash ./mkbuildtree ../gdb-$GDB_VERSION

cd ..
mkdir gdb-$GDB_VERSION-linux-i386-xen
cd gdb-$GDB_VERSION-linux-i386-xen
../gdb-$GDB_VERSION/configure

# Use $MAKE if set, else use gmake if present, otherwise use make
if [ "$MAKE" ]; then
    $MAKE
elif which gmake ; then
    gmake -j4
else
    make -j4
fi
