CUR=`pwd`

cd "$CUR/src/unix"

TARGET=""
case "$UNAME" in
"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 "$($CC -dumpmachine)" 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*|aarch64*)
        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

# The Makefile ignores LDFLAGS; we include it here so that rpath is set on Linux
sdh_make "$TARGET" USEPNG=-DUSEPNG PNGLIB="$LDFLAGS -lpng -lz"

echo "Installing the Tachyon binary..."
cd "$CUR"
binary_name=tachyon

# The '*' is a place-holder for the arch just built:
sdh_install src/compile/*/"${binary_name}" "$SAGE_LOCAL/bin"
