:
#    Copyright (c) 1996 - 2001 Caldera International, Inc.
#                     All Rights Reserved
#
# @(#) S9setup:1.16 1/22/1996 00:00:00
#
# S9setup
#

NNL=
CCL=

#
# first, figure out how to make echo work without automatic newline
#
if echo "\c" | grep c >/dev/null 2>&1
then
	NNL='-n'
else
	CCL='\c'
fi

#
# are we doing an APR ?
#
case "$1" in
	"")             DOAPR=NO;;
	"doapr")        DOAPR=YES;;
	*)              echo
			echo "Usage: S9setup<CR> or S9setup doapr<CR>"
			echo
			exit 0;;
esac
case $# in
	0)		echo;;
	1)		echo;;
	*)		echo
			echo "Usage: S9setup<CR> or S9setup doapr<CR>"
			echo
			exit 0;;
esac
#
# display intro
#
echo
echo
echo
echo "          AIM Independent Resource Benchmark - Suite IX S9setup"
echo "          Copyright (c) 1996 - 2001 Caldera International, Inc."
echo "                          All rights reserved"
echo
echo
echo "------------"
echo "INTRODUCTION"
echo "------------"
echo
if test "$DOAPR" = "YES"
then
  echo "YOU HAVE INDICATED THAT THIS IS AN APR RUN."
  echo
fi
echo "This script guides you through the steps needed to tailor the AIM"
echo "Independent Resource Benchmark - Suite IX to your environment.  "
echo "It will ask you a series of questions to identify the components of"
echo "the System Under Test (SUT).  As each question is displayed on the "
echo "screen, you can accept the default value that is enclosed in brackets"
echo "(e.g. [default_value] ), or enter the correct value.  At any point"
echo "during the execution of this script, you may type Q to terminate it."
echo
echo "CAUTION:  This script will NOT automatically set up the correct environment"
echo "to run the benchmark.  It is important that you provide the correct"
echo "information for the computer and operating system that are being benchmarked."
echo "Verify and edit the files Makefile as required before running singleuser."
echo
echo

while :
do
	echo $NNL "Press RETURN to continue, press Q to exit ...$CCL"
	read ANS
	case "$ANS" in
	        "")     break;;
	        Q)      exit 0;;
	        *)      echo; echo "\"$ANS\" is not allowed ... ^G";;
	esac
done

echo
echo
echo
echo "You will be asked to provide the following information about the system"
echo "to be tested:"
echo
echo "	1) Your compiler name"
echo
echo "	2) The compiler options to be used"
echo
echo "	3) The linker options to be used"
echo
echo "	4) The location of the Bourne shell executable"
echo
if test "$DOAPR" = "YES"
then
echo "	5) The Path for temporary files created by disk tests"
echo
fi
#echo "	5) The Per Test Period in seconds"
#echo
#echo "	6) The Path for temporary files created by disk tests"
#echo
#echo "	7) The file size for the temporary files created during disk tests"
#echo
echo "If you do not know or are unsure about any of the items mentioned above,"
echo "press Q to terminate this installation script.  Check with your System"
echo "Administrator or consult the SUT manuals for the correct information."
echo
echo
while :
do
	echo $NNL "Press RETURN to continue, press Q to exit ...$CCL"
	read ANS
	case "$ANS" in
	        "")     break;;
	        Q)      exit 0;;
	        *)      echo; echo "\"$ANS\" is not allowed ... ^G";;
	esac
done
#
# init default settings
#
CC=cc
DCCOPT=-O
BSH=/bin
TEST_TIME=20
DPATH=./
DSIZE=1M
#
#---------------------
# get the AIM id #
#---------------------
if test "$DOAPR" = "YES"
then
    AIMID=`ls ../#* 2> /dev/null | wc -l`
    if [ $AIMID -eq 1 ]  # here is aimid#, is it correct?
    then
	echo $NNL "Enter the AIM id [`cd ..; ls \#*`] :$CCL"
	read ANS
	if [ "$ANS" != "" ]
	then
	    ANS=`echo $ANS | sed "s/^#//"`    # make sure safe to add # sign
	    touch ../\#$ANS
	fi
    else
	echo $NNL "Enter the AIM id :$CCL"
	read ANS
	ANS=`echo $ANS | sed "s/^#//"`        # make sure safe to add # sign
	touch ../\#$ANS
    fi
