if [ "x$GCTLIB" = "x" ]
then
  GCTLIB=`pwd`/../../../
  PATH=.:`pwd`/../../..:$PATH
fi

ROOT=..
. $ROOT/run.source

# Override standard make_U to include dummy routines.
make_U()
{
  hush_cc -c $1.c
  hush_cc -c gct-ps-defs.c
  hush_cc -c dummy.c
  hush_cc -o U $1.o gct-ps-defs.o test-driver.o gct-write.o dummy.o
}

# Override standard make_I to include checking routines. 
make_I()
{
	gct -B$GCTLIB $1.c
	maybe_log
	hush_cc -c T$1.c
	hush_cc -c gct-ps-defs.c
	hush_cc -c util.c
	hush_cc -o I T$1.o gct-ps-defs.o test-driver.o gct-write.o util.o
}


count_race_macros()
{
  # Change all macros to dollar signs.
  sed 's/GCT_RACE_GROUP/$$$/g' < T$1.c > dollar.out
  # Change everything else to a blank and count words.
  sed 's/[^$]/ /g' dollar.out | sed 's/\$\$\$/word/g' | sed 's/\$/ /g' |\
	wc -w > count.out
}
# For some reason, on SunOS 4.1.1, the call to ../../../cut-map in the standard
# run.source file makes the shell dump core (only in the race
# routines). So I replaced it with the contents of cut-map.  Sigh.

log_check()
{
  /bin/rm -f GMERGE
  join gct-map GLOG | sed -e 's/[0-9]* [^ ]* //p' > GMERGE
  diff GMERGE $1.ref 
}

race_test ()
{
	std_test $1
	count_race_macros $1; diff -b count.out $1.cref
}

clean
make_constant_objects

sed 's/#define GCT_THREAD.*>>>/#define GCT_THREAD Thread/' gct-defs.h > /tmp/G$$
/bin/rm gct-defs.h ; 
sed '/<<<TAG>>>/d' /tmp/G$$ > gct-defs.h

race_test $1


if [ -f MASTER_LOG ]
then
	breport -test-map ${GCTLIB}btool_map MASTER_LOG > REPORT
fi

exit 0
