AC_INIT
AC_CONFIG_SRCDIR([aclocal.m4])
dnl
dnl autoconf 2.49 defaults to a /dev/null cache file, which is what we
dnl do not want for performance reasons. 
if test "x$cache_file" = "x/dev/null"; then
  cache_file=./config.cache
  AC_CACHE_LOAD
fi
dnl
CONFIG_RULES
dnl
dnl Determine version from patchlevel.h
eval `sed -n 's/#define \([A-Z0-9_]*\)[ \t]*\(.*\)/\1=\2/p' < $srcdir/patchlevel.h`
KRB5_VERSION="$KRB5_MAJOR_RELEASE.$KRB5_MINOR_RELEASE"
if test "$KRB5_PATCHLEVEL" = 0; then :; else
  KRB5_VERSION="$KRB5_VERSION.$KRB5_PATCHLEVEL"
fi
if test -n "$KRB5_RELTAIL"; then
  KRB5_VERSION="$KRB5_VERSION-$KRB5_RELTAIL"
fi
AC_SUBST(KRB5_VERSION)
dnl
AC_REQUIRE_CPP
dnl
dnl The following lines are so that configure --help gives some global 
dnl configuration options.
dnl
KRB5_LIB_AUX
AC_KRB5_TCL
AC_ARG_ENABLE([athena],
[  --enable-athena         build with MIT Project Athena configuration],,)
dnl
if test -z "$KRB4_LIB"; then
kadminv4=""
krb524=""
libkrb4=""
KRB4=""
else
kadminv4=kadmin.v4
krb524=krb524
libkrb4=lib/krb4
KRB4=krb4
fi
AC_SUBST(KRB4)
AC_SUBST(krb524)
dnl
dnl Begin autoconf tests for the Makefiles generated out of the top-level
dnl configure.in...
dnl
AC_CHECK_FUNCS(memmove)
KRB5_BUILD_LIBOBJS
KRB5_BUILD_LIBRARY_WITH_DEPS
KRB5_BUILD_PROGRAM
dnl for slave
AC_TYPE_MODE_T
AC_PROG_INSTALL
KRB5_AC_NEED_DAEMON
KRB5_GETSOCKNAME_ARGS
KRB5_GETPEERNAME_ARGS
LIBUTIL=
AC_CHECK_LIB(util,main,[AC_DEFINE(HAVE_LIBUTIL)
LIBUTIL=-lutil
])
AC_SUBST(LIBUTIL)
dnl for kdc
AC_CHECK_HEADERS(syslog.h stdarg.h sys/select.h sys/sockio.h ifaddrs.h unistd.h)
AC_CHECK_FUNCS(openlog syslog closelog strftime vsprintf)
KRB5_NEED_PROTO([#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
/* Solaris 8 declares swab in stdlib.h.  */
#include <stdlib.h>
],swab,1)
dnl
AC_PROG_AWK
KRB5_AC_INET6
KRB5_SOCKADDR_SA_LEN
CHECK_SIGNALS
dnl
dnl --with-vague-errors disables useful error messages.
dnl
AC_ARG_WITH([vague-errors],
AC_HELP_STRING([--with-vague-errors],[Do not @<:@do@:>@ send helpful errors to client]), , withval=no)dnl
if test "$withval" = yes; then
	AC_MSG_RESULT(Supplying vague error messages to KDC clients)
	AC_DEFINE(KRBCONF_VAGUE_ERRORS)
