dnl Autoconf script for tcsh
dnl To rebuild the `configure' script from this, execute the command
dnl 	autoconf
dnl in the directory containing this script.
dnl
dnl You'll also need a version of config.guess from a gnu package
dnl
dnl Written by Kaveh Ghazi (ghazi@caip.rutgers.edu) 5/11/96.
dnl

AC_PREREQ(2.12)dnl Minimum Autoconf version required.
AC_INIT(tc.vers.c)

tcsh_configure_args="$@"
# Shift out arguments leaving the optional platform name.
while test -n "$1" ; do
 case "$1" in
  -*) shift ;;
  *) break ;;
 esac
done

AC_MSG_CHECKING(for the canonical name of this system)
if test "$1" = '' ; then
  PATH=$srcdir:$PATH # Prefer the tcsh source directory, it might be there.
  export PATH
  new_canonical=`(config.guess) 2>/dev/null` || new_canonical=unknown
else
  new_canonical="$1"
fi
AC_CACHE_VAL(tcsh_cv_canonical, tcsh_cv_canonical=${new_canonical})
AC_MSG_RESULT($tcsh_cv_canonical)

if test  "$tcsh_cv_canonical" != "$new_canonical"
then
  AC_MSG_WARN([Cache configured for \`${tcsh_cv_canonical}'.])
  AC_MSG_WARN([This system is \`${new_canonical}'.])
  AC_MSG_WARN([Assuming invalid cache - removing \`${cache_file}'.])
  AC_MSG_WARN([Restarting...])
  rm -f "$cache_file"
  exec ${CONFIG_SHELL-/bin/sh} $0 "$tcsh_configure_args"
fi

changequote(, )dnl

case "${tcsh_cv_canonical}" in

  ## Alpha (DEC) machines.
  alpha-dec-osf* )
    tcsh_config_file=decosf1
  ;;

  ## Ultrix
  *-dec-ultrix* )
    tcsh_config_file=ultrix
  ;;

  ## DGUX
  *-dg-dguxR4* )
    tcsh_config_file=dgux5.4
  ;;
  m88k-dg-dgux5.4R* )
    tcsh_config_file=dgux5.4
  ;;

  ## HP/UX
  *-hp-hpux7* )
    tcsh_config_file=hpux7
  ;;
  *-hp-hpux[89]* )
    tcsh_config_file=hpux8
  ;;
  *-hp-hpux10* )
    tcsh_config_file=hpux8
  ;;

  ## IBM AIX systems
  *-ibm-aix*)
    tcsh_config_file=aix
  ;;

  ## Linux
  *-*-linux* )
    tcsh_config_file=linux
  ;;

  ## Motorola systems
  m68k-motorola-sysv* )
    tcsh_config_file=sysV68
  ;;
  m88k-motorola-sysv3* )
    tcsh_config_file=sysV88
  ;;

  ## NetBSD systems
  *-*-netbsd*)
    tcsh_config_file=bsd4.4
  ;;

  ## FreeBSD systems
  *-*-freebsd*)
    tcsh_config_file=bsd4.4
  ;;

  ## OpenBSD systems
  *-*-openbsd*)
    tcsh_config_file=bsd4.4
  ;;

  ## BSDI systems
  *-*-bsdi*)
    tcsh_config_file=bsd4.4
  ;;

  ## Silicon Graphics machines
  *-sgi-iri* )
    tcsh_config_file=sgi
    NON_GNU_DFLAGS='-D__STDC__'
    case "${tcsh_cv_canonical}" in
      *-irix[34]*)
        LIBS='-lsun -lbsd -lc_s'
      ;;
    esac
  ;;

  ## Suns
  *-sun-sunos3* )
    tcsh_config_file=sunos35
  ;;
  *-sun-sunos4.0* )
    tcsh_config_file=sunos40
  ;;
  *-sun-sunos4.1.[12]* )
    tcsh_config_file=sunos41
  ;;
  *-sun-sunos4.1.[3456]* )
    tcsh_config_file=sunos413
  ;;
  *-*-solaris2.[01]* ) # Should handle sparc or x86
    tcsh_config_file=sol2
  ;;
  *-sun-solaris2.2* ) # Sparc only release
    tcsh_config_file=sol22
  ;;
  *-sun-solaris2.3* ) # Sparc only release
    tcsh_config_file=sol23
  ;;
  *-*-solaris2.[45]* ) # Should handle sparc, x86 and powerpc
    tcsh_config_file=sol24
  ;;
  *-*-solaris2.[678]* ) # Should handle sparc, x86 and powerpc
    tcsh_config_file=sol26
  ;;

  ## Dell SVR4
  *-dell-sysv4* )
    tcsh_config_file=sysv4
    DFLAGS="$DFLAGS -DDELL"
  ;;

  ## SVR4 (Generic and otherwise)
  *-*-sysv4* )
    tcsh_config_file=sysv4
  ;;

  ## Tektronix systems
  m68k-tektronix-bsd* )
    tcsh_config_file=bsd
    NON_GNU_DFLAGS='-DBSD -DUTek'
  ;;
  m88k-tektronix-sysv3* )
    tcsh_config_file=tekXD88
  ;;

  ## SCO
  *-sco3.2v5*) 
    tcsh_config_file=sco32v5
  ;;
  *-sco3.2v4*)
    tcsh_config_file=sco32v4
  ;;
  *-sco3.2v2*)
    tcsh_config_file=sco32v2
  ;;

  ## Siemens Nixdorf BS2000
  bs2000-sni-posix)
    tcsh_config_file=bs2000
  ;;
  ## Cray
  *-cray-unicos*)
    tcsh_config_file=cray
  ;;

  * )
  changequote([, ])dnl
  AC_MSG_ERROR([Tcsh can't guess the configuration file name
for \`${tcsh_cv_canonical}' systems.
Check tcsh's \`Ported' file for manual configuration instructions.])
  changequote(, )dnl
  ;;

esac

echo "Tcsh will use configuration file \`$tcsh_config_file'."
changequote([, ])dnl

AC_CONFIG_HEADER(config.h:config/${tcsh_config_file}:config.h.in)
AC_PROG_CC
AC_PROG_CPP
AC_PROG_GCC_TRADITIONAL

if test $ac_cv_prog_gcc = no ; then
  DFLAGS="$DFLAGS $NON_GNU_DFLAGS"
  CFLAGS="$CFLAGS $NON_GNU_CFLAGS"
fi

AC_CHECK_FUNC(crypt)
if test $ac_cv_func_crypt = no; then
  AC_CHECK_LIB(crypt, crypt)
fi
AC_CHECK_LIB(termlib, tgetent)
if test $ac_cv_lib_termlib_tgetent = no ; then
  AC_CHECK_LIB(curses, tgetent)
  if test $ac_cv_lib_curses_tgetent = no ; then
    AC_CHECK_LIB(termcap, tgetent)
  fi
fi
AC_CHECK_FUNC(gethostbyname)
if test $ac_cv_func_gethostbyname = no; then
      AC_CHECK_LIB(nsl, gethostbyname)
fi
AC_CHECK_FUNC(connect)
if test $ac_cv_func_connect = no; then
  AC_CHECK_LIB(socket, connect)
fi
AC_SUBST(DFLAGS)

AC_CHECK_FUNC(res_send, :, AC_CHECK_LIB(resolv, res_send, HES_RES_LIB=-lresolv))
AC_SUBST(HES_RES_LIB)
AC_SUBST(lbindir)

AC_OUTPUT(Makefile)
