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

AC_REVISION($Revision: 1.73 $)dnl
AC_INIT(server/server.c)
AC_PREREQ(2.13)
AM_CONFIG_HEADER(include/config.h)

dnl
dnl definitions
dnl

AC_PREFIX_DEFAULT(/usr/athena)

CFLAGS="-g ${CFLAGS}"

AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE(zephyr,rainbow-0.0spre1)

AC_SUBST(SUPPORT_LIBS)
AC_SUBST(ET_LDFLAGS)
AC_SUBST(ETDEP)
AC_SUBST(SS_LDFLAGS)
AC_SUBST(SSDEP)



INITPROGS=true

AC_SUBST(INITPROGS)

dnl Command-line option to disable Hesiod support
AC_ARG_WITH(hesiod,
	    [  --with-hesiod=PREFIX    Compile with Hesiod support],
	    [hesiod="$withval"], [hesiod=${hesiod-no}])

dnl Command-line option to disable Krb4 support
AC_ARG_WITH(krb4,
	    [  --with-krb4=PREFIX      Compile with Kerberos 4 support],
	    [krb4="$withval"], [krb4="auto"])

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CC_FLAGS
AM_PROG_LIBTOOL
AC_PROG_YACC
AM_PROG_LEX
AC_PROG_INSTALL
AM_PROG_LIBTOOL
AC_PROG_MAKE_SET
AC_PROG_LN_S
AC_PATH_PROG(PERL, perl, no)dnl
AC_SUBST(PERL)dnl

dnl these programs are usually bundled with kerberos

case "$krb4" in
no)
  ;;
auto)
  krb4_libexec=/usr/athena/libexec
  krb4_bin=/usr/athena/bin ;;
*)
  krb4_libexec=$krb4/libexec
  krb4_bin=$krb4/bin ;;
esac

AC_PATH_PROG(COMPILE_ET, compile_et, [../../lib/et/compile_et], $krb4_bin)
AC_PATH_PROG(MK_CMDS, mk_cmds, [../../lib/ss/mk_cmds], $krb4_bin)
AC_PATH_PROG(KRB_PUSH_PATH, push,$krb4_libexec,, $krb4_libexec)

AC_MSG_CHECKING(location of temporary directory)
if test -d /var/tmp; then
	found_tmp=/var/tmp/
elif test -d /usr/tmp; then
	found_tmp=/usr/tmp/
else
	found_tmp=/tmp/
fi
AC_DEFINE_UNQUOTED(FOUND_TMP, "${found_tmp}", [a temporary directory])
AC_MSG_RESULT(${found_tmp})

dnl Checks for header files.
AC_PATH_XTRA
AC_HEADER_STDC
AC_HEADER_SYS_WAIT

AC_CHECK_HEADERS([				\
	curses.h				\
	fcntl.h					\
	libgen.h				\
	malloc.h				\
	netdb.h					\
	net/if.h				\
	paths.h					\
	regex.h					\
	regexp.h				\
	sgtty.h					\
	sys/cdefs.h				\
	sys/file.h				\
	sys/filio.h				\
	sys/if.h				\
	sys/ioctl.h				\
	sys/msgbuf.h				\
	sys/select.h				\
	sys/sockio.h				\
	sys/time.h				\
	sys/uio.h				\
	sys/utsname.h				\
	term.h					\
	termcap.h				\
	termios.h				\
	errno.h					\
	unistd.h])

if test "$no_x" != "yes"; then
	XCLIENTS=xzwrite
	ZWGC_LIBX11=-lX11
	MKWITH_X_P=""
else
	MKWITH_X_P="#"
fi
AC_SUBST(XCLIENTS)
AC_SUBST(ZWGC_LIBX11)
AC_SUBST(MKWITH_X_P)

dnl Checks for typedefs, structures, and compiler characteristics.

AC_ROKEN(9,
	[/usr/heimdal /usr/athena /usr/arla],
	[$(top_builddir)/lib/roken/libroken.la],
	[-I$(top_srcdir)/lib/roken -I$(top_builddir)/lib/roken])