fi
dnl
dnl --with-kdc-kdb-update makes the KDC update the database with last request
dnl information and failure information.
dnl
AC_ARG_WITH([kdc-kdb-update],
AC_HELP_STRING([--with-kdc-kdb-update],[Update the database @<:@don't update@:>@]), , withval=no)dnl
if test "$withval" = yes; then
	AC_MSG_RESULT(Updating KDC database with each request)
	AC_DEFINE(KRBCONF_KDC_MODIFIES_KDB)
fi
dnl
dnl Needed for hw-preauth replay detection on KDC.
dnl
dnl USE_RCACHE enables the replay cache
dnl NOCACHE disables the lookaside cache
dnl
dnl The lookaside cache is checked first; if *exactly* the same message
dnl comes in twice, e.g., because the (legitimate) client resent it,
dnl the previous response will be resent.  Otherwise, the replay cache
dnl is used to check for attempts to fake out the KDC.  Some hardware
dnl preauth methods are weak enough that we *really* want to have this
dnl checking turned on.
dnl
AC_ARG_ENABLE([kdc-replay-cache],
AC_HELP_STRING([--enable-kdc-replay-cache],[check for replayed/retransmitted KDC requests (recommended when hardware preauthentication is in use) @<:@disabled@:>@]), , enableval=yes)dnl
if test "$enableval" = yes ; then
	AC_DEFINE(USE_RCACHE)
else
	AC_DEFINE(NOCACHE)
fi
AC_ARG_ENABLE([fakeka],
AC_HELP_STRING([--enable-fakeka],[build the Fake KA server (emulates an AFS kaserver) @<:@default: don't build@:>@]), , enableval=no)dnl
if test "$enableval" = yes; then
	FAKEKA=fakeka
else
	FAKEKA=
fi
AC_SUBST(FAKEKA)
KRB5_RUN_FLAGS
dnl
dnl for krb524
AC_TYPE_SIGNAL
dnl
dnl
dnl Check for thread safety issues.
dnl (Is there a better place for this?)
tsfuncs="getpwnam_r getpwuid_r gethostbyname_r getservbyname_r gmtime_r localtime_r"
AC_CHECK_FUNCS($tsfuncs)
if test "$enable_thread_support" = yes; then
  tsmissing=""
  for ts in $tsfuncs; do
    if eval "test \"\${ac_cv_func_$ts}\" != yes"; then
      tsmissing="$tsmissing $ts"
    fi
  done
  if test "$ac_cv_func_res_nsearch/$ac_cv_lib_resolv_res_nsearch" = "no/no"; then
    tsmissing="$tsmissing res_nsearch"
  fi
  if test "$tsmissing" != ""; then
    AC_MSG_WARN([Some functions that are needed for library thread])
    AC_MSG_WARN([safety appear to be missing.])
    for ts in $tsmissing; do
      AC_MSG_WARN([  missing thread-safe function: $ts])
    done
    AC_MSG_WARN([Without these functions, the installed libraries])
    AC_MSG_WARN([may not be thread-safe.])
  fi # tsmissing not empty
fi # enable_thread_support
dnl
HOST_TYPE=$krb5_cv_host
AC_SUBST(HOST_TYPE)
dnl
dnl
if test "$COM_ERR_VERSION" = k5 ; then
  AC_CONFIG_SUBDIRS(util/et)
fi
if test "$SS_VERSION" = k5 ; then
  AC_CONFIG_SUBDIRS(util/ss)
fi
AC_CONFIG_SUBDIRS(util/profile util/pty)
if test "$DB_VERSION" = k5 ; then
  AC_CONFIG_SUBDIRS(util/db2)
fi
AC_CONFIG_SUBDIRS(include lib/crypto lib/krb5 lib/des425 lib/apputils)
if test -n "$KRB4_LIB"; then
  AC_CONFIG_SUBDIRS(lib/krb4)
fi
AC_CONFIG_SUBDIRS(lib/kdb lib/gssapi lib/rpc lib/kadm5)
dnl if test -n "$KRB4_LIB"; then
dnl   AC_CONFIG_SUBDIRS(krb524)
dnl fi

AC_CONFIG_SUBDIRS(kadmin clients appl tests)
AC_CONFIG_FILES(krb5-config, [chmod +x krb5-config])
V5_AC_OUTPUT_MAKEFILE(. util util/support util/send-pr lib kdc slave krb524 config-files gen-manpages)
