AC_INIT(auth_gssapi.c)
CONFIG_RULES
AC_CONFIG_SUBDIRS(unit-test)
AC_CHECK_HEADERS(sys/uio.h sys/param.h)
AC_TYPE_GETGROUPS
### Check where struct rpcent is declared.
#
# This is necessary to determine:
# 1. If /usr/include/netdb.h declares struct rpcent
# 2. If /usr/include/rpc/netdb.h declares struct rpcent
#
# We have our own rpc/netdb.h, and if /usr/include/netdb.h includes
# rpc/netdb.h, then nastiness could happen.
#
# Logic: If /usr/include/netdb.h declares struct rpcent, then check
# rpc/netdb.h.  If /usr/include/rpc/netdb.h declares struct rpcent,
# then define STRUCT_RPCENT_IN_RPC_NETDB_H, otherwise do not.  If
# neither netdb.h nor rpc/netdb.h declares struct rpcent, then define
# STRUCT_RPCENT_IN_RPC_NETDB_H anyway.
#
AC_MSG_CHECKING([where struct rpcent is declared])
AC_TRY_COMPILE([#include <netdb.h>],
[struct rpcent e;
char c = e.r_name[0];
int i = e.r_number;],
[AC_TRY_COMPILE([#include <rpc/netdb.h>],
[struct rpcent e;
char c = e.r_name[0];
int i = e.r_number;],
[AC_MSG_RESULT([rpc/netdb.h])
rpcent_define='#define STRUCT_RPCENT_IN_RPC_NETDB_H'],
[AC_MSG_RESULT([netdb.h])])],
[AC_MSG_RESULT([nowhere])
rpcent_define='#define STRUCT_RPCENT_IN_RPC_NETDB_H'])
AC_SUBST(rpcent_define)

AC_CHECK_HEADERS(sys/select.h sys/time.h unistd.h)
if test $ac_cv_header_sys_select_h = yes; then
  GSSRPC__SYS_SELECT_H='#include <sys/select.h>'
else
  GSSRPC__SYS_SELECT_H='/* #include <sys/select.h> */'
fi
AC_SUBST(GSSRPC__SYS_SELECT_H)
if test $ac_cv_header_sys_time_h = yes; then
  GSSRPC__SYS_TIME_H='#include <sys/time.h>'
else
  GSSRPC__SYS_TIME_H='/* #include <sys/time.h> */'
fi
AC_SUBST(GSSRPC__SYS_TIME_H)
if test $ac_cv_header_unistd_h = yes; then
  GSSRPC__UNISTD_H='#include <unistd.h>'
else
  GSSRPC__UNISTD_H='/* #include <unistd.h> */'
fi
AC_SUBST(GSSRPC__UNISTD_H)

AC_CACHE_CHECK([for MAXHOSTNAMELEN in sys/param.h],
  [krb5_cv_header_sys_param_h_maxhostnamelen],
  [AC_TRY_COMPILE([#include <sys/param.h>],
    [int i = MAXHOSTNAMELEN;],
    [krb5_cv_header_sys_param_h_maxhostnamelen=yes],
    [krb5_cv_header_sys_param_h_maxhostnamelen=no])])
AC_CACHE_CHECK([for MAXHOSTNAMELEN in netdb.h],
  [krb5_cv_header_netdb_h_maxhostnamelen],
  [AC_TRY_COMPILE([#include <netdb.h>],
    [int i = MAXHOSTNAMELEN;],
    [krb5_cv_header_netdb_h_maxhostnamelen=yes],
    [krb5_cv_header_netdb_h_maxhostnamelen=no])])

GSSRPC__SYS_PARAM_H='/* #include <sys/param.h> */'
GSSRPC__NETDB_H='/* #include <netdb.h> */'
if test $krb5_cv_header_sys_param_h_maxhostnamelen = yes; then
  GSSRPC__SYS_PARAM_H='#include <sys/param.h>'
else
  if test $krb5_cv_header_netdb_h_maxhostnamelen = yes; then
    GSSRPC__NETDB_H='#include <netdb.h>'
  else
    AC_MSG_WARN([can't find MAXHOSTNAMELEN definition; faking it])
  fi
fi
AC_SUBST(GSSRPC__SYS_PARAM_H)
AC_SUBST(GSSRPC__NETDB_H)

AC_CACHE_CHECK([for uint32_t in sys/types.h],
  [krb5_cv_header_sys_types_h_uint32_t],
  [AC_TRY_COMPILE([#include <sys/types.h>],
      [uint32_t i = 0;],
      [krb5_cv_header_sys_types_h_uint32_t=yes],
      [krb5_cv_header_sys_types_h_uint32_t=no])])
AC_CACHE_CHECK([for uint32_t in stdint.h],
  [krb5_cv_header_stdint_h_uint32_t],
  [AC_TRY_COMPILE([#include <stdint.h>],
      [uint32_t i = 0;],
      [krb5_cv_header_stdint_h_uint32_t=yes],
      [krb5_cv_header_stdint_h_uint32_t=no])])
AC_CACHE_CHECK([for uint32_t in inttypes.h],
  [krb5_cv_header_inttypes_h_uint32_t],
  [AC_TRY_COMPILE([#include <inttypes.h>],
      [uint32_t i = 0;],
      [krb5_cv_header_inttypes_h_uint32_t=yes],
      [krb5_cv_header_inttypes_h_uint32_t=no])])
GSSRPC__STDINT_H='/* #include <stdint.h> */'
GSSRPC__INTTYPES_H='/* #include <inttypes.h> */'
GSSRPC__FAKE_UINT32='/* #undef GSSRPC__FAKE_INT32 */'
if test $krb5_cv_header_sys_types_h_uint32_t = yes; then
  : # already included sys/types.h
else
  if test $krb5_cv_header_stdint_h_uint32_t = yes; then
    GSSRPC__STDINT_H='#include <stdint.h>'
  else
    if test $krb5_cv_header_inttypes_h_uint32_t = yes; then
      GSSRPC__INTTYPES_H='#include <inttypes.h>'
    else
      AC_MSG_WARN([can't find a fixed-width 32-bit type anywhere; faking it])
      GSSRPC__FAKE_UINT32='#define GSSRPC__FAKE_UINT32 1'
    fi
  fi
fi
AC_SUBST(GSSRPC__STDINT_H)
AC_SUBST(GSSRPC__INTTYPES_H)
AC_SUBST(GSSRPC__FAKE_UINT32)

AC_CACHE_CHECK([for BSD type aliases], [krb5_cv_type_bsdaliases],
  [AC_TRY_COMPILE(
    [#include <sys/types.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif],
    [u_char c;
u_int i;
u_long l;], [krb5_cv_type_bsdaliases=yes], [krb5_cv_type_bsdaliases=no])])
if test $krb5_cv_type_bsdaliases = yes; then
  GSSRPC__BSD_TYPEALIASES='/* #undef GSSRPC__BSD_TYPEALIASES */'
else
  GSSRPC__BSD_TYPEALIASES='#define GSSRPC__BSD_TYPEALIASES 1'
fi
AC_SUBST(GSSRPC__BSD_TYPEALIASES)

AC_CHECK_FUNCS(strerror)
#
# sockaddr length field checks
#
AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , ,
  [#include <sys/types.h>
@%:@include <netinet/in.h>])
AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
  [#include <sys/types.h>
@%:@include <sys/socket.h>])

AC_MSG_CHECKING([return type of setrpcent])
AC_CACHE_VAL(k5_cv_type_setrpcent,
[AC_TRY_COMPILE([#include <netdb.h>
#ifdef __cplusplus
extern "C"
#endif
extern void setrpcent();],
[int i;], k5_cv_type_setrpcent=void, k5_cv_type_setrpcent=int)])dnl
AC_MSG_RESULT($k5_cv_type_setrpcent)
AC_DEFINE_UNQUOTED(SETRPCENT_TYPE, $k5_cv_type_setrpcent)
dnl
AC_MSG_CHECKING([return type of endrpcent])
AC_CACHE_VAL(k5_cv_type_endrpcent,
[AC_TRY_COMPILE([#include <netdb.h>
#ifdef __cplusplus
extern "C"
#endif
extern void endrpcent();],
[int i;], k5_cv_type_endrpcent=void, k5_cv_type_endrpcent=int)])dnl
AC_MSG_RESULT($k5_cv_type_endrpcent)
AC_DEFINE_UNQUOTED(ENDRPCENT_TYPE, $k5_cv_type_endrpcent)
DECLARE_SYS_ERRLIST
KRB5_BUILD_LIBOBJS
KRB5_BUILD_LIBRARY_WITH_DEPS
K5_GEN_FILE(types.h:types.hin)
V5_AC_OUTPUT_MAKEFILE
