#!/bin/sh

# Reinstrument all of GCT from scratch.  Saved versions are optionally
# placed in 'save'.

# /usr/tmp/GCTLOG is deleted before instrumentation (after perhaps being
# saved).  It becomes a record of how GCT is exercised when it instruments
# itself.

# Make sure installed versions of GCT are used in preference to 
# just-being-built versions.  Annoying that this doesn't
# change automatically if I change the makefile, but I rarely change the
# makefile.

GCT=${1:-gct}
COMPILER=${2:-""}

bindir=/usr/port/bin
PATH=$bindir:$PATH
export PATH

# The installed version's library directory.  
libdir=/x/new/lib/

# Exit on error.
set -e

echo "Save current instrumented state of system?"
read answer
if [ "y" = "$answer" ]
then
	./dosave
fi

date
make clean > /dev/null
rm -f /usr/tmp/GCTLOG
gct-init -test-map gct-map.self
/bin/rm -f /var/tmp/__gct_lock__
/bin/rm -f gct-write.c
sed 's/.*#define GCT_LOCKING.*/#define GCT_LOCKING/' gct-write.G > gct-write.c

make "CC=$GCT $COMPILER -DTESTING -B$(libdir)/ -test-map gct-map.self -test-control gct-ctrl.self"
date

# For convenience, link gct-map.self and gct-map.  I use gct-map.self 
# because I often try little test instrumentations in this source
# directory, and I don't want to overwrite GCT's map file.
if [ -f gct-map ] ; then /bin/rm gct-map; fi
ln gct-map.self gct-map	

echo "FINISHED:  Use 'update' if you want to update the logfile."

exit 0
