#!/bin/sh

# Reinstrument changed GCT files.  Saved versions are optionally
# placed in 'save'.

# 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
# path.
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

# Make sure all executables are remade, so that they're consistent about
# which mapfile they want.  Sources must be compiled first.
# Note:  The gen* programs are usually not remade during a
# reinstrumentation, so don't have to worry about building those 
# utility executables before doing the -test-nolink compile.
 

make cleanexec > /dev/null
/bin/rm -f gct-write.c /var/tmp/__gct_lock__
sed 's/.*#define GCT_LOCKING.*/#define GCT_LOCKING/' gct-write.G > gct-write.c


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

# 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
