#!/bin/csh -f

# Harpoon directory under SHARC_HOME
set hpn_dir = harpoon

# Valid Architectures
#--------------------
set machin = (hp_11.0_64 \
              apple_10.3_32 \
              linux_2.4 \
              linux_2.4_64 \
              linux_2.6_64 \
              linux_ia64_2.4 \
              sgi_6.5_n64 \
              ibm_5.3_64 \
              sun_8_64)


# Verify that SHARC_HOME is set
#---------------------------------
if ($?SHARC_HOME) then
  echo "Using SHARC_HOME = $SHARC_HOME"
else
  echo ""
  echo "The SHARC_HOME environment variable"
  echo "must be set before you can run Harpoon"
  echo ""
  exit
endif

# Verify the SHARC_ARCH is set and valid
#------------------------------------------
if (! $?SHARC_ARCH) then
  setenv SHARC_ARCH `$SHARC_HOME/bin/sharc_arch`
endif
echo "Using SHARC_ARCH = $SHARC_ARCH"


foreach mach ($machin)
  if($mach == $SHARC_ARCH) then
    goto input
  endif
end

echo ""
echo "SHARC_ARCH is invalid. Must be one of the following:"
foreach mach ($machin)
 echo " $mach"
end
exit


# Start Harpoon
#-----------------
input:

set count = 1
@ index_num = $count
@ index_count = $#argv

set foundx = 0
while ($index_num <= $index_count)
 if("$argv[$index_num]" == "-X") then
    set foundx = 1
 endif
 @ index_num++
end

if ($?DISPLAY) then
  echo "DISPLAY = "$DISPLAY
else
  echo "DISPLAY environment variable not set."
endif

echo "hostname = "`hostname`

set SHARC_LIB_DIR = ""
if ( -d "$SHARC_HOME"/harpoon/machines/$SHARC_ARCH/libCAD ) then
   set SHARC_LIB_DIR = "$SHARC_HOME"/harpoon/machines/$SHARC_ARCH/libCAD
endif
      if ($?LD_LIBRARY_PATH) then
         setenv LD_LIBRARY_PATH "${SHARC_LIB_DIR}":"${LD_LIBRARY_PATH}"
      else
         setenv LD_LIBRARY_PATH "${SHARC_LIB_DIR}"
      endif


if($foundx == 0) then
  echo ""
  echo "<Starting Harpoon>"
  $SHARC_HOME/$hpn_dir/machines/$SHARC_ARCH/harpoon $*
else
  echo "<Starting Harpoon with MESA Rendering>"
  echo ""
  set SHARC_X_DIR = ""
    if ( -d "$SHARC_HOME"/harpoon/machines/$SHARC_ARCH/libMesa ) then
       set SHARC_X_DIR = "$SHARC_HOME"/harpoon/machines/$SHARC_ARCH/libMesa
       setenv LD_LIBRARY_PATH "${SHARC_X_DIR}":"${LD_LIBRARY_PATH}"
       $SHARC_HOME/$hpn_dir/machines/$SHARC_ARCH/harpoon $*
    else
      echo "<You do not have MESA correctly installed on this machine>"
    endif
endif


