#!/bin/bash

set -e

SCRIPTDIR="$(dirname "$0")"
HERE="$(cd "$SCRIPTDIR" && pwd)"

TARGETS=(
  "vax-linux"
  "mcore-elf"
  "fr30-elf"
  "lm32-uclinux"
  "tilegx-linux"
  "frv-linux"
  "am33_2.0-linux"
  "cris-linux"
  "spu-elf"
  "aarch64-linux"
  "hppa-linux"
  "xtensa-elf"
  "h8300-linux"
  "ia64-linux"
  "tilepro-linux"
  "nvptx-elf"
  "alpha-linux"
  "avr-elf"
  "sparc-linux"
  "iq2000-elf"
  "xstormy16-elf"
  "mips-linux"
  "epiphany-elf"
  "pdp11-aout"
  "rx-elf"
  "nds32le"
  "powerpc-linux"
  "c6x-elf"
  "v850-rtems"
  "mmix-mmixware"
  "sh-linux"
  "cr16-elf"
  "bfin-uclinux"
  "microblaze-linux"
  "nios2-linux"
  "s390-linux"
  "m32c-elf"
  "arc-linux-uclibc"
  "arm-eabi"
  "m32r-elf"
  "msp430-elf"
  "i386-linux"
)

for targ in "${TARGETS[@]}"; do
  rm -rf "$targ"
  mkdir "$targ"
  pushd "$targ"
  echo "Configuring for $targ"
  extra_opts=
  case "$targ" in
  arc*)
    extra_opts="--with-cpu=arc700"
    ;;
  *)
    ;;
  esac
  ../../src/gcc-mainline/configure --prefix="$HERE"/prefix --target="$targ" --enable-languages=c $extra_opts >& "$HERE/$targ.conf" || echo FAILED.
  echo "Building for $targ"
  make -j4 all-gcc >& "$HERE/$targ.build" || echo FAILED.
  popd
done
echo Done.
