dnl $Id: configure.in,v 1.22 2004/05/10 23:19:02 kretch Exp $
dnl Process this file with autoconf to produce a configure script.
AC_INIT(owl.c)

AC_CONFIG_HEADER(config.h)

AC_PROG_CC

dnl If we're using GCC, enable all warnings
if test "$GCC" = yes; then
     CFLAGS="$CFLAGS -Wall -g";
fi


dnl Check for Athena
AC_MSG_CHECKING(for /usr/athena/include)
if test -d /usr/athena/include; then
	CFLAGS=${CFLAGS}\ -I/usr/athena/include
	CPPFLAGS=${CPPFLAGS}\ -I/usr/athena/include
	AC_MSG_RESULT(yes)
else
	AC_MSG_RESULT(no)
fi
AC_MSG_CHECKING(for /usr/athena/lib)
if test -d /usr/athena/lib; then
	LDFLAGS=-L/usr/athena/lib\ -R/usr/athena/lib\ ${LDFLAGS}
	AC_MSG_RESULT(yes)
else
	AC_MSG_RESULT(no)
fi

dnl Check for kerberosIV include
AC_MSG_CHECKING(for /usr/include/kerberosIV)
if test -d /usr/include/kerberosIV; then
        CFLAGS=${CFLAGS}\ -I/usr/include/kerberosIV
        CPPFLAGS=${CPPFLAGS}\ -I/usr/include/kerberosIV
        AC_MSG_RESULT(yes)
else
        AC_MSG_RESULT(no)
fi

AC_CHECK_LIB(ncurses, initscr,,
   AC_CHECK_LIB(curses, initscr,, AC_MSG_ERROR(No curses library found.)))
AC_CHECK_LIB(com_err, com_err)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(k5crypto, krb5_derive_key)
AC_CHECK_LIB(des425, req_act_vno)
AC_CHECK_LIB(des, des_quad_cksum)
AC_CHECK_LIB(resolv, res_search)
AC_CHECK_LIB(krb5, krb5_get_credentials)
AC_CHECK_LIB(krb4, krb_sendauth,,
   AC_CHECK_LIB(krb, krb_sendauth))
dnl AC_CHECK_LIB(zephyr, ZGetSender,, AC_MSG_ERROR(No zephyr library found.))
AC_CHECK_LIB(zephyr, ZGetSender)
AC_CHECK_LIB(zephyr, ZInitLocationInfo, AC_DEFINE([HAVE_LIBZEPHYR_ZINITLOCATIONINFO], [], [Have ZInitLocationInfo]),)

AC_CHECK_FUNCS(use_default_colors des_string_to_key des_key_sched des_ecb_encrypt)

AC_MSG_CHECKING(for des_ecb_encrypt prototype)
AC_TRY_COMPILE([#include <des.h>
int des_ecb_encrypt(char foo[], char bar[], des_key_schedule baz, int qux);],
[int foo = des_ecb_encrypt(0,0,0,0);],
ac_cv_des_ecb_encrypt_proto=no,
ac_cv_des_ecb_encrypt_proto=yes)
AC_MSG_RESULT($ac_cv_des_ecb_encrypt_proto)
if test "$ac_cv_des_ecb_encrypt_proto" = yes; then
	AC_DEFINE([HAVE_DES_ECB_ENCRYPT_PROTO], [], [have proto for des_ecb_encrypt])
fi

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(strings.h sys/ioctl.h sys/filio.h unistd.h com_err.h)

dnl Add CFLAGS for embeded perl
FOO=`perl -MExtUtils::Embed -e ccopts`
echo Adding perl CFLAGS ${FOO}
CFLAGS=${CFLAGS}\ ${FOO}

dnl Find the location of perl XSUBPP
AC_MSG_CHECKING(for the perl xsubpp precompiler)
XSUBPPDIR="`(perl -MExtUtils::MakeMaker -e 'print ExtUtils::MakeMaker->new({NAME => qw(owl)})->tool_xsubpp;') | grep \^XSUBPPDIR | sed -e 's/XSUBPPDIR = //g;'`"
if test -n "${XSUBPPDIR}"; then
   AC_MSG_RESULT(${XSUBPPDIR})
else
   AC_MSG_ERROR(not found)
fi

dnl Add LDFLAGS for embeded perl
FOO=`perl -MExtUtils::Embed -e ldopts | sed 's/,-E//' | sed 's/-liconv//'`
echo Adding perl LDFLAGS ${FOO}
LDFLAGS=${LDFLAGS}\ ${FOO}

dnl Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_FILE(/usr/share/terminfo, AC_DEFINE(TERMINFO, "/usr/share/terminfo", [Have terminfo]),
  AC_CHECK_FILE(/usr/share/lib/terminfo, AC_DEFINE(TERMINFO, "/usr/share/lib/terminfo", [Have terminfo]),
  AC_MSG_ERROR(No terminfo found for this system)))

AC_SUBST(XSUBPPDIR)

AC_PROG_INSTALL

AC_CONFIG_SUBDIRS(libfaim)

AC_OUTPUT(Makefile)
