dnl Process this file with autoconf to produce a configure script.
dnl
AC_REVISION($Revision: 1.194 $)
AC_INIT(afssys.c)
AC_CONFIG_HEADER(config.h)

dnl
dnl definitions
dnl

PACKAGE=krbafs
AC_SUBST(PACKAGE)dnl
VERSION=0.9.3-pre1
AC_SUBST(VERSION)dnl
# This may be overridden using --prefix=/usr to configure
AC_PREFIX_DEFAULT(/usr/local)

AC_CANONICAL_HOST
AC_PROG_MAKE_SET
AC_ARG_PROGRAM

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

dnl
dnl check for programs
dnl

CFLAGS=${CFLAGS-"-g"}

AC_LN_S
AC_PROG_CC
AC_PROG_CPP
AC_ISC_POSIX
AC_KRB_PROG_YACC
AC_PROG_LEX
AC_PROG_RANLIB
AC_PROG_INSTALL

dnl
dnl check for build options
dnl

AC_TEST_PACKAGE(socks,socks.h,libsocks5.a,-lsocks5)
CFLAGS="$SOCKSINCLUDE $CFLAGS"
LIBS="$SOCKSLIB $LIBS"

dnl Check if we want to use shared libaries
AC_ARG_WITH(shared,
[  --enable-shared           create shared libraries for Kerberos])

dnl
dnl Shared library stuff has to be different everywhere
dnl

dnl If we're using gcc and the user hasn't specified CFLAGS, add -O to CFLAGS.
dnl test -n "$GCC" && test -n "$auto_cflags" && CFLAGS="$CFLAGS -O"

AC_SUBST(CFLAGS)dnl
AC_SUBST(LDFLAGS)dnl

case ${enable_shared} in
  yes ) enable_shared=yes;;
  no  ) enable_shared=no;;
  *   ) enable_shared=no;;
esac

# NOTE: Building shared libraries may not work if you do not use gcc!
#
# OS		$SHLIBEXT
# HP-UX		sl
# Linux		so
# NetBSD	so
# FreeBSD	so
# OSF		so
# SunOS5	so
# SunOS4	so.0.5
# Irix		so
#
# LIBEXT is the extension we should build (.a or $SHLIBEXT)
REAL_PICFLAGS="-fpic"
REAL_SHARED="-shared"
case "${host}" in
*-*-hpux*)	 REAL_SHLIBEXT=sl;	 REAL_LD_FLAGS='-Wl,+b$(libdir)'
if test -z "$GCC"; then REAL_SHARED="-c ; /bin/ld -b"; REAL_PICFLAGS="+z"; fi ;;
*-*-linux*)	 REAL_SHLIBEXT=so;	 REAL_LD_FLAGS='-Wl,-rpath,$(libdir)' ;;
*-*-netbsd*)	 REAL_SHLIBEXT=so;	 REAL_LD_FLAGS='-Wl,-L$(libdir),-R' ;;
*-*-freebsd*)	 REAL_SHLIBEXT=so;	 REAL_LD_FLAGS='-Wl,-L$(libdir),-R' ;;
*-*-osf*)	 REAL_SHLIBEXT=so;	 REAL_LD_FLAGS='-Wl,-rpath,$(libdir)'; REAL_PICFLAGS= ;;
*-*-solaris2*) REAL_SHLIBEXT=so;	 REAL_LD_FLAGS='-Wl,-R$(libdir)'
if test -z "$GCC"; then REAL_SHARED="-G"; REAL_PICFLAGS="-Kpic"; fi ;;
*-*-sunos*)	 REAL_SHLIBEXT=so.0.5 REAL_LD_FLAGS='-Wl,-L$(libdir)' ;;
*-*-irix*)	 REAL_SHLIBEXT=so;	 REAL_LD_FLAGS='-Wl,-rpath,$(libdir)'; REAL_PICFLAGS= ;;
*)		 REAL_SHLIBEXT=nobuild; REAL_PICFLAGS= ;;
esac

if test "${enable_shared}" != "yes" ; then 
 PICFLAGS=""
 SHLIBEXT="nobuild"
 LIBEXT="a"
else
 PICFLAGS=$REAL_PICFLAGS
 SHLIBEXT=$REAL_SHLIBEXT
 LIBEXT=$SHLIBEXT
 SHARED=$REAL_SHARED
 LD_FLAGS=$REAL_LD_FLAGS
fi

AC_SUBST(REAL_PICFLAGS) dnl
AC_SUBST(REAL_SHARED) dnl
AC_SUBST(REAL_SHLIBEXT) dnl
AC_SUBST(REAL_LD_FLAGS) dnl

AC_SUBST(PICFLAGS) dnl
AC_SUBST(SHARED) dnl
AC_SUBST(SHLIBEXT) dnl
AC_SUBST(LD_FLAGS) dnl
AC_SUBST(LIBEXT) dnl

dnl
dnl Check if we need to use weak-stuff
dnl

AC_HAVE_PRAGMA_WEAK

