#!/bin/sh -x
#
# $Id$
#
# Run this to build and twice rebuild the heap, and to run GC test code.
# By overriding the setting for CUSTOM_EXPRESSIONS on the command line
# it is possible to choose different compiler switches, for example
#   CUSTOM_EXPRESSIONS='(fast-unsafe-code)' autobuild-precise
# will build everything using fast-unsafe settings.

CUSTOM_DEFAULT=""
CUSTOM_EXTRA='(issue-warnings #f) (inline-allocation #f)'

CUSTOM_EXPRESSIONS="${CUSTOM_EXPRESSIONS:-$CUSTOM_DEFAULT} $CUSTOM_EXTRA"

BUILD_SYSTEM=${BUILD_SYSTEM:-1}
BUILD_GC_TESTS=${BUILD_GC_TESTS:-1}
RUN_GC_TESTS=${RUN_GC_TESTS:-1}
LOG="log.auto"
TRACE="trace.auto"

if [ $BUILD_SYSTEM != 0 ]; then
build -chez <<EOF
$CUSTOM_EXPRESSIONS
(system "make libclean faslclean")
(make-sparc-heap)
(make-development-environment)
EOF
rm -f larceny.bin ; ln -s bdwlarceny.bin larceny.bin

build -lb <<EOF
$CUSTOM_EXPRESSIONS
(system "make libclean faslclean")
(make-sparc-heap)
(make-development-environment)
EOF

cp sparc.heap sparc.heap.safe
build -lb <<EOF
$CUSTOM_EXPRESSIONS
(system "make libclean faslclean")
(make-sparc-heap)
(make-development-environment)
EOF
cmp sparc.heap sparc.heap.safe || ( echo "ERROR -- heaps not equal" ; exit 1 )
fi

if [ $BUILD_GC_TESTS != 0 ]; then
  build -lb <<EOF
$CUSTOM_EXPRESSIONS
(make-gc-testsuite)
(make-regression-test)
EOF
fi

if [ $RUN_GC_TESTS != 0 ]; then
  cd Testsuite/GC
  ../../larceny.bin ../../sparc.heap <<EOF
(load "../run-gc-tests.sch")
(run-gc-tests "../../larceny.bin" "../../sparc.heap" "$LOG" "$TRACE" 'conservative)
EOF
fi
