#!/bin/bash -e
# debug PharoVM with VM profiler and threaded heartbeat
INSTALLDIR=debug/cogspur64linuxht
OPT="-g3 -O0 -fwrapv -DDEBUGVM=1 -DPharoVM"

if [ $# -ge 1 ]; then
	INSTALLDIR="$1"; shift
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 \
		--with-src=spur64src \
	CC="gcc -m64" \
	CXX="g++ -m64" \
	CFLAGS="$OPT -msse2 -D_GNU_SOURCE -DCOGMTVM=0" \
	LIBS="-lpthread -luuid -Wl,-rpath,'\$\$ORIGIN' " \
	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
../../editpharoinstall.sh ../../../products/$INSTALLDIR "$@"
