#!/usr/bin/env bash
set -e
# Spur VM with VM profiler and threaded heartbeat
INSTALLDIR=sqcogspur64sunosht/usr
# Some gcc versions create a broken VM using -O2
OPT="-DAIO_DEBUG -DNDEBUG -DDEBUGVM=0"
MAKE=gmake

CFLAGS="$OPT -DCOGMTVM=0"
LIBS="-lmapmalloc"
LDFLAGS=""

if [ $# -ge 1 ]; then
	INSTALLDIR="$1"; shift
fi

if ../../../../scripts/checkSCCSversion ; then exit 1; fi
echo -n "clean? "
read a
case $a in
n|no|N|NO)	echo "ok but this isn't safe!!";;
*)			test -f Makefile && $MAKE reallyclean
esac
test -f plugins.int || (test -f ../plugins.int && cp -p ../plugins.int . || cp -p ../../plugins.int .)
test -f plugins.ext || (test -f ../plugins.ext && cp -p ../plugins.ext . || cp -p ../../plugins.ext .)
test -f config.h || ../../../../platforms/unix/config/configure --without-npsqueak \
		--with-vmversion=5.0 \
		--without-libtls \
		--without-vm-sound-Sun \
		--without-vm-sound-OSS \
		--disable-dynamicopenssl \
		--with-src=src/spur64.cog \
		--with-scriptname=spur64 \
	TARGET_ARCH="-m64" \
	CFLAGS="$CFLAGS" \
	LIBS="$LIBS" \
	LDFLAGS="$LDFLAGS"
rm -f vm/sqUnixMain.o # nuke version info
rm -rf ../../../../products/$INSTALLDIR
# prefer $MAKE install prefix=`readlink -f \`pwd\`/../../../../products/$INSTALLDIR`
# but older linux readlinks lack the -f flag
$MAKE install-squeak install-doc install-plugins prefix=`(cd ../../../../;pwd)`/products/$INSTALLDIR 2>&1 | tee LOG
