#!/bin/csh -f

set basever = `./xgcc -dumpversion`
set machine = `./xgcc -dumpmachine`
set outname = doinstall
set tmpout  = tmp-doinstall

rm -f $tmpout

clear
cat << EOF


  This script is provided to simplify the installation of the $machine
  binary version of the GNAT Ada 95 compiler which is now maintained by
  Ada Core Technologies. For information on commerical support please
  contact sales@gnat.com.

  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

set x = $<

clear
cat << EOF


  There are 2 options for installation:

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

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


  Options 2 provides simplest and most flexible use of GNAT.

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

# --------------------------- Option 2 selected -----------------------
install-std:
  clear
  set prefix = /usr/gnat
  set bindir = $prefix/bin
  set libsubdir = $prefix/lib/gcc-lib/$machine/$basever
  mv -f .gnat_wrapper .gnat_wrapper.old >& /dev/null
  if ( -d $libsubdir ) goto no-stdinstall
  cat << EOF
    The installation in the GCC standard locations will install:
      In $bindir :
          gcc gnatbind gnatbl gnatchop gnatfind gnatkr gnatls gnatlink gnatmake
          gnatmem gnatname gnatprep gnatpsta gnatxref gcov gdb gvd
          gnatelim gnatstub addr2line objdump

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

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

      In $libsubdir/adalib :
          The object & ali files of the RTL
          and libgnat.a
EOF
  echo make ins-all bindir=$prefix/bin >$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/$machine/$basever
  mv -f .gnat_wrapper.old .gnat_wrapper >& /dev/null
  cat << EOF

    The installation of GNAT will install:
      In $bindir :
          gcc gnatbind gnatbl gnatchop gnatfind gnatkr gnatls gnatlink gnatmake
          gnatmem gnatname gnatprep gnatpsta gnatxref gcov gdb gvd
          gnatelim gnatstub addr2line objdump

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

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

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

EOF
  echo make ins-all prefix=$prefix >$tmpout
  echo "echo Warning: this file is obsolete and does nothing." > env-vals
  cp env-vals env-vals.sh

  cat << EOF
    The files env-vals & env_vals.sh have been created for upward
    compatibility with previous GNAT versions, but they are *not* needed.

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

