#!/bin/sh

# Note:  use sed to strip blanks because not all systems have same version
# of diff.

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


# Just make sure that -S works

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

assert_no_object()
{
  if [ -f test.o ]
  then
	echo "FAILURE:  Should not have created .o file."
  fi
}

# After -S, finish compiling and linking. Then run.
finish()
{
	ASSEMBLER=$1
	COMPILER=$2
	$ASSEMBLER -o test.o test.s 
	$COMPILER -c gct-write.c
	$COMPILER -c gct-ps-defs.c
	$COMPILER test.o gct-write.o gct-ps-defs.o
	./a.out > test.log
	diff test.log test.ref
	greport GCTLOG > test.glog; diff test.glog test.gref
}

echo "$INDENT" " The following test will fail if your 'cc' does not"
echo "$INDENT" " support the -S option.  That's harmless."
say cc
make clean
gct-init $GCTLIB
gct -B$GCTLIB -S test.c
assert_no_object

if [ "$GCT_UNPORTABLE_OK" = true ]
then
	finish /bin/as cc

	# Now try GCC
	say gcc
	make clean
	gct-init $GCTLIB
	gct -test-cc gcc -B$GCTLIB -S test.c
	assert_no_object
	finish gas gcc

	
	# As above, but use -c and -S together
	say gcc-c
	make clean
	gct-init $GCTLIB
	gct -test-cc gcc -B$GCTLIB -S -c test.c
	assert_no_object
	finish gas gcc
fi


exit 0
