#!/bin/sh
if [ "x$GCTLIB" = "x" ]
then
  GCTLIB=`pwd`/../../../
  PATH=.:`pwd`/../../..:$PATH
  export PATH
fi

#  This compiles files but throws away stupid copyright messages that 
#  some C compilers spit to stderr.  
hush_cc()
{
  cc $* 2> /tmp/Gerr$$
  grep -v 'Copyright (C)' /tmp/Gerr$$ 1>&2
  rm /tmp/Gerr$$
}

say()
{
	echo "$INDENT" " $1"
}

doit()
{
	gct -B$GCTLIB $1.c
	hush_cc -c $1.c 
	hush_cc -c T$1.c
	cmp $1.o T$1.o
}

# This copies a file from the source directory.  It runs it through the
# preprocessor to remove things like effect of #ifdef __GNUC__.
copy()
{
	(cd $GCTLIB; /lib/cpp  -I. -I. -I./config < $1.c > /tmp/__TEST.c)
	mv /tmp/__TEST.c $1.c 
}


make clean
gct-init $GCTLIB

echo $INDENT "NOTE:  On Systems that use COFF, the comparison of object files will fail."

# Can't use copy -- special -D options.
say cccp
(cd $GCTLIB; cccp  -I. -I. \
	-I./config -DGCC_INCLUDE_DIR=\"/tmp\" \
	-DGCT_INCLUDE_DEFAULT=\"/tmp\" \
	-DSTANDARD_STARTFILE_PREFIX=\"/tmp/\" \
	-DGPLUSPLUS_INCLUDE_DIR=\"/tmp\" \
	< cccp.c > /tmp/__TEST.c)
mv /tmp/__TEST.c cccp.c 
doit cccp

if [ -f TEST-ALL ] 
then
  for i in `cat GCT_CASES`
  do
    $GCTLIB/testdir/checktest $GCTLIB/testdir
    say $i; copy $i; doit $i
  done
fi



say shar; doit shar
say getopt; doit getopt