fi
#
echo
echo
echo "----------"
echo " COMPILER "
echo "----------"
echo
echo "Enter the name of the C compiler you wish to use for this run."
echo
echo "   Please use BOTH upper and lower case, exactly as required by your"
echo "   compiler."
echo
echo $NNL "Enter compiler name [$CC] :$CCL"
read ANS
if test ! "$ANS" = ""
then
	CC=$ANS
fi
#
echo
echo
echo "----------------"
echo "COMPILER OPTIONS"
echo "----------------"
echo
echo "Enter any compiler options that you want to use for $CC.  Some examples"
echo "of valid entries are listed below:"
echo
echo "       \"-O\" to optimize code produced by \"pcc\" based compilers"
echo "       \"-OP\" to do peephole optimization with the Pyramid OSx compiler"
echo "       \"-O -f68881\" for optimization and floating point for Sun-3's"
echo
echo "Please note that the benchmark is written in Ansi C and is POSIX"
echo "compliant.  Some compilers have special flags for these options."
echo
echo "   Please use BOTH upper and lower case, exactly as required by your "
echo "   compiler."
echo
echo "  You may type Q to exit and look up the correct answer."
echo
echo $NNL "Enter compiler options [$DCCOPT] :$CCL"
read ANS
case "$ANS" in
        Q)      exit 0;;
        "")     CCOPT=$DCCOPT;;
        *)      CCOPT=$ANS;;
esac
#
LDOPT=
echo
echo
echo "--------------"
echo "LINKER OPTIONS"
echo "--------------"
echo
echo "Are there any linker options that you should identify for the benchmark?"
echo "For information on the linker, refer to the Programmer's Reference Manual"
echo "for your system.  You might identify a non-standard location of a library"
echo "or system specific libraries that are needed to build the benchmark."
echo "For example, enter \"-Wl,L/usr/local/lib\" to search for libraries in"
echo "a \"/usr/local/lib\" directory."
echo
echo "Note that the benchmark requires that networking routines such as 'socket()'"
echo "be available.  On some machines, an additional library such as -lsocket"
echo "will need to be specified.  Check with your System Administrator or"
echo "consult your System manuals."
echo
echo "   Again, use BOTH upper and lower case, exactly as required by your"
echo "   compiler."
echo
echo "  You may type Q to exit and look up the correct answer."
echo
echo $NNL "Enter linker options [$LDOPT] :$CCL"
read ANS
case "$ANS" in
	Q)	exit 0;;
	"")	;;
	*)	LDOPT=$ANS;;
esac
#
echo
echo
echo "------------"
echo "BOURNE SHELL"
echo "------------"
echo
echo "You must specify the location of the Bourne shell executable on your"
echo "system. 'sh' is usually found in /bin.  However, this may vary from"
echo "system to system.  Check with your System Administrator or consult"
echo "your System manuals."
echo $NNL "Enter the path to 'sh' [$BSH] :$CCL"
read ANS
case "$ANS" in
	Q)	exit 0;;
	"")	BSH=$BSH;;
	*)	BSH=$ANS;;
