dnl Process this file with autoconf to produce a configure script.

AC_INIT(configure.in)
AM_INIT_AUTOMAKE(telnet98, 1.0.1)

test "$CFLAGS" = "" && CFLAGS="-O"

dnl Checks for programs.

AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_ARG_PROGRAM

dnl Checks for libraries.

AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(util, logout)
AC_CHECK_LIB(termlib, setupterm, LIBS="-ltermlib $LIBS", AC_DEFINE(TERMCAP) LIBS="-ltermcap $LIBS")

dnl Checks for header files.

AC_CHECK_HEADER(sys/filio.h, AC_DEFINE(FILIO_H))
AC_CHECK_HEADER(sys/stream.h, AC_DEFINE(STREAMS))
AC_CHECK_HEADER(string.h, AC_DEFINE(HAVE_STRING_H), AC_DEFINE(NO_STRING_H))
AC_CHECK_HEADER(bsdsetjmp.h, AC_DEFINE(HAVE_BSD_SETJMP), AC_DEFINE(NO_BSD_SETJMP))

dnl Checks for compiler characteristics.

AC_C_BIGENDIAN

dnl Checks for library functions.

AC_FUNC_VFORK
AC_REPLACE_FUNCS([strcasecmp setenv getent getopt strdup strcasecmp strftime strerror herror parsetos strchr strrchr])
AC_CHECK_FUNC(memmove, , LIBOBJS="$LIBOBJS mem.o")
AC_CHECK_FUNC(gettosbyname, AC_DEFINE(HAS_GETTOS))
AC_CHECK_FUNC(mktime, AC_DEFINE(HAVE_MKTIME), AC_DEFINE(NO_MKTIME))
AC_CHECK_FUNC(modutx, AC_DEFINE(UTMPX))

dnl User options.

AC_ARG_ENABLE(noencryption, [  --enable-noencryption		disable encryption], AC_DEFINE(NOENCRYPTION), AC_DEFINE(ENCRYPTION))
AC_ARG_WITH(inet6, [  --with-inet6		compile with IPv6 support])

if test "$with_inet6" = "yes"
then
	AC_DEFINE(INET6)
	CPPFLAGS="$CPPFLAGS -I/usr/inet6/include"
	LIBS="-L/usr/inet6/lib -linet6 $LIBS"
fi

dnl Authentication types.

AC_DEFINE(AUTHENTICATION)
AC_ARG_WITH(srp, [  --with-srp		compile with SRP support])
AC_ARG_WITH(krb4, [  --with-krb4		compile with kerberos4 support])
AC_ARG_WITH(krb5, [  --with-krb5		compile with kerberos5 support])
AC_ARG_WITH(spx, [  --with-spx		compile with SPX support])
AC_ARG_WITH(rsaencpwd, [  --with-rsaencpwd		compile with RSA_ENCPWD support])
AC_ARG_WITH(krb4encpwd, [  --with-krb4encpwd		compile with KRB4_ENCPWD support])

if test "$with_srp" != "no"
then
	AC_DEFINE(SRP)
	LIBS="-lsrp $LIBS"
fi

if test "$with_krb4" = "yes"
then
	AC_DEFINE(KRB4)
	LIBS="-lkrb $LIBS"
	CPPFLAGS="$CPPFLAGS -I/usr/include/kerberos"
	with_des=yes
fi

if test "$with_krb5" = "yes"
then
	AC_DEFINE(KRB5)
	LIBS="-lkrb5 $LIBS"
	CPPFLAGS="$CPPFLAGS -I/usr/include/kerberos5"
	with_des=yes
fi

if test "$with_spx" = "yes"
then
	AC_DEFINE(SPX)
fi

if test "$with_rsaencpwd" = "yes"
then
	AC_DEFINE(RSA_ENCPWD)
fi

if test "$with_krb4encpwd" = "yes"
then
	AC_DEFINE(KRB4_ENCPWD)
fi

dnl Encryption options.

AC_ARG_WITH(cast, [  --with-cast		compile with CAST5 (RFC 2144) encryption support ])
AC_ARG_WITH(des, [  --with-des		compile with DES encryption support ])

if test "$with_cast" != "no" -a "$enable_noencryption" != "yes"
then
	AC_DEFINE(CAST_ENCRYPTION)
fi

if test "$with_des" = "yes" -a "$enable_noencryption" != "yes"
then
	AC_DEFINE(DES_ENCRYPTION)
	LIBS="$LIBS -ldes"
fi

dnl Math library options.

AC_ARG_WITH(cryptolib, [  --with-cryptolib		compile to use cryptolib])
if test "$with_cryptolib" = "yes"
then
	LIBS="$LIBS -lcrypt"
else
	LIBS="$LIBS -lgmp"
fi

dnl Configurable options.

AC_DEFINE(ENV_HACK)
AC_DEFINE(OLD_ENVIRON)
AC_DEFINE(KLUDGELINEMODE)
AC_DEFINE(DIAGNOSTICS)
AC_DEFINE(TJW)

