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.13)dnl Minimum Autoconf version required.
AC_INIT(tc.vers.c)

AC_CANONICAL_HOST

dnl We don't use AC_VALIDATE_CACHED_SYSTEM_TUPLE here because we only
dnl care about the HOST value, not the HOST/BUILD/TARGET triplet.
AC_MSG_CHECKING([cached host tuple])
if { test x"${ac_cv_host_system_type+set}" = x"set" &&
     test x"$ac_cv_host_system_type" != x"$host"; }; then
  AC_MSG_RESULT([different])
  AC_MSG_ERROR([remove config.cache and re-run configure])
else
  AC_MSG_RESULT(ok)
fi
ac_cv_host_system_type="$host"


changequote(, )dnl

case "${host}" 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-hpux1[0-9]* )
    tcsh_config_file=hpux8
  ;;

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

  ## SX-4
  sx4-nec-*)
    CC='cc -h0,ansi,novector,float0'
    LDFLAGS='-Gsmall'
    tcsh_config_file=superux8
  ;;

  ## 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
  ;;

  ## Mac OS X Server
  *-*-rhapsody* )
    tcsh_config_file=bsd4.4
  ;;

  ## Mac OS X Server
  *-*-darwin* )
    tcsh_config_file=bsd4.4
  ;;

  ## Silicon Graphics machines
  *-sgi-iri* )
    tcsh_config_file=irix
    case "${host_os}" in
      irix[34]*) # Irix-3.x - Irix 4.x
        NON_GNU_DFLAGS='-D__STDC__'
        LIBS='-lsun -lbsd -lc_s'
      ;;
      irix5* | irix6.[01]*) # Irix 5.x, Irix 6.0 - 6.1
        LIBS='-lbsd'
      ;;
      irix6.[2-9]*) # Irix 6.2 and later
	tcsh_config_file=irix62
      ;;
    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.7 ) # Should handle sparc, x86 and powerpc
    tcsh_config_file=sol26
    CFLAGS=-xarch=v9
  ;;
  *-*-solaris2.* ) # 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 BS2000 Mainframe
  bs2000-siemens-posix)
    tcsh_config_file=bs2000
  ;;

  ## Convex
  *-convex*)
    tcsh_config_file=convex
  ;;

  ## Cray
  *-cray-unicos*)
    tcsh_config_file=cray
  ;;

  ## Cygnus GNU Win32
  *-cygwin)
    tcsh_config_file=cygwin32
  ;;

  * )
  changequote([, ])dnl
  AC_MSG_ERROR([Tcsh can't guess the configuration file name
for \`${host}' 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_SEARCH_LIBS(crypt, crypt)
AC_SEARCH_LIBS(tgetent, termlib ncurses curses termcap)
AC_SEARCH_LIBS(gethostbyname, nsl)
AC_SEARCH_LIBS(connect, socket)

AC_SUBST(DFLAGS)

AC_ARG_WITH(hesiod,
  [  --with-hesiod=PREFIX    Use Hesiod lookup for ~ expansion],
  [hesiod="$withval"], [hesiod=no])
if test "$hesiod" != no; then
  HESLIB="-lhesiod"
  AC_CHECK_FUNC(res_send, :,
    AC_CHECK_LIB(resolv, res_send, HESLIB="$HESLIB -lresolv"))
  HESDEF=-DHESIOD
  if test "$hesiod" != yes; then
    HESDEF="$HESDEF -I$hesiod/include"
    HESLIB="-L$hesiod/lib $HESLIB"
  fi
fi
AC_SUBST(HESDEF)
AC_SUBST(HESLIB)

AC_ARG_WITH(grd,
            [  --with-grd=ARCH         SGE/SGEEE ARCH (LINUX5/LINUX6...)],
            [grd="$withval"], [grd=no])
if test "$grd" != no; then
   GRDDEF="-I../../../libs/gdi"
   GRDLIB="-L../../../$grd \$(SGE_LIBS) ${LDFLAGS}"
   CFLAGS="$CFLAGS -DPROG_NAME='\"qtcsh\"' -D$grd"
fi
AC_SUBST(GRDDEF)
AC_SUBST(GRDLIB)
AC_SUBST(PROG_NAME)


AC_OUTPUT(Makefile)
