#!/bin/bash -e
# assert Spur VM with VM profiler and threaded heartbeat
INSTALLDIR=assert/nsnaccogspur64linuxht
OPT="-g3 -O1 -fwrapv -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -DDEBUGVM=0"

if [ $# -ge 1 ]; then
	case "$1" in
	-*)	;;
	*)	INSTALLDIR="$1"; shift
	esac
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
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 \
		--with-vmversion=5.0 \
		--with-src=nsspur64src \
		--without-vm-display-fbdev --without-npsqueak \
	CC="gcc -m64" \
	CXX="g++ -m64" \
	CFLAGS="$OPT -DEnforceAccessControl=0 -msse2 -D_GNU_SOURCE" \
	LIBS="-lpthread -luuid" \
	LDFLAGS=-Wl,-z,now
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
../../editnewspeakinstall.sh ../../../products/$INSTALLDIR -source SqueakV41 "$@"
