CUR=`pwd`

cd "$CUR/src/unix"

TARGET=""
case "$UNAME" in
"CYGWIN")
    TARGET=win32
    ;;
"Darwin")
    TARGET=macosx
    ;;
"FreeBSD")
    # Tachyon doesn't have a threaded option for FreeBSD (though it shouldn't
    # be too difficult to add).  There's no need for an explicit 64-bit version
    # since the only difference is a slight performance optimisation.
    TARGET=bsd
    ;;
"Linux")
    case "`uname -m`" in
    i[3456]86)
        TARGET=linux-thr
        ;;
    ia64)
        TARGET=linux-ia64-thr
        ;;
    amd64|x86_64)
        TARGET=linux-64-thr
        ;;
    ppc*|powerpc*)
        TARGET=linux-ppc
        ;;
    armv6l|armv7l)
        TARGET=linux-arm-thr
        ;;
    esac
    ;;
"SunOS")
    TARGET=solaris-pthreads-gcc
    ;;
# TODO: I don't think we even support these platforms anymore
"AIX")
    CFLAGS="$CFLAGS -g -O2"
    export CFLAGS
    TARGET=aix-generic-thr
    ;;
"HP-UX")
    CFLAGS="$CFLAGS -g -O2"
    export CFLAGS
    TARGET=hpux-generic-thr
    ;;
esac

if [ -z "$TARGET" ]; then
    sdh_die "Error: Sorry, your platform isn't supported by Tachyon and/or Sage. Exiting..."
fi

sdh_make "$TARGET"

echo "Installing the Tachyon binary..."
cd "$CUR"
if [ "$UNAME" = CYGWIN ]; then
    binary_name=tachyon.exe
else
    binary_name=tachyon
fi

# The '*' is a place-holder for the arch just built (e.g. 'win32' for
# Cygwin, other directories won't exist):
sdh_install src/compile/*/"${binary_name}" "$SAGE_LOCAL/bin"
