#!/bin/csh -f
#
# install Proteus
#
# Copyright 1992, Eric A. Brewer
#
# Last modified: 11-25-92
#

### please set the following environment variables

setenv INIT_CC cc
setenv INIT_YACC 'bison -y'
setenv INIT_LIBDIR /usr/lib



### start of installation

cd augment
if ($status) then
	echo "Unable to find subdirectory augment"
	exit(1)
endif

cd libm
if ($status) then
	echo "Unable to find subdirectory augment/libm"
	exit(1)
endif

cd ../libc
if ($status) then
	echo "Unable to find subdirectory augment/libc"
	exit(1)
endif



################# generate include files for augment

make missing
if ($status) then
	echo "Unable to generate libc/missing.h and libc/counted.h"
	exit(1)
endif

cd ../libm
make missing
if ($status) then
	echo "Unable to generate libm/missing.h and libm/counted.h"
	exit(1)
endif



################# install augment

cd ..
./INSTALL-AUGMENT
if ($status) then
	echo "Unable to build augment"
	exit(1)
endif
cd ../bin
ln -s ../augment/augment
cd ../augment

################# build libcyc.a

cd libc
echo ""
echo "****"
echo "****  Building cycle-counting library libcyc.a"
echo "****"
echo ""
make libcyc.a
if ($status) then
	echo "Unable to build libcyc.a"
	exit(1)
endif
cd ../../lib
ln -s ../augment/libc/libcyc.a
cd ../augment


################# build libcycm.a

cd libm
echo ""
echo "****"
echo "****  Building cycle-counting math library libcycm.a"
echo "****"
echo ""
make libcycm.a
if ($status) then
	echo "Unable to build libcycm.a"
	exit(1)
endif

cd ../../lib
ln -s ../augment/libm/libcycm.a

################# build catoc

echo ""
echo "****"
echo "****  Building catoc, catis"
echo "****"
echo ""

cd ../catoc
if ($status) then
	echo "Unable to find subdirectory catoc"
	exit(1)
endif

ln -s ../bin/augment .

make catoc
if ($status) then
	echo "Unable to build catoc"
	exit(1)
endif
cd ../bin
ln -s ../catoc/catoc
cd ../catoc

make catis
if ($status) then
	echo "Unable to build catis"
	exit(1)
endif
cd ../bin
ln -s ../catoc/catis
cd ../catoc

################# build catoc-test

echo ""
echo "****"
echo "****  Building catoc test program: catoc-test"
echo "****"
echo ""
make catoc-test
if ($status) then
	echo "Unable to build catoc-test"
	exit(1)
endif



################# run catoc-test

echo ""
echo "****"
echo "****  Executing catoc-test"
echo "****"
echo ""

./catoc-test
if ($status) then
	echo "catoc-test failed..."
	exit(1)
endif

make reset


################# build saveparams

echo ""
echo "****"
echo "****  Building saveparams"
echo "****"
echo ""

cd ../saveparams
if ($status) then
	echo "Unable to find subdirectory saveparams"
	exit(1)
endif

make saveparams
if ($status) then
	echo "Unable to build saveparams"
	exit(1)
endif
cd ../bin
ln -s ../saveparams/saveparams

################# build simex

echo ""
echo "****"
echo "****  Building simex"
echo "****"
echo ""

cd ../simex
if ($status) then
	echo "Unable to find subdirectory simex"
	exit(1)
endif

make simex
if ($status) then
	echo "Unable to build simex"
	exit(1)
endif
cd ../bin
ln -s ../simex/simex

###########################

echo ""
echo ""
echo '************'
echo ""
echo "Build complete, be sure to:"
echo "  1) Adjust your path to include the bin directory"
echo "  2) Edit SimMake to set LIBDIRS, the path to the cycle-counting"
echo "       libraries. (They are currently in the lib subdirectory.)"
echo ""
