#!/usr/bin/env bash
set -e
# debug Stack Spur VM with VM profiler and threaded heartbeat
INSTALLDIR=debug/sqstkspur64ARMv8linuxht
OPT="-g3 -O0 -DDEBUG -DDEBUGVM=1 -D_GNU_SOURCE"

### OPT="-g3 -O0 -DDEBUGVM=1"

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!!";;
*)			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.stack --disable-cogit \
	--without-npsqueak \
	--with-scriptname=spur64 \
	CC=gcc \
	VM_WORD_SIZE="64" \
	VM_CFLAGS="$OPT"
	CFLAGS="$OPT"
##	--without-vm-display-fbdev --without-npsqueak \
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-plugins prefix=`(cd ../../../../;pwd)`/products/$INSTALLDIR 2>&1 | tee LOG ; test ${PIPESTATUS[0]} -eq 0