esac
#
#only ask if creating 'input' file for AIM staff
if test "$DOAPR" = "YES"
then
#echo
#echo
#echo "---------------"
#echo "PER TEST PERIOD"
#echo "---------------"
#echo
#echo "You may specify the amount of time allocated to the individual tests"
#echo "in the benchmark."
#echo
#echo "You may type Q to exit and determine the per test period."
#echo
#while :
#do
#echo $NNL "Enter the Per Test Period in seconds [$TEST_TIME] :$CCL"
#        read ANS
#        case "$ANS" in
#                [0-9])                  TEST_TIME=$ANS; break;;
#                [0-9][0-9])             TEST_TIME=$ANS; break;;
#                [0-9][0-9][0-9])        TEST_TIME=$ANS; break;;
#                [0-9][0-9][0-9][0-9])   TEST_TIME=$ANS; break;;
#                Q)                      exit 0 ;;
#		"")                     TEST_TIME=$TEST_TIME; break ;;
#                *)      echo ; echo "\"$ANS\" is not allowed ...^G";;
#        esac
#done
#
echo
echo
echo "------------------"
echo "PATH TO DISK FILES"
echo "------------------"
echo
echo "The disk tests create and use temporary files during the test."
echo "The actual location of these files may affect performance depending"
echo "on the speed of the disk used, location of the directory, etc."
echo $NNL "Enter the path for the disk files [$DPATH] :$CCL"
read ANS
case "$ANS" in
	Q)	exit 0;;
	"")	DPATH=$DPATH;;
	*)	DPATH=$ANS;;
esac
#echo
#echo
#echo "--------------"
#echo "TEST FILE SIZE"
#echo "--------------"
#echo
#echo "The disk tests create and use temporary files during the test."
#echo "The size of these files can be specified as an integral number of"
#echo "kilobytes (xK) or megabytes (xM)."
#echo
#echo "You may type Q to exit and determine the test file size."
#echo
#while :
#do
#echo $NNL "Enter the Test File Size in K of M [$DSIZE] :$CCL"
#        read ANS
#        case "$ANS" in
#                [0-9][k,K,m,M])            DSIZE=$ANS; break;;
#                [0-9][0-9][k,K,m,M])      DSIZE=$ANS; break;;
#                [0-9][0-9][0-9][k,K,m,M]) DSIZE=$ANS; break;;
#                Q)                        exit 0 ;;
#		"")                       DSIZE=$DSIZE; break ;;
#                *)      echo ; echo "\"$ANS\" is not allowed ...^G";;
#        esac
#done
fi  # end of doapr loop
#
# create makefile
#
echo
echo $NNL "Creating \"Makefile\" ... $CCL"

rm -f Makefile

echo "#  Copyright (c) 1996 - 2001 Caldera International, Inc." > Makefile
echo "#                    All Rights Reserved"                 >> Makefile
echo "#"                                                        >> Makefile
echo "CC=$CC"                                                   >> Makefile
echo "CCOPT=$CCOPT"                                             >> Makefile
echo "LDOPT=-lm $LDOPT"                                         >> Makefile
echo                                                            >> Makefile
echo "CFLAGS= \$(CCOPT)"                                        >> Makefile
#
cat >> Makefile <<END

SRCS =  add.c disk1.c div.c fun.c funcal.c mul.c \\
	ram.c creat-clo.c disk_src.c int_fcns.c num_fcns.c pipe_test.c \\
	fillin.c rand.c rtmsec.c

TASKS = add.o disk1.o div.o fun.o funcal.o mul.o \\
	ram.o creat-clo.o disk_src.o int_fcns.o num_fcns.o pipe_test.o

OBJS = fillin.o rand.o rtmsec.o \$(TASKS)

# ugly but portable, even on (very) dumb makes..

.c.o:	suite.h
	\$(CC) \$(CFLAGS) -c \$*.c

all:	singleuser rpt9
	echo "#!$BSH/sh" > true
	chmod +x true

singleuser: singleuser.o suite.h files.h \$(OBJS)
	\$(CC) \$(CFLAGS) -o singleuser singleuser.o \$(OBJS) \$(LDOPT)

rpt9: rpt9.o
	\$(CC) \$(CFLAGS) -o rpt9 rpt9.o \$(LDOPT)

add.o : add.c suite.h

creat-clo.o : creat-clo.c suite.h

disk1.o : disk1.c suite.h

disk_src.o : disk_src.c suite.h

div.o : div.c suite.h

fillin.o : fillin.c suite.h

fun.o : fun.c suite.h funcal.h

funcal.o : funcal.c suite.h funcal.h

mul.o : mul.c suite.h

singleuser.o : singleuser.c suite.h files.h

int_fcns.o : int_fcns.c suite.h

