dnl
dnl *** PLEASE NOTE ***
dnl *** PLEASE NOTE ***
dnl *** PLEASE NOTE ***
dnl
dnl Update $VERSION before making a new release
dnl

dnl Process this file with autoconf to produce a configure script.
dnl
AC_REVISION($Revision: 1.2 $)
AC_PREREQ(2.53)
AC_INIT(KTH-KRB, 1.2, kth-krb-bugs@pdc.kth.se, krb4)
AC_CONFIG_SRCDIR([kuser/kinit.c])
AM_CONFIG_HEADER(include/config.h)

AM_INIT_AUTOMAKE

dnl
dnl definitions
dnl

# This may be overridden using --prefix=/usr to configure
AC_PREFIX_DEFAULT(/usr/athena)

sysconfdir='/etc'

AC_CANONICAL_HOST
CANONICAL_HOST=$host
AC_SUBST(CANONICAL_HOST)

dnl
dnl this is needed to run the configure tests against glibc
dnl
AC_DEFINE([_GNU_SOURCE], 1,
	[Define to enable extensions on glibc-based systems such as Linux.])


AC_PROG_MAKE_SET

# We want these before the checks, so the checks can modify their values.
test -z "$LDFLAGS" && LDFLAGS=-g

dnl
dnl check for programs
dnl

AC_DEFINE(KRB4, 1, [This is Kerberos 4 after all.])dnl
AM_CONDITIONAL(KRB4, true)
AM_CONDITIONAL(KRB5, false)
AM_CONDITIONAL(DCE, false)
AM_CONDITIONAL(do_roken_rename, true)

