#! /bin/sh
#

TARGET=${1}

#PREFIX=/home/joel/test-gcc/install-4.9-branch
# PREFIX=/home/joel/test-gcc/install-4.8-branch
# PREFIX=/home/joel/test-gcc/install-bisect
# PREFIX=/home/joel/test-gcc/install-gcc10
PREFIX=/home/joel/test-gcc/install-master
#PREFIX=/home/joel/test-gcc/install-gccrs

if [ $# -ne 1 ] ; then
  echo USAGE: $0 TARGET
  exit 1
fi

# Temporary until merged
BIN_GDB=binutils-gdb
case ${TARGET} in
  epiphany*) BIN_GDB=epiphany-binutils-gdb ;;
  #or1k*)     BIN_GDB=binutils-gdb-or1k ;;
  *)    ;;
esac
if [ ! -d ${BIN_GDB} ] ; then
  echo "ERROR: no ${BIN_GDB} source present"
  exit 1
fi
rm -rf b-${TARGET}-bin
mkdir b-${TARGET}-bin
cd b-${TARGET}-bin

WARNING_ERROR=--disable-werror
case ${TARGET} in
  *sparc*) SIM_ARGS="--disable-sim" ;;
  *) SIM_ARGS="--enable-sim --enable-sim-hardware \
        --enable-timebase --enable-sim-trace"
        ;;
esac


#  --with-gmp-lib=/home/joel/test-gcc/install-gmp/lib \
#  --with-gmp-include=/home/joel/test-gcc/install-gmp/include \

../${BIN_GDB}/configure \
  --target=${TARGET} \
  --prefix=${PREFIX} \
  ${WARNING_ERROR} \
  --with-libgmp-prefix=/home/joel/test-gcc/install-gmp \
  ${SIM_ARGS} \
  >c.log 2>&1 && \
make -j >b.log 2>&1 && \
make install >i.log 2>&1
status=$?

#if [ ${status} -eq 0 ] ; then
#  rm -rf ../b-${TARGET}-bin
#fi
echo $status
exit $status