num_fcns.o : num_fcns.c suite.h

pipe_test.o : pipe_test.c suite.h

ram.o : ram.c suite.h

rand.o : rand.c suite.h

rtmsec.o : rtmsec.c suite.h testerr.h

clean newrun:
	@echo "Resetting AIM Independent Resource Benchmark - Suite IX for another run."
	@rm -f tmp* core *.o

reset:
	@echo "Resetting AIM Independent Resource Benchmark - Suite IX to new install condition."
	@rm -f s9workfile suite9.ss logfile.suite9 results
	@rm -f input singleuser nohup.out
	@rm -f tmp* core *.o
	@cp Makefile.setup Makefile

END
cp Makefile Makefile.orig		# for SAVE script
#
rm -f tmp* core *.o
if test "$DOAPR" = "FORGET IT"
then
  USE_OLD_APRINFO=NO
  if test -f ../save/APRINFO
    then
	NO_OLD_APRINFO=FALSE
	echo "There is an APRINFO file in the ../save directory already."
	while :
	do
		echo
		echo "Use the information in that APRINFO file for this Suite 9 run (y/n)? [y]: $CCL"
		read ANS
		case "$ANS" in
			Y|y)	USE_OLD_APRINFO=YES; break;;
			N|n)	USE_OLD_APRINFO=NO;  break;;
			"")	USE_OLD_APRINFO=YES; break;;
			*)	echo ; echo "\"$ANS\" is not allowed ...^G";
		esac
	done
    else
        NO_OLD_APRINFO=TRUE
  fi
  if test "$USE_OLD_APRINFO" = "NO" -o "$NO_OLD_APRINFO" = "TRUE"
    then
	while :
		do
		echo
		echo $NNL "Enter the name of the System Under Test [ex: PS570]:$CCL"
		read SUT_NAME
		echo
		while :
			do
			echo "The name of the System Under Test is $SUT_NAME."
			echo $NNL "Press Enter to accept press C to change: $CCL"
			read ANS
			case "$ANS" in
				"C")	break;;
				"")	break;;
				*)	echo; echo "\"$ANS\" is not allowed ...." ;;
			esac
		done
		if test "$ANS" = ""
		then break;
		fi
	done
    else
	# there is an APRINFO file in the ../save directory already and we are to use
	# its content for this Suite 9 run
	SUT_NAME=`grep "NAME:" ../save/APRINFO | sed 's/	//' | awk -F: '{print $2}'`
	echo
	echo "The name of the System is $SUT_NAME"
  fi
fi  # end of forget it loop
if test "$DOAPR" = "YES"
then
  #
  # Build Suite 9 input file
  #
  if test -f input
  then
    rm -f input
  fi
  echo $SUT_NAME > input
  echo $SUT_NAME >> input
  echo 15 >> input
  echo "$DPATH" >> input
  chmod 644 input
fi  # end of doapr loop
#
# done
#
echo
echo "completed."
echo
echo

if test "$DOAPR" = "YES"
then
  echo "Makefile and input have been created."
  echo
  echo "Enter \"make\" to build AIM Suite 9."
  echo
  echo "Type RUN to run the benchmark then SAVE to 'cat' the information to be"
  echo "saved for this run to the screen for downloading.  Also download the"
  echo "suite9.ss file."
  echo
  echo "If you are running this benchmark on a remote system and it is best to"
  echo "logoff while Suite 9 is running, use:"
  echo "        \"nohup RUN &\""
  echo "to start Suite 9 then logoff. Log back in about 15 minutes later to run the"
  echo "SAVE script to 'cat' the information to be saved for this run to the screen"
  echo "for downloading.  Also download the suite9.ss file."
else
  echo "The file \"Makefile\" has been created."
  echo
  echo "Enter \"make\" to build AIM Independent Resource Benchmark Suite IX."
  echo
  echo "Type \"singleuser\" to run AIM Independent Resource Benchmark Suite IX."
fi
echo
echo "If there are any problems, you can either run this configuration script"
echo "again or edit the \"Makefile\" directly."