dnl various compat defines
AH_BOTTOM([#define KRB_PUT_INT(f, t, l, s) krb_put_int((f), (t), (l), (s))])dnl
AC_DEFINE(HAVE_KRB_ENABLE_DEBUG, 1, [We do.])
AC_DEFINE(HAVE_KRB_DISABLE_DEBUG, 1, [We do.])
AC_DEFINE(HAVE_KRB_GET_OUR_IP_FOR_REALM, 1, [We do.])
AC_DEFINE([ORGANIZATION], "eBones International",
	[This is the organization printed by kinit.])

AC_KRB_PROG_LN_S
AC_PROG_CC
AC_ISC_POSIX
AC_PROG_CPP
AC_PROG_CC_STDC
AC_PROG_YACC
dnl AC_KRB_PROG_YACC
AM_PROG_LEX
AC_PROG_INSTALL
AC_PROG_AWK
AC_CHECK_PROG(MAKEINFO, makeinfo, makeinfo, :)

AM_DISABLE_SHARED
AC_PROG_LIBTOOL

dnl Use make WFLAGS=".."
dnl AC_WFLAGS(-Wall -Wmissing-prototypes -Wpointer-arith -Wbad-function-cast -Wmissing-declarations -Wnested-externs)
WFLAGS=""
WFLAGS_NOUNUSED=""
WFLAGS_NOIMPLICITINT=""
AC_SUBST(WFLAGS) dnl
AC_SUBST(WFLAGS_NOUNUSED) dnl
AC_SUBST(WFLAGS_NOIMPLICITINT) dnl

dnl
dnl check for build options
dnl

INCLUDE_krb4='$(INCLUDE_des)'
LIB_krb4='$(top_builddir)/lib/krb/libkrb.la'
AC_SUBST(INCLUDE_krb4)
AC_SUBST(LIB_krb4)

rk_ROKEN(lib/roken)
LIB_roken="\$(top_builddir)/lib/vers/libvers.la $LIB_roken"

rk_TEST_PACKAGE(socks,[#include <socks.h>],-lsocks5,,, SOCKS)
CFLAGS="$INCLUDE_socks $CFLAGS"
LIBS="$LIB_socks $LIBS"

AC_ARG_ENABLE(legacy-kdestroy,
	AC_HELP_STRING([--enable-legacy-kdestroy],[kdestroy doesn't destroy tokens by default]))
if test "$enable_legacy_kdestroy" = "yes"; then
	AC_DEFINE([LEGACY_KDESTROY], 1, [Define to enable old kdestroy behavior.])
fi

AC_ARG_ENABLE(match-subdomains,
	AC_HELP_STRING([--enable-match-subdomains],[match realm in subdomains]))
if test "$enable_match_subdomains" = "yes"; then
	AC_DEFINE([MATCH_SUBDOMAINS], 1, [Define if you want to match subdomains.])
fi

AC_ARG_WITH(ld-flags,
	AC_HELP_STRING([--with-ld-flags=flags],[what flags use when linking]))

AC_ARG_WITH(cracklib,
	AC_HELP_STRING([--with-cracklib=dir],[use the cracklib.a in dir]))

AC_ARG_WITH(dictpath,
	AC_HELP_STRING([--with-dictpath=path],[use this dictionary with cracklib]))

(test -z "$with_cracklib" && test -n "$with_dictpath") ||
(test -n "$with_cracklib" && test -z "$with_dictpath") &&
AC_MSG_ERROR(--with-cracklib requires --with-dictpath and vice versa)
if test -n "$with_cracklib"; then
	CRACKLIB="-L$with_cracklib -lcrack"
	AC_MSG_RESULT(Using cracklib in $with_cracklib)
	AC_SUBST(CRACKLIB)dnl
fi
if test -n "$with_dictpath"; then
	AC_MSG_RESULT(Using dictpath=$with_dictpath)
	AC_DEFINE_UNQUOTED(DICTPATH,"$with_dictpath", [Define this to be the directory where the 
	dictionary for cracklib resides.])
fi

AC_ARG_WITH(mailspool,
	AC_HELP_STRING([--with-mailspool=dir],[this is the mail spool directory]))
if test -n "$with_mailspool"; then
	AC_DEFINE_UNQUOTED([KRB4_MAILDIR], "$with_mailspool",
		[Define this to the path of the mail spool directory.])
fi

AC_ARG_WITH([db-dir],
	AC_HELP_STRING([--with-db-dir=dir],[this is the database directory (default /var/kerberos)]))
if test -n "$with_db_dir"; then
	AC_DEFINE_UNQUOTED([DB_DIR], "$with_db_dir", 
		[Define this to the kerberos database directory.])
fi

AC_ARG_ENABLE(random-mkey,
	AC_HELP_STRING([--enable-random-mkey],[use new code for master keys]))
if test "enable_random_mkey" = "yes"; then
	AC_DEFINE([RANDOM_MKEY], 1, [Define to enable new master key code.])
fi

AC_ARG_WITH(mkey,
	AC_HELP_STRING([--with-mkey=file],[where to put the master key]))
if test -n "$with_mkey"; then
	AC_DEFINE_UNQUOTED(MKEYFILE,"$with_mkey",
		[Define this to the location of the master key.])
fi

rk_OTP

AC_CHECK_OSFC2

AC_ARG_ENABLE(mmap,
	AC_HELP_STRING([--disable-mmap],[disable use of mmap]))
if test "$enable_mmap" = "no"; then
	AC_DEFINE(NO_MMAP, 1, [Define if you don't want to use mmap.])
fi

AC_ARG_ENABLE([afs-support],
	AC_HELP_STRING([--disable-afs-support],
		[if you don't want support for AFS]))

if test "$enabls_afs_support" = no; then
	AC_DEFINE(NO_AFS, 1, [Define if you don't wan't support for AFS.])
fi

AC_ARG_WITH(des-quad-checksum,
	AC_HELP_STRING([--with-des-quad-checksum=kind],
                           [default checksum to use (new, old, or guess)]))
case "$with_des_quad_checksum" in
	new)
		ac_x=DES_QUAD_NEW;;
	old)
		ac_x=DES_QUAD_OLD;;
	*)
		ac_x=DES_QUAD_GUESS;;
esac
AC_DEFINE_UNQUOTED(DES_QUAD_DEFAULT,$ac_x, 
	[Set this to the type of des-quad-cheksum to use.])
AH_BOTTOM([
/* Temporary fixes for krb_{rd,mk}_safe */
#define DES_QUAD_GUESS  0
#define DES_QUAD_NEW    1
#define DES_QUAD_OLD    2
])

AC_ARG_WITH(afsws,
	AC_HELP_STRING([--with-afsws=dir],[use AFS includes and libraries from dir=/usr/afsws]))
case "$with_afsws" in
/*)	AFSWS="$with_afsws";;
*)	AFSWS="/usr/afsws";;
esac
AC_SUBST(AFSWS)dnl

AC_ARG_ENABLE(rxkad,
	AC_HELP_STRING([--enable-rxkad],[build rxkad library]))

if test "$enable_afs_support" != no -a "$enable_rxkad" = yes; then
	LIB_SUBDIRS="$LIB_SUBDIRS rxkad"
fi
AC_SUBST(LIB_SUBDIRS)dnl

dnl AC_ARG_ENABLE(cat-manpages,
dnl 	AC_HELP_STRING([--disable-cat-manpages],[don't install any preformatted manpages]))

AC_FIND_FUNC_NO_LIBS(tgetent, termcap ncurses curses)


AC_MIPS_ABI

dnl
dnl Check for endian-ness, this breaks cross compilation
dnl
AC_C_BIGENDIAN

dnl
dnl Check for constness
dnl
AC_C_CONST

dnl
dnl Check for inline keyword
dnl
AC_C_INLINE

dnl
dnl Check for __attribute__
dnl
AC_C___ATTRIBUTE__

dnl
dnl Check for strange operating systems that you need to handle differently
dnl

rk_AIX
rk_IRIX
rk_SUNOS
rk_SYS_NEXTSTEP

dnl some OS/2 stuff.  From <d96-mst@nada.kth.se>
AH_BOTTOM([
#ifdef __EMX__
#define _EMX_TCPIP
#define MAIL_USE_SYSTEM_LOCK
#endif])

dnl
dnl Various checks for headers and their contents
dnl

AC_HEADER_STDC

AC_CHECK_HEADERS([arpa/ftp.h			\
	arpa/inet.h				\
	arpa/nameser.h				\
	arpa/telnet.h				\
	bsd/bsd.h				\
	bsdsetjmp.h				\
	capability.h				\
	crypt.h					\
	curses.h				\
	dirent.h				\
	err.h					\
	errno.h					\
	fcntl.h					\
	fnmatch.h				\
	grp.h					\
	inttypes.h				\
	io.h					\
	lastlog.h				\
	libutil.h				\
	limits.h				\
	login.h					\
	maillock.h				\
	net/if.h				\
	net/if_tun.h				\
	net/if_var.h				\
	netdb.h					\
	netinet/in.h				\
	netinet/in6.h				\
	netinet/in6_machtypes.h			\
	netinet/in_systm.h			\
	paths.h					\
	pty.h					\
	pwd.h					\
	resolv.h				\
	rpcsvc/ypclnt.h				\
	sac.h					\
	security/pam_modules.h			\
	shadow.h				\
	siad.h					\
	signal.h				\
	stropts.h				\
	sys/bitypes.h				\
	sys/category.h				\
	sys/file.h				\
	sys/filio.h				\
	sys/ioccom.h				\
	sys/ioctl.h				\
	sys/locking.h				\
	sys/mman.h				\
	sys/param.h				\
	sys/poll.h				\
	sys/proc.h				\
	sys/pty.h				\
	sys/ptyio.h				\
	sys/ptyvar.h				\
	sys/resource.h				\
	sys/select.h				\
	sys/socket.h				\
	sys/sockio.h				\
	sys/stat.h				\
	sys/str_tty.h				\
	sys/stream.h				\
	sys/stropts.h				\
	sys/strtty.h				\
	sys/syscall.h				\
	sys/sysctl.h				\
	sys/termio.h				\
	sys/time.h				\
	sys/timeb.h				\
	sys/times.h				\
	sys/tty.h				\
	sys/types.h				\
	sys/uio.h				\
	sys/un.h				\
	sys/utsname.h				\
	sys/wait.h				\
	syslog.h				\
	term.h					\
	termcap.h				\
	termio.h				\
	termios.h				\
	tmpdir.h				\
	ttyent.h				\
	udb.h					\
	ulimit.h				\
	unistd.h				\
	userpw.h				\
	userconf.h				\
	usersec.h				\
	util.h					\
	utime.h					\
	utmp.h					\
	utmpx.h					\
	wait.h])

AC_HEADER_TIME
AC_DECL_SYS_SIGLIST

CHECK_NETINET_IP_AND_TCP

AM_CONDITIONAL(have_err_h, test "$ac_cv_header_err_h" = yes)
AM_CONDITIONAL(have_fnmatch_h, test "$ac_cv_header_fnmatch_h" = yes)

EXTRA_LOCL_HEADERS=
EXTRA_HEADERS=
if test "$ac_cv_header_err_h" != yes; then
	EXTRA_HEADERS="$EXTRA_HEADERS err.h"
fi
if test "$ac_cv_header_fnmatch_h" != yes; then
	EXTRA_LOCL_HEADERS="$EXTRA_LOCL_HEADERS fnmatch.h"
fi
##AC_SUBST(EXTRA_HEADERS)
##AC_SUBST(EXTRA_LOCL_HEADERS)

AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, 
	u_int8_t, u_int16_t, u_int32_t, u_int64_t,
	uint8_t, uint16_t, uint32_t, uint64_t],,,[
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_BITYPES_H
#include <sys/bitypes.h>
#endif
#ifdef HAVE_BIND_BITYPES_H
#include <bind/bitypes.h>
#endif
#ifdef HAVE_NETINET_IN6_MACHTYPES_H
#include <netinet/in6_machtypes.h>
#endif
])

AC_MSG_CHECKING(for strange sys/bitypes.h)
AC_CACHE_VAL(krb_cv_int8_t_ifdef, [
AC_TRY_COMPILE([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_BITYPES_H
#include <sys/bitypes.h>
#endif
#ifdef HAVE_NETINET_IN6_MACHTYPES_H
#include <netinet/in6_machtypes.h>
#endif
],
int8_t x;
,
krb_cv_int8_t_ifdef=no,
krb_cv_int8_t_ifdef=yes)])
AC_MSG_RESULT($krb_cv_int8_t_ifdef)
if test "$krb_cv_int8_t_ifdef" = "yes"; then
  AC_DEFINE(HAVE_STRANGE_INT8_T, 1, [Huh?])dnl
fi

dnl
dnl Various checks for libraries and their contents
dnl

AC_FIND_FUNC_NO_LIBS(crypt, crypt)dnl

dnl this is a hack for KRB_CRYPTO
with_krb4=no
KRB_CRYPTO

if test "$DIR_des"; then
  DES_H='des.h'
else
  DES_H='openssl/des.h'
fi
AC_SUBST(DES_H)

if ! test "$DIR_des"; then
	save_CFLAGS="$CFLAGS"
	CFLAGS="$INCLUDE_des $save_CFLAGS"
	save_LIBS="$LIBS"
	LIBS="$LIB_des $save_LIBS"
	AC_CACHE_CHECK([if des_quad_cksum is broken],
			[rk_cv_func_des_quad_cksum_broken],[
	rk_cv_func_des_quad_cksum_broken=no
	AC_TRY_RUN([
#include <string.h>
#ifdef HAVE_OPENSSL
#include <openssl/des.h>
#else
#include <des.h>
#endif
int main(int argc, char **argv)
{
    char buf[] = "this is a test";
    des_cblock key = { 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78 };
    unsigned char correct[] = { 
	0x62, 0x61, 0x7b, 0x28, 0x67, 0x51, 0x3f, 0x0a,
	0x42, 0x66, 0xfc, 0x58, 0x99, 0xee, 0xe9, 0x2f };
    unsigned char c[32];
    des_set_odd_parity(&key);
    des_quad_cksum(buf, c, strlen(buf), 2, &key);
    return memcmp(c, correct, sizeof(correct));
}
],:,rk_cv_func_des_quad_cksum_broken=yes,:)
	])
	CFLAGS="$save_CFLAGS"
	LIBS="$save_LIBS"
fi
AM_CONDITIONAL(DES_QUAD_CKSUM_BROKEN, test "$rk_cv_func_des_quad_cksum_broken" = yes)


dnl
dnl Horror AIX needs -lodm -lcfg to link login
dnl

AC_FIND_FUNC_NO_LIBS(odm_initialize, odm)
AC_FIND_FUNC_NO_LIBS(getattr, cfg)
AC_FIND_FUNC_NO_LIBS(setpcred, s)
AC_FIND_FUNC_NO_LIBS(logwtmp, util)
AC_FIND_FUNC_NO_LIBS(openpty, util)
AC_FIND_FUNC_NO_LIBS(logout, util)
	
dnl 
dnl See if there is any X11 present
dnl
KRB_CHECK_X

AM_CONDITIONAL(HAVE_X, test "$no_x" != yes)

AC_CHECK_XAU

rk_TEST_PACKAGE(hesiod,[#include <hesiod.h>],-lhesiod,,, HESIOD)

dnl
dnl Look for berkeley db, gdbm, and ndbm in that order.
dnl

AC_CHECK_FUNCS([				\
	_getpty					\
	_scrsize				\
	_setsid					\
	_stricmp				\
	arc4random				\
	atexit					\
	chroot					\
	fattach					\
	fchmod					\
	fcntl					\
	forkpty					\
	frevoke					\
	getpriority				\
	getservbyname				\
	gettosbyname				\
	grantpt					\
	mktime					\
	on_exit					\
	parsetos				\
	poll					\
	ptsname					\
	rand					\
	random					\
	revoke					\
	setitimer				\
	setpgid					\
	setpriority				\
	setproctitle				\
	setregid				\
	setresgid				\
	setresuid				\
	setreuid				\
	setsid					\
	setutent				\
	sigaction				\
	srandomdev				\
	ttyname					\
	ttyslot					\
	ulimit					\
	unlockpt				\
	vhangup					\
	yp_get_default_domain			\
	])

KRB_CAPABILITIES

AC_CHECK_GETPWNAM_R_POSIX

AC_FIND_FUNC_NO_LIBS(getsockopt,,
[#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif],
[0,0,0,0,0])
AC_FIND_FUNC_NO_LIBS(setsockopt,,
[#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif],
[0,0,0,0,0])

dnl Cray stuff
AC_CHECK_FUNCS(getudbnam setlim)

AC_FUNC_MMAP
AC_FUNC_ALLOCA

CHECK_COMPILE_ET

rk_AUTH_MODULES

dnl
dnl Checks for prototypes and declarations
dnl

AC_PROTO_COMPAT([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
],
gethostbyname, struct hostent *gethostbyname(const char *))

AC_PROTO_COMPAT([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
],
gethostbyaddr, struct hostent *gethostbyaddr(const void *, size_t, int))

AC_PROTO_COMPAT([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
],
getservbyname, struct servent *getservbyname(const char *, const char *))

AC_PROTO_COMPAT([
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
],
openlog, void openlog(const char *, int, int))

AC_NEED_PROTO([
#ifdef HAVE_CRYPT_H
#include <crypt.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
],
crypt)

AC_NEED_PROTO([
#include <stdio.h>
],
fclose)

AC_NEED_PROTO([
#include <string.h>
],
strtok_r)

AC_NEED_PROTO([
#include <string.h>
],
strsep)

AC_NEED_PROTO([
#include <unistd.h>
],
getusershell)

AC_NEED_PROTO([
#ifdef HAVE_UTIME_H
#include <utime.h>
#endif
],
utime)

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

rk_CHECK_VAR(h_errlist, [#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif])

rk_CHECK_VAR(h_nerr, [#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif])

rk_CHECK_VAR(__progname, [#ifdef HAVE_ERR_H
#include <err.h>
#endif])

AC_CHECK_DECLARATION([#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif], optarg)
AC_CHECK_DECLARATION([#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif], optind)
AC_CHECK_DECLARATION([#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif], opterr)
AC_CHECK_DECLARATION([#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif], optopt)

AC_CHECK_DECLARATION([#include <stdlib.h>], environ)

dnl
dnl According to ANSI you are explicitly allowed to cast to void,
dnl but the standard fails to say what should happen. Some compilers
dnl think this is illegal:
dnl
dnl void foo(void)
dnl {
dnl   return (void)0;
dnl }
dnl
dnl Thus explicitly test for void
dnl
AC_TYPE_SIGNAL
if test "$ac_cv_type_signal" = "void" ; then
	AC_DEFINE(VOID_RETSIGTYPE, 1, [Define if RETSIGTYPE == void.])
fi

dnl
dnl Check for fields in struct utmp
dnl

AC_HAVE_STRUCT_FIELD(struct utmp, ut_addr,
[#include <sys/types.h>
 #include <utmp.h>])
AC_HAVE_STRUCT_FIELD(struct utmp, ut_host,
[#include <sys/types.h>
 #include <utmp.h>])
AC_HAVE_STRUCT_FIELD(struct utmp, ut_id,
[#include <sys/types.h>
 #include <utmp.h>])
AC_HAVE_STRUCT_FIELD(struct utmp, ut_pid,
[#include <sys/types.h>
 #include <utmp.h>])
AC_HAVE_STRUCT_FIELD(struct utmp, ut_type,
[#include <sys/types.h>
 #include <utmp.h>])
AC_HAVE_STRUCT_FIELD(struct utmp, ut_user,
[#include <sys/types.h>
 #include <utmp.h>])
AC_HAVE_STRUCT_FIELD(struct utmpx, ut_exit,
[#include <sys/types.h>
 #include <utmp.h>])
AC_HAVE_STRUCT_FIELD(struct utmpx, ut_syslen,
[#include <sys/types.h>
 #include <utmp.h>])

dnl
dnl Check for fields in struct tm
dnl

AC_HAVE_STRUCT_FIELD(struct tm, tm_gmtoff, [#include <time.h>])
AC_HAVE_STRUCT_FIELD(struct tm, tm_zone, [#include <time.h>])

dnl
dnl or do we have a variable `timezone' ?
dnl

rk_CHECK_VAR(timezone,
[#include <time.h>])

AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])

AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])

AC_HAVE_TYPE([struct sockaddr_storage], [#include <sys/socket.h>])

AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])

AC_KRB_STRUCT_SPWD

AC_CHECK_MEMBERS(struct stat.st_blksize)

dnl
dnl Check for struct winsize
dnl

AC_KRB_STRUCT_WINSIZE

dnl
dnl Check for some common types
dnl

AC_TYPE_PID_T
AC_TYPE_UID_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T

AC_CHECK_TYPE_EXTRA(ssize_t, int, [
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif])

AC_CHECK_TYPE_EXTRA(sig_atomic_t, int, [#include <signal.h>])

dnl
dnl Check for broken ultrix sys/socket.h
dnl

AC_MSG_CHECKING(for broken sys/socket.h)
AC_CACHE_VAL(krb_cv_header_sys_socket_h_broken, [
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socket.h>],[],
krb_cv_header_sys_socket_h_broken=no,
krb_cv_header_sys_socket_h_broken=yes)])
AC_MSG_RESULT($krb_cv_header_sys_socket_h_broken)
AM_CONDITIONAL(BROKEN_SOCKET_H, test $krb_cv_header_sys_socket_h_broken = yes)

dnl
dnl Check for broken ultrix netdb.h
dnl

AC_MSG_CHECKING(for broken netdb.h)
AC_CACHE_VAL(krb_cv_header_netdb_h_broken, [
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <netdb.h>
#include <netdb.h>],[],
krb_cv_header_netdb_h_broken=no,
krb_cv_header_netdb_h_broken=yes)])
AC_MSG_RESULT($krb_cv_header_netdb_h_broken)
AC_SUBST(krb_cv_header_netdb_h_broken)
if test "$krb_cv_header_netdb_h_broken" = "yes"; then
  EXTRA_HEADERS="$EXTRA_HEADERS netdb.h"
fi

dnl
dnl Check for sa_len in sys/socket.h
dnl

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

dnl
dnl Check for ouid in sys/siad.h
dnl

if test "$ac_cv_header_siad_h" = yes; then
AC_HAVE_STRUCT_FIELD(SIAENTITY, ouid, [#include <siad.h>])
fi

rk_TEST_PACKAGE(readline,
[#include <stdio.h>
 #include <readline.h>],-lreadline,,, READLINE)

KRB_READLINE

rk_TELNET

AC_MSG_CHECKING([if /bin/ls takes -A])
if /bin/ls -A > /dev/null 2>&1 ;then
	AC_DEFINE(HAVE_LS_A, 1, [Define if /bin/ls has a `-A' flag.])
	krb_ls_a=yes
else
	krb_ls_a=no
fi
AC_MSG_RESULT($krb_ls_a)
	
rk_CHECK_MAN

rk_DESTDIRS

LTLIBOBJS=`echo "$LIB@&t@OBJS" |
	sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
AC_SUBST(LTLIBOBJS)

AH_BOTTOM([#ifdef ROKEN_RENAME
#include "roken_rename.h"
#endif])

dnl
dnl We are all set to emit the Makefiles and config.h
dnl
AC_OUTPUT(					\
	Makefile 					\
	admin/Makefile					\
	appl/Makefile					\
	appl/afsutil/Makefile 				\
	appl/bsd/Makefile 				\
	appl/ftp/Makefile				\
	appl/ftp/common/Makefile			\
	appl/ftp/ftp/Makefile				\
	appl/ftp/ftpd/Makefile				\
	appl/kauth/Makefile				\
	appl/kip/Makefile				\
	appl/kx/Makefile				\
	appl/movemail/Makefile				\
	appl/otp/Makefile				\
	appl/popper/Makefile				\
	appl/push/Makefile				\
	appl/sample/Makefile				\
	appl/telnet/Makefile				\
	appl/telnet/libtelnet/Makefile			\
	appl/telnet/telnet/Makefile			\
	appl/telnet/telnetd/Makefile			\
	appl/xnlock/Makefile				\
	doc/Makefile					\
	etc/inetd.conf.changes				\
	include/Makefile				\
	include/sys/Makefile				\
	kadmin/Makefile					\
	kuser/Makefile					\
	lib/Makefile					\
	lib/acl/Makefile				\
	lib/auth/Makefile				\
	lib/auth/afskauthlib/Makefile			\
	lib/auth/pam/Makefile				\
	lib/auth/sia/Makefile				\
	lib/com_err/Makefile				\
	lib/des/Makefile				\
	lib/editline/Makefile				\
	lib/kadm/Makefile				\
	lib/kafs/Makefile				\
	lib/kdb/Makefile				\
	lib/krb/Makefile				\
	lib/krb/krb.h					\
	lib/otp/Makefile				\
	lib/roken/Makefile				\
	lib/rxkad/Makefile				\
	lib/sl/Makefile					\
	lib/vers/Makefile				\
	server/Makefile					\
	slave/Makefile					\
	tools/Makefile					\
) dnl end of AC_OUTPUT

AC_KRB_VERSION
