  # Bourne Shell:
#   PRE-Gmake   
#
# Run "PRE-Gmake" before executing "Gmake".
# You must be the user "grass" to run "PRE-Gmake".
# (This "PRE-Gmake" script needs to be executed only once.)
# This script simply places the proper "distance.h" file to be used in 
# directory "distance".  It also copies the Gmakefile to be used in 
# directory "distance" as well.
#
if [ `whoami` = "grass" ]
then
  if [ -w `pwd` ]
  then
    if [ -x PRE-Gmake ] 
    then
      if [ -f Gmakefile ]
      then
        echo "You only need to execute \"PRE-Gmake\" once."
        exit 0 
      fi
      if [ -r /usr/include/oldcurses.h ]
      then
#       echo "\"oldcurses\" library selected."
#       echo "Variable \"CURSES\" should equal \"-loldcurses $(TERMLIB)\" when executing \"Gmake\"."
        cp oldcurses/distance.h .
        cp oldcurses/Gmakefile .
        echo "Ready to execute \"Gmake\" in directory \"distance\" now...  Be sure"
        echo "to read \"README\" file first though..."
      else
        if [ -r /usr/include/curses.h ]
        then
#         echo "\"curses\" library selected."
#         echo "Variable \"CURSES\" should equal \"-lcurses $(TERMLIB)\" when executing \"Gmake\"."
          cp curses/distance.h .
          cp curses/Gmakefile .
          echo "Ready to execute \"Gmake\" in directory \"distance\" now...  Be sure"
          echo "to read \"README\" file first though..."
        else
          echo "Your system does not have \"oldcurse.h\" or \"curses.h\" in directory \"/usr/include\" directory."
          echo "Your system should at the very least have \"curses.h\" in this directory."
          echo "Check with your system administrator for your system as to why you have this situation."
        fi
      fi
      if [ -d /usr/5bin ]
      then
        echo "$PATH" | fgrep -s '/usr/5bin'
        usr_5bin=$?
        echo "$PATH" | fgrep -s '/usr/bin'
        usr_bin=$?
        if [ usr_5bin -eq 0 ] || [ usr_bin -eq 1 ]
        then
          echo "Enter the command:"
          echo "                    setenv PATH /usr/bin:\$PATH"
          echo "before executing \"Gmake\"."
          echo "NOTE:  Directory \"/usr/bin\" must be before \"usr/5bin\" in the"
          echo "environmental variable \"PATH\" for \"d.distance\" to compile"
          echo "successfully."
        fi
      fi
    else
      echo "You must be located in the \"distance\" directory to run \"PRE-Gmake\"."
      echo "You must run \"PRE-Gmake\" before executing \"Gmake\" (only once)."
      exit 1
    fi
  else
    echo "You must have write permission for directory \"distance\" to run \"PRE-Gmake\"."
    echo "You must run \"PRE-Gmake\" before executing \"Gmake\" (only once)."
  fi
else
  echo "You must be the user \"grass\" to run \"PRE-Gmake\"."
  echo "You must run \"PRE-Gmake\" before executing \"Gmake\" (only once)."
fi
exit 0
