#! /bin/sh
#
# The C-Mix example makefiles use this script.
#
# print-time [-s <filename>] <executable> <repeat> <testdata>
#
program=$0

if [ $# -lt 3 ]
then
	echo "Usage:" 2>&1
	echo "\t$0 [-s <filename>] <executable> <repeat> <testdata>" 2>&1
	exit 1
fi

if [ x$1 = x-s ]
then
	sourcefile=$2
	shift 2
else
	sourcefile=$1
fi

executable=$1
repeat=$2
testdata=$3

if [ ! -x $executable-time ]
then
	echo "$0: Time-program \`$executable-time' not executable" 2>&1
	exit 2
fi

if [ x$ARCH = x ]
then
	if [ x$DIKUARCH = x ]
	then
		ARCH="probably sparc-linux-gnu"
	else
		ARCH=$DIKUARCH
	fi
fi

origsize="unknown"
if [ -r $sourcefile.o ]
then
	origsize=`wc -c $sourcefile.o`
fi

ressize="unknown"
if [ -r $executable-res.o ]
then
	ressize=`wc -c $executable-res.o`
fi

echo ============================================================
echo "Program $sourcefile.c on host $HOST, architecture $ARCH:"
echo "Compiler command is \`${CC-gcc} $CPPFLAGS ${CFLAGS-}'"
echo "Test repeated $repeat time(s), input is \`$testdata'."
echo
echo "Source   program size: $origsize"
echo "Residual program size: $ressize"
echo
./$executable-time $repeat $testdata
echo ============================================================
