#!/usr/bin/env bash
set -e
# debug Spur VM with VM profiler and itimer heartbeat
INSTALLDIR=debug/nsnaccogspur64linux
OPT="-g3 -O0 -DDEBUGVM=1"

if [ $# -ge 1 ]; then
	case "$1" in
	-*)	;;
	*)	INSTALLDIR="$1"; shift
	esac
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!!";;
*)			rm -f config.h; test -f Makefile && make reallyclean
esac
../../../../scripts/copylinuxpluginspecfiles
test -f config.h || ../../../../platforms/unix/config/configure \
		--with-vmversion=5.0 \
		--with-src=src/spur64.cog.newspeak \
		--without-vm-display-fbdev --without-npsqueak \
	TARGET_ARCH="-m64" \
	CC=clang \
	CFLAGS="$OPT -DEnforceAccessControl=0 -msse2 -DITIMER_HEARTBEAT=1"
rm -f vm/sqUnixMain.o # nuke version info
rm -rf ../../../../products/$INSTALLDIR
make install-squeak install-plugins prefix=`(cd ../../../../;pwd)`/products/$INSTALLDIR 2>&1 | tee LOG ; test ${PIPESTATUS[0]} -eq 0
../../editnewspeakinstall.sh ../../../../products/$INSTALLDIR -source SqueakV41 "$@"
