#!/bin/csh -f

set basever = `cat GCC-BASE`
set outname = doinstall
set tmpout  = tmp-doinstall

rm -f $tmpout

clear
cat << EOF


  This script is provided to simplify the installation of the Sun sparc
  binary version of the GNU NYU Ada Translator (GNAT).

  This script asks a few questions about how you want GNAT configured
  and then creates a file in this directory which can then be invoked
  to do the actual installation.  Running this configuration script will
  not modify anything anywhere else in your system.  You can break
  out of it or run it multiple times before doing the actual installation.

  Hit RETURN to continue.
EOF

$< >/dev/null

clear
cat << EOF


  There are basically 3 options for installation:

  1) Install GNAT-specific files on top of an existing GCC $basever
     installation (must be in standard locations -- will likely
     require root permission).

  2) Install GCC C compiler and GNAT files in the standard  GCC locations.
     (Note: This includes directories under /usr/local.  On most
      systems, this requires root permission).

  3) Install GCC C compiler and GNAT files in non-standard locations
     that you will specify.


  Options 1 and 2 provide simplest and most flexible use of GNAT.
  Option 3 requires users to set some environment variables.

EOF
while (1)
  echo Type 1, 2, or 3 "(then RETURN)" to choose an option:
  set answer = $< 
  switch ($answer)
  case [1]:
    goto install-top
    breaksw
  case [2]:
    goto install-std
    breaksw
  case [3]:
    goto install-non
    breaksw
  endsw
end

# --------------------------- Option 1 selected -----------------------
install-top:
  clear
  set prefix = /usr/local
  set bindir = $prefix/bin
  set libsubdir = $prefix/lib/gcc-lib/sparc-sun-sunos4.1/$basever
  if ( ! -d $libsubdir)  goto no-gccinstall
  if ( ! -d $bindir)     goto no-gccinstall
  if ( ! -f $bindir/gcc) goto no-gccinstall
  cat << EOF
    The installation on top of GCC-$basever will install:
      In $bindir :
          gcc gnatbind gnatbl gnatf

      In $libsubdir :
          gnat1

      In $prefix/adainclude :
          The source files of the RTL

      In $libsubdir/adalib :
          The object files of the RTL, libgnat.a, and libpthreads.a
EOF
  echo make ins-gnatstuff >$tmpout
  goto fin

no-gccinstall:
  cat << EOF
  GCC-$basever not installed in standard locations.
  cannot do this type of installation
EOF
  rm -f $outname
  exit 1



# --------------------------- Option 2 selected -----------------------
install-std:
  clear
  set prefix = /usr/local
  set bindir = $prefix/bin
  set libsubdir = $prefix/lib/gcc-lib/sparc-sun-sunos4.1/$basever
  if ( -d $libsubdir ) goto no-stdinstall
  cat << EOF
    The installation in the GCC standard locations will install:
      In $bindir :
          gcc gnatbind gnatbl

      In $libsubdir :
          gnat1 cc1 cpp ld libgcc.a specs

      In $prefix/adainclude :
          The source files of the RTL

      In $libsubdir/adalib :
          The object files of the RTL, libgnat.a, and libpthreads.a
EOF
  echo make ins-all >$tmpout
  goto fin

no-stdinstall:
  cat << EOF
  Some GCC-$basever files were found.  They should be removed before
  using this option, or you should choose another option.
EOF
  rm -f $outname
  exit 1


# --------------------------- Option 3 selected -----------------------
install-non:
  clear
  cat << EOF


    To install GNAT is a non-standard location you need to specify a
    base directory.  All the files will be installed in subdirectories
    that are created under this directory.

    Specify the base directory you want to use for installation:

EOF
  set basedir = $<
  while (1)
    if ( X == X`echo $basedir|sed -n -e 's%^/.*%/%p'`) then
      set basedir = `pwd`/$basedir
    endif
    echo "    " The base directory is $basedir
    echo "    " To accept this choice enter RETURN.
    echo "    " Otherwise type a new name.
    set answer = $< 
    if ( X$answer == X ) break
    set basedir = $answer
  end
  clear
  set prefix = $basedir
  set bindir = $prefix/bin
  set libsubdir = $prefix/lib/gcc-lib/sparc-sun-sunos4.1/$basever
  cat << EOF

    The installation of GNAT will install:
      In $bindir :
          gcc gnatbind gnatbl

      In $libsubdir :
          gnat1 cc1 cpp ld libgcc.a specs

      In $prefix/adainclude :
          The source files of the RTL

      In $libsubdir/adalib :
          The object files of the RTL, libgnat.a, and libpthreads.a

EOF
  echo make ins-all prefix=$prefix >$tmpout

  cat << EOF >env-vals
setenv GCC_EXEC_PREFIX $libsubdir/
setenv ADA_INCLUDE_PATH $prefix/adainclude
setenv ADA_OBJECTS_PATH $libsubdir/adalib
setenv LIBRARY_PATH $libsubdir/adalib
setenv C_INCLUDE_PATH $libsubdir/include
EOF

  cat << EOF
    The file env-vals has been created.  It contains the csh commands
    to set the environment variables you need to use GNAT.  These
    commands (or their equivalent for the shell you use) should be
    placed in your .cshrc (or equivalent) file.

EOF


# -------  fin -------
fin:
  rm -f $outname
  mv $tmpout $outname
  chmod +x $outname
  echo    Configuration complete.  Run $outname to do the installation.
  echo    DO NOT FORGET: put $bindir at the front of your PATH
  echo ""
  exit
