#!/bin/csh -f
#
#  maketestdir - make a new directory where we can build and run STARFISH
#
# Part of 
#           The STARFISH Parallel file-system simulator
#      (Simulation Tool for Advanced Research in File Systems)
#
#                              David Kotz
#                          Dartmouth College
#                             Version 3.0
#                             October 1996
#                         dfk@cs.dartmouth.edu


if ($#argv != 1) then
    echo usage: maketestdir dirname
    exit 1
endif

set dir="$1"
if (-e $dir) then
    echo $dir exists, you must supply a new directory name
    echo usage: maketestdir dirname
    exit 1
endif

if ($dir =~ */*) then
    echo you must choose a simple directory name in the current directory
    exit 1
endif

onintr cleanup2

# build the basic proteus compilation directory
# this is assuming that ./proteus contains the proteus engine code
mkdir $dir

cd $dir
onintr cleanup
ln -s ../proteus/*.h .         || goto cleanup
cp -i ../proteus/*.param .     || goto cleanup
chmod +w *.param
ln -s ../proteus/mk_* .        || goto cleanup
ln -s ../proteus/gdb-macros .  || goto cleanup
ln -s ../proteus/*.ca .        || goto cleanup
ln -s ../proteus/*.c .         || goto cleanup
ln -s ../proteus/*.S .         || goto cleanup

rm -f schedule.*c
rm -f {queens,test1,test2}.ca

# link in the STARFISH user makefile
ln -s ../Makefile UserMake  ||  goto cleanup

cd ..

# replace the default proteus .params with my favorite configuration
cp typical/*.param $dir/    ||  goto cleanup2
cp typical/SimMake $dir/    ||  goto cleanup2

# use that to link in the rest of the STARFISH files
domake $dir links
if ($status != 0) goto cleanup2

echo ""
echo now you may build proteus in $dir as follows:
echo domake $dir mydepend
echo domake $dir

exit 0

cleanup:
cd ..

cleanup2:
echo something went wrong, cleaning up...
rm -rf $dir
exit 1
