#!/bin/sh
#
#  =====================
#  CCI SHELL SCRIPT "cci"
#  =====================
#
#  VERSION 1.1 : May 31, 1996
#
#  The following shell script will backup the current LAPACK
#  code by moving the lapack_RS6K.a library to lapack_RS6K_noCCI.a
#  Then, the LAPACK source files will be moved from *.f to *.f.old
#  Finally, the CCI files will be put in the LAPACK/SRC directory,
#  compiled, and put into the library lapack_RS6K.a
#  To accomplish the above, type "cci".
#
echo '============='
echo '   CCI 1.1'
echo '============='
echo 
echo 'Installion beginning...'
echo
echo 'Renaming files so that they are not overwritten.'
echo
#
#  Check if lapack_RS6K.a library exists.
#  If so, rename it so that it is not overwritten.
#
if [ -f lapack_RS6K.a ]; then
	echo 'lapack_RS6K.a exists.'
	mv -f lapack_RS6K.a lapack_RS6K_noCCI.a
	echo 'Renamed to lapack_RS6K_noCCI.a'
else
	echo 'lapack_RS6K.a does not exist.'
fi
echo
#
#  Check if make.inc exists.
#  If so, rename it so that it is not overwritten.
#
if [ -f make.inc ]; then
	echo 'make.inc exists.'
	mv -f make.inc make.inc.old
	echo 'Renamed to make.inc.old'
else
	echo 'make.inc does not exist.'
fi
echo
#
#  Check if standard LAPACK routines exist.
#  If so, rename them so that they are not overwritten.
#
cd SRC
for file in sgetrf.f sgetri.f sgetrs.f spbtrf.f spotrf.f spotri.f spotrs.f \
	spptrf.f spptri.f stptri.f strtri.f \
	cgetrf.f cgetrs.f cpotrf.f cpotrs.f \
	dgetrf.f dgetri.f dgetrs.f dpbtrf.f dpotrf.f dpotri.f dpotrs.f \
	dpptrf.f dpptri.f dtptri.f dtrtri.f \
	zgetrf.f zgetrs.f zpotrf.f zpotrs.f
do
	if [ ! -f "$file" ]; then
		echo "$file not found!"
		continue
	else
		mv -f $file $file.old
		echo "$file renamed to $file.old"
	fi
done
cd ..
echo
#
#  Renaming complete.
#
echo 'Renaming complete.'
echo
sleep 2
#
#  Remove object files so that CCI can be compiled.
#
echo 'Removing old object files.'
echo
cd SRC
for file in sgetrf.o sgetri.o sgetrs.o spbtrf.o spotrf.o spotri.o spotrs.o \
	spptrf.o spptri.o stptri.o strtri.o \
	cgetrf.o cgetrs.o cpotrf.o cpotrs.o \
	dgetrf.o dgetri.o dgetrs.o dpbtrf.o dpotrf.o dpotri.o dpotrs.o \
	dpptrf.o dpptri.o dtptri.o dtrtri.o \
	zgetrf.o zgetrs.o zpotrf.o zpotrs.o
do
	if [ ! -f "$file" ]; then
		echo "$file not found!"
		continue
	else
		rm -f $file
		echo "$file removed."
	fi
done
cd ..
echo
#
#  Removal complete.
#
echo 'Removal complete.'
echo
sleep 2
#
#  Untar CCI make.inc and CCI source files
#
echo 'Installing new make.inc and CCI source files.'
echo
tar xvf ccisrc.tar
echo 'Files in place.'
echo
sleep 2
#
#  Rebuild lapack_RS6K.a with CCI enabled.
#
echo 'Rebuilding lapack_RS6K.a with CCI.'
echo 'If this script fails after this point,'
echo 'edit the make.inc file and make sure that'
echo 'BLASLIB defines the correct ESSL library.'
echo 'The default is -lessl.  However, -lesslp2'
echo 'may be preferable if using an RS6K POWER2.'
echo 'If the make.inc is changed, it will be'
echo 'necessary to remove the object files in'
echo 'LAPACK/SRC and type "make lapacklib" in'
echo 'the LAPACK directory.'
echo
sleep 2
make lapacklib
echo 'CCI installation complete.'
echo 'Enjoy the enhanced performance of your IBM RS6K!!'
echo