dnl
dnl Cross compiling?
dnl
AC_C_CROSS

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

dnl
dnl Check for constness
dnl
AC_C_CONST

AC_CHECK_SIZEOF(long,4)
AC_CHECK_SIZEOF(int,4)
if test "$ac_cv_sizeof_long" = "4"; then
        INT32=long
else
   if test "$ac_cv_sizeof_int" = "4"; then
        INT32=int
   else
        AC_MSG_ERROR([Cannot find 32 bit type])
   fi
fi
AC_SUBST(INT32)

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

AC_KRB_SYS_NEXTSTEP
AC_KRB_SYS_AIX

if test "$krb_cv_sys_aix" = yes ;then
	AFS_EXTRA_OBJS='$(srcdir)/afsl.exp dlfcn.o'
	AC_SUBST(AFS_EXTRA_OBJS)
	AFS_EXTRA_LIBS=afslib.so
	AC_SUBST(AFS_EXTRA_LIBS)
fi

dnl
dnl Various checks for libraries and their contents
dnl

dnl
dnl System V is have misplaced the socket routines, should really be in libc
dnl
dnl This won't work on SGIs

AC_FIND_FUNC(socket, socket)
AC_FIND_FUNC(gethostbyname, nsl)

AC_FIND_FUNC(res_search, resolv)
AC_FIND_FUNC(dn_expand, resolv)

AC_CHECK_FUNCS(gethostname)

AC_FUNC_MMAP
AC_FUNC_ALLOCA

AC_BROKEN(memmove putenv setenv unsetenv)

AC_KRB_FUNC_GETCWD_BROKEN

dnl
dnl Various checks for headers and their contents
dnl

AC_STDC_HEADERS

AC_CHECK_HEADERS(arpa/nameser.h crypt.h)
AC_CHECK_HEADERS(netdb.h netinet/in.h)
AC_CHECK_HEADERS(resolv.h)
AC_CHECK_HEADERS(sys/bitypes.h sys/cdefs.h)
AC_CHECK_HEADERS(sys/filio.h sys/ioccom.h sys/ioctl.h)
AC_CHECK_HEADERS(afs/param.h)
AC_CHECK_HEADERS(sys/param.h)
AC_CHECK_HEADERS(sys/socket.h)
AC_CHECK_HEADERS(sys/syscall.h)
AC_CHECK_HEADERS(sys/types.h)
AC_CHECK_HEADERS(unistd.h)

AC_DECL_SYS_SIGLIST
AC_SUBST(ac_cv_header_sys_cdefs_h)dnl
AC_SUBST(ac_cv_header_sys_bitypes_h)dnl
AC_SUBST(ac_cv_header_err_h)dnl

dnl
dnl Checks for prototypes and declarations
dnl

AC_NEED_DECLARATION([#include <stdlib.h>], [char *], optarg)
AC_NEED_DECLARATION([#include <stdlib.h>], [int], optind)
AC_NEED_DECLARATION([#include <stdlib.h>], [int], opterr)
AC_NEED_DECLARATION([#include <stdlib.h>], [int], optopt)

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)
fi

dnl
dnl Check for u_int32_t in sys/types.h
dnl
AC_EGREP_HEADER(u_int32_t, sys/types.h, sys_types_have_int32_t=yes)
AC_SUBST(sys_types_have_int32_t)dnl

dnl
dnl Check for some common types
dnl

AC_TYPE_PID_T
AC_TYPE_UID_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T

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

AC_MSG_CHECKING(for sa_len in struct sockaddr)
AC_CACHE_VAL(krb_cv_struct_sockaddr_sa_len, [
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/socket.h>],
[struct sockaddr sa;
int foo = sa.sa_len;],
krb_cv_struct_sockaddr_sa_len=yes,
krb_cv_struct_sockaddr_sa_len=no)
])
AC_MSG_RESULT($krb_cv_struct_sockaddr_sa_len)
if test "$krb_cv_struct_sockaddr_sa_len" = yes; then
	AC_DEFINE(SOCKADDR_HAS_SA_LEN)
fi

dnl
dnl you can link with getmsg on AIX 3.2 but you cannot run the program
dnl

AC_CACHE_CHECK(for working getmsg, ac_cv_func_getmsg,
AC_TRY_RUN(
[
#include <stdio.h>

int main()
{
  getmsg(open("/dev/null", 0), NULL, NULL, NULL);
  return 0;
}
], ac_cv_func_getmsg=yes, ac_cv_func_getmsg=no, ac_cv_func_getmsg=no))
test "$ac_cv_func_getmsg" = "yes" &&
AC_DEFINE_UNQUOTED(HAVE_GETMSG)

AC_NEED_PROTO([
#ifdef HAVE_CRYPT_H
#include <crypt.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
],
[char x = *crypt("key", "salt");],
crypt)

dnl
dnl We are all set to emit the Makefiles and config.h
dnl
AC_OUTPUT(					\
Makefile 					\
krbafs_int.h
) dnl end of AC_OUTPUT