AC_TYPE_SIGNAL
AC_TYPE_UID_T
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_TYPE(ulong, unsigned long)
AC_MSG_CHECKING(for 32-bit integer type)
if test "$ac_cv_sizeof_long" = 4; then
	int32=long
elif test "$ac_cv_sizeof_int" = 4; then
	int32=int
elif test "$ac_cv_sizeof_short" = 4; then
	int32=short
else
	AC_WARN([Can't find 32-bit type, using long])
	int32=long
fi
AC_DEFINE_UNQUOTED(ZEPHYR_INT32, ${int32}, [a 32 bit long integer type])
AC_MSG_RESULT(${int32})

AC_CHECK_VAR([#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif],
h_errno)

# If we can't find connect, try looking in -lsocket and -lnsl.  The
# Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
# libsocket.so which has a bad implementation of gethostbyname (it
# only looks in /etc/hosts), so we only look for -lsocket if we need
# it.
AC_CHECK_FUNC(connect, :, [AC_CHECK_LIB(socket, socket)
			   AC_CHECK_LIB(nsl, gethostbyname)])

AC_CHECK_LIB(resolv, res_send)
AC_CHECK_LIB(resolv, dn_expand)
AC_CHECK_LIB(db, dbopen)

if test "$hesiod" != "no"; then
	if test "$hesiod" != "yes"; then
		CPPFLAGS="${CPPFLAGS} -I${hesiod}/include"
		LDFLAGS="${LDFLAGS} -L${hesiod}/lib"
	fi
	AC_DEFINE(HAVE_HESIOD, 1, [use hesiod])
	AC_FIND_FUNC(hes_resolve, hesiod)
	if test "$ac_cv_func_hes_resolve" != "yes"; then
	  AC_ERROR([Hesiod functions not found])
	fi
fi

save_CPPFLAGS="${CPPFLAGS}"
save_LDFLAGS="${LDFLAGS}"

if test "$krb4" != "no"; then
	if test "$krb4" = "auto"; then
		CPPFLAGS="${CPPFLAGS} -I/usr/athena/include"
		LDFLAGS="${LDFLAGS} -L/usr/athena/lib"
		KRB4_LDFLAGS="${KRB4_LDFLAGS} -L/usr/athena/lib -rpath /usr/athena/lib"
		krb_prefix=/usr/athena
	elif test "$krb4" != "yes"; then
		CPPFLAGS="${CPPFLAGS} -I${krb4}/include"
		LDFLAGS="${LDFLAGS} -L${krb4}/lib"
		KRB4_LDFLAGS="${KRB4_LDFLAGS} -L${krb4}/lib -rpath ${krb4}/lib"
		krb_prefix=${krb4}
	fi
	AC_CHECK_LIB(krb, krb_mk_req,
		[AC_DEFINE(HAVE_KRB4, 1, [use Kerberos 4])dnl
		 LIBS="-lkrb -ldes ${LIBS}"],
		[if test "$krb4" != "auto"; then
		 AC_MSG_ERROR(Kerberos4 library not found)dnl
		 else
	 	 AC_MSG_WARN(compiling without Kerberos support; Zephyr will be insecure.)
		 CPPFLAGS="${save_CPPFLAGS}"
		 LDFLAGS="${save_LDFLAGS}"
		 fi], -ldes)
else
	AC_MSG_WARN(compiling without Kerberos support; Zephyr will be insecure.)
fi

AC_FIND_FUNC_NO_LIBS(tgetent, curses termcap)
AC_FIND_FUNC_NO_LIBS(regcmp, gen)
AC_FIND_FUNC_NO_LIBS(srcsrpy, src)
AC_SUBST(LIB_tgetent)
AC_SUBST(LIB_regcmp)
AC_SUBST(LIB_srcsrpy)

AC_FIND_FUNC_NO_LIBS(com_err, com_err)

AC_FIND_FUNC_NO_LIBS2(readline, readline editline, [], [], [$LIB_tgetent $LIB_com_err], [])

AC_SUBST(LIB_readline)

AC_FIND_FUNC_NO_LIBS(ss_create_invocation, sl ss,[],[],
[$LIB_readline $LIB_tgetent $LIB_com_err])

if test "$ac_cv_func_ss_create_invocation" != "yes"; then
	WITH_LIBSS=ss
fi
AC_SUBST(WITH_LIBSS)

if test "$ac_cv_func_com_err" != "yes"; then
	WITH_LIBET=et
fi
AC_SUBST(WITH_LIBET)

dnl CMU_KRB4
dnl CMU_KRB_RD_REQ_PROTO
dnl CMU_KRB_SET_KEY_PROTO
dnl ATHENA_HESIOD
dnl ATHENA_REGEXP
dnl ATHENA_ARES
dnl ATHENA_UTIL_COM_ERR
dnl ATHENA_UTIL_SS
dnl LIBS="$KRB4_LIBS $HESIOD_LIBS $ARES_LIBS $LIBS $RPATH"

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_VPRINTF

AC_HAVE_STRUCT_FIELD(struct sockaddr, sa_len, [#include <sys/types.h>
#include <sys/socket.h>])

AC_SUBST(LIB_ss_create_invocation)
AC_SUBST(LIB_com_err)
AC_SUBST(KRB4_LDFLAGS)

AC_CHECK_FUNCS([				\
	gethostid				\
	getlogin				\
	getpgid					\
	getsid					\
	krb_get_err_text			\
	krb_get_lrealm				\
	krb_log					\
	krb_set_key				\
	lrand48					\
	memcpy					\
	memmove					\
	putenv					\
	random					\
	re_comp					\
	regcomp					\
	strchr					\
	strerror				\
	waitpid])
AC_FUNC_GETPGRP
AC_FUNC_SETPGRP


AC_ARG_ENABLE(server-cksum,
[  --disable-server-cksum   don't enforce checksums in the server],
[
if test "$enableval" = "no"; then
        AC_DEFINE(NO_SERVER_CKSUM,1)
fi
])

AC_ARG_ENABLE(cmu-hm-flush-restrict,
[  --enable-cmu-hm-flush-restrict   enable CMU zctl hm flush restriction],[
if test "$enableval" = "yes"; then
        AC_DEFINE(HM_FLUSH_RESTRICT,1)
fi
])

AC_ARG_ENABLE(cmu-opstaff-locate-self,
[  --enable-cmu-opstaff-locate-self enable CMU opstaff locate-self ability],[
if test "$enableval" = "yes"; then
        AC_DEFINE(OPSTAFF_LOCATE_SELF,1)
fi
])

if test "$DIR_roken" != ""; then
 AC_CONFIG_SUBDIRS(lib/roken)
fi

LDFLAGS="${save_LDFLAGS}"

AC_OUTPUT([					\
	Makefile				\
	etc/Makefile				\
	clients/Makefile			\
	clients/syslogd/Makefile		\
	clients/xzwrite/Makefile		\
	clients/zaway/Makefile			\
	clients/zctl/Makefile			\
	clients/zleave/Makefile			\
	clients/zlocate/Makefile		\
	clients/zmailnotify/Makefile		\
	clients/zmailnotify/zmailnotify		\
	clients/znol/Makefile			\
	clients/zpopnotify/Makefile		\
	clients/zshutdown_notify/Makefile	\
	clients/zstat/Makefile			\
	clients/zstart/Makefile 		\
	clients/zlogin/Makefile			\
	clients/zrefresh/Makefile		\
	clients/zwgc/Makefile			\
	clients/zwgc/zephyr.vars		\
	clients/zwrite/Makefile			\
	clients/zmail/Makefile			\
	clients/zrepeat/Makefile		\
	clients/zstop/Makefile			\
	include/Makefile			\
	include/ss/Makefile			\
	include/zephyr/Makefile			\
	lib/Makefile				\
	lib/dyn/Makefile			\
	lib/et/Makefile				\
	lib/ss/Makefile				\
	lib/zephyr/Makefile			\
	server/Makefile				\
	server/acl/Makefile			\
	zhm/Makefile				\
	])

AC_KRB_VERSION