dnl Find host type and set parameters.

AC_CANONICAL_HOST

changequote(,)dnl
version_num=`expr "${host}" : '.*[^0-9.]\([0-9.]*\)$'`
changequote([,])dnl

case "${host}" in
  *bsdi*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\nBSDI BSD/OS ${version_num} (%h) (%t)\r\n\r\r\n\r")
    ;;
  *bsd*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\n${version_num}BSD UNIX (%h) (%t)\r\n\r\r\n\r")
    ;;
  *reno*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\n${version_num}BSD-Reno UNIX (%h) (%t)\r\n\r\r\n\r")
    ;;
  *tahoe*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\n${version_num}BSD-Tahoe UNIX (%h) (%t)\r\n\r\r\n\r")
    ;;
  *unicos*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\nCray UNICOS ${version_num} (%h) (%t)\r\n\r\r\n\r")
    ;;
  *sunos*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\nSunOS UNIX ${version_num} (%h) (%t)\r\n\r\r\n\r")
    ;;
  *solaris2*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\n\r\nUNIX(r) System V Release 4.0 (%h)\r\n\r\n")
    ;;
  *linux*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\n\r\nLinux(r) Release ${version_num} (%h)\r\n\r\n")
    ;;
  *dynix*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\nDYNIX(R) V${version_num} (%h) (%t)\r\n\r\r\n\r")
    ;;
  *ultrix*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\nULTRIX V${version_num} (%h) (%t)\r\n\r\r\n\r")
    ;;
  *irix*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\n\r\nIRIX System V.4 (%h) (%t)\r\n\r\r\n\r")
    ;;
  *osf*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\n\r\nOSF/1 (%h) (%t)\r\n\r\r\n\r")
    ;;
  *hpux*)
    AC_DEFINE_UNQUOTED(DEFAULT_IM, "\r\n\r\nHP-UX (%h) (%t)\r\n\r\r\n\r")
    ;;
esac

case "${host}" in
  *unicos*)
    AC_DEFINE(signal, bsdsignal)
    ;;
esac

case "${host}" in
  *solaris2*)
    AC_DEFINE(SOLARIS)
    ;;
  *irix*)
    AC_DEFINE(IRIX)
    ;;
  *linux*)
    AC_DEFINE(LINUX)
    ;;
  *osf*)
    AC_DEFINE(OSF)
    ;;
esac

case "${host}" in
  *bsd* | *unicos* | *reno* | *tahoe*)
    AC_DEFINE(LINEMODE)
    ;;
esac

case "${host}" in
  *unicos*)
    AC_DEFINE(SYSV_TERMIO)
    ;;
esac

case "${host}" in
  *unicos6*)
    AC_DEFINE(NEWINIT)
    ;;
esac

case "${host}" in
  *bsd* | *reno* | *unicos6* | *sunos4* | *solaris2* | *linux* | *ultrix* | *irix* | *osf* | *hpux*)
    AC_DEFINE(USE_TERMIO)
    ;;
esac

case "${host}" in
  *sunos3*)
    AC_DEFINE(HAVE_fd_set)
    ;;
esac

case "${host}" in
  *solaris2* | *irix*)
    AC_DEFINE(STREAMSPTY)
    ;;
esac

AC_ARG_ENABLE(loginf, [  --enable-loginf		use if /bin/login supports -f])

case "${host}" in
  *sunos4* | *solaris2.[234]* | *ultrix4.3* | irix[5-9]*)
    if test "$enable_loginf" != "yes"
    then
      AC_DEFINE(NO_LOGIN_F)
      AC_DEFINE(LOGIN_R)
    fi;;
  *bsd* | *reno* | *tahoe* | *solaris2* | *linux* | *hpux* | *dynix* | *osf* | *next*)
    if test "$enable_loginf" = "no"
    then
      AC_DEFINE(NO_LOGIN_F)
      AC_DEFINE(LOGIN_R)
    fi;;
  *unicos[7-9]*)
    if test "$enable_loginf" = "no"
    then
      AC_DEFINE(NO_LOGIN_F)
    fi;;
  *)
    if test "$enable_loginf" != "yes"
    then
      AC_DEFINE(NO_LOGIN_F)
    fi
esac

case "${host}" in
  *unicos6* | *hpux* | *solaris2.[234]*)
    AC_DEFINE(NO_LOGIN_P)
    AC_DEFINE(LOGIN_ARGS)
    ;;
  *bsd* | *reno* | *tahoe* | *unicos[7-9]* | *sunos4* | *solaris2* | *linux* | *dynix* | *osf* | *next* | *convex*)
    ;;
  *)
    AC_DEFINE(NO_LOGIN_P)
esac

dnl Generate Makefiles.

AC_OUTPUT(Makefile arpa/Makefile libtelnet/Makefile telnet/Makefile telnetd/Makefile)
