dnl> this is a test comment
AC_INIT(src/xsup_driver.c)
AM_INIT_AUTOMAKE(xsupplicant, 1.0.1)
AC_CANONICAL_HOST
AC_PROG_RANLIB
AC_PROG_CC
 if test -n "$GCC"; then
      CFLAGS="$CFLAGS -Wall "
 fi


AC_PROG_YACC
 if test -n "$YACC"; then
       YACC="$YACC -d"
 fi

AM_PROG_LEX
 if test -n "$LEX"; then
       LFLAGS="$LFLAGS -i"
       MORELIBS="${MORELIBS} -lfl"
 fi 

AC_C_BIGENDIAN([big_endian=true;AC_DEFINE(BIGENDIAN)],[big_endian=false;AC_DEFINE(LILENDIAN)])

GGDBFLAGS=""

AC_ARG_WITH(ossl-root, [  --with-ossl-root=DIR    OpenSSL source tree located in DIR], OSSL_ROOT="$withval", OSSL_ROOT=)

dnl We need to fix this to be a little more intelligent.
AC_ARG_ENABLE(eap-sim, [  --enable-eap-sim	enable use of SIM card for authentication],
     [ if test -n "$GCC"; then
	 MOREDEFS="-DEAP_SIM_ENABLE $MOREDEFS"
	 GGDBFLAGS="-ggdb"
	 LDFLAGS="-lpcsclite -lpthread $LDFLAGS"
        else
	 MOREDEFS="-DEAP_SIM_ENABLE $MOREDEFS"
	 LDFLAGS="-lpcsclite -lpthread $LDFLAGS"
       fi
     ],)

AC_ARG_ENABLE(radiator-test, [  --enable-radiator-test    enable use of the test vectors from Radiator.  (Doesn't require a SIM card)],
     [ AC_DEFINE(RADIATOR_TEST) ],)

AC_ARG_ENABLE(experimental,  [  --enable-experimental     enable the use of experimental features/code. ],
     [ AC_DEFINE(EXPERIMENTAL)  ],)

dnl AC_ARG_ENABLE(pwd-reset, [  --disable-pwd-reset disable clearing password on failed authentication.], [ AC_DEFINE(NO_PWD_RESET) ])

dnl This is a feature we will turn on later.  Turning it on now will cause more
dnl confusion than it is worth! ;)
AC_DEFINE(NO_PWD_RESET)

AC_ARG_ENABLE(static-openssl, [  --enable-static-openssl enable static linking of OpenSSL],
     [ LDFLAGS="-static $LDFLAGS"
       STATIC_OSSL="yes" ],
       [STATIC_OSSL="no" ])


AC_MSG_CHECKING([Operating System])

dnl Below turns of Kerberos support in OpenSSL, to avoid compile errors.
AC_DEFINE(OPENSSL_NO_KRB5)
SYSTEM=`uname -s`
AC_MSG_RESULT([$SYSTEM])
if test $SYSTEM = "FreeBSD" || test $SYSTEM = "OpenBSD"; then
  AC_DEFINE(__BSD__)
fi
if test $SYSTEM = "OpenBSD"; then
  AC_DEFINE(OPENBSD)
fi
if test $SYSTEM = "Linux"; then
   AC_DEFINE(LINUX)
fi

if test $STATIC_OSSL = "yes"; then
   AC_MSG_CHECKING([for openssl (required package) <static>])
    if test ".${OSSL_ROOT}" != .; then
       if test -d $OSSL_ROOT &&
	  test -r $OSSL_ROOT/libcrypto.a &&
	  test -r $OSSL_ROOT/libssl.a &&
	  test -r $OSSL_ROOT/include/openssl/hmac.h; then
	       OSSL_ROOT=`cd ${OSSL_ROOT} && pwd`
	       MORELIBS="${MORELIBS} -L$OSSL_ROOT -lssl -lcrypto"
	       INCS="${INCS} -I$OSSL_ROOT/include"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
	  elif test -d $OSSL_ROOT &&
	       test -r $OSSL_ROOT/lib/libcrypto.a &&
	       test -r $OSSL_ROOT/lib/libssl.a &&
	       test -r $OSSL_ROOT/include/openssl/hmac.h; then
	       OSSL_ROOT=`cd ${OSSL_ROOT} && pwd`
	       MORELIBS="${MORELIBS} -L$OSSL_ROOT/lib -lssl -lcrypto"
	       INCS="${INCS} -I$OSSL_ROOT/include"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
	  else
		AC_MSG_RESULT([not found in ${OSSL_ROOT}])
		AC_MSG_WARN([ The Open SSL Library development tree seems corrupted or incomplete!])
		AC_MSG_RESULT([ It looks that you don't have some files needed to use the Open SSL library.])
		AC_MSG_RESULT([ Please check the source tree, compile and, optionally, install the software.])
		AC_MSG_RESULT([ When finished please re-run this program.])
		AC_MSG_ERROR([ You can download the latest source tarball at http://www.openssl.org/])
	fi
    elif test -d /usr/local/ssl &&
	 test -r /usr/local/ssl/lib/libcrypto.a &&
	 test -r /usr/local/ssl/lib/libssl.a &&
	 test -r /usr/local/ssl/include/openssl/hmac.h; then
	      OSSL_ROOT="/usr/local/ssl"
	      MORELIBS="${MORELIBS} -L$OSSL_ROOT/lib  -lssl -lcrypto"
	      INCS="${INCS} -I$OSSL_ROOT/include"
	      AC_DEFINE(HAVE_OPENSSL)
	      AC_MSG_RESULT([$OSSL_ROOT])
     elif test -d /usr/local/ &&
	  test -r /usr/local/lib/libcrypto.a &&
	  test -r /usr/local/lib/libssl.a &&
	  test -r /usr/local/include/openssl/hmac.h; then
	       OSSL_ROOT="/usr/local"
	       MORELIBS="${MORELIBS} -L$OSSL_ROOT/lib  -lssl -lcrypto"
	       INCS="${INCS} -I$OSSL_ROOT/include"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
     elif test -r /usr/lib/ssl/libcrypto.a &&
	  test -r /usr/lib/ssl/libssl.a &&
	  test -r /usr/include/ssl/hmac.h; then
	       OSSL_ROOT="/usr/lib/ssl"
	       MORELIBS="${MORELIBS}  -lssl -lcrypto"
	       INCS="${INCS} -I/usr/include/ssl"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
     elif test -r /usr/lib/libcrypto.a &&
	  test -r /usr/lib/libssl.a &&
	  test -r /usr/include/openssl/hmac.h; then
	       OSSL_ROOT="/usr/lib/"
	       MORELIBS="${MORELIBS}  -lssl -lcrypto"
	       INCS="${INCS} -I/usr/include/openssl"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
dnl Mac OS-X uses libcrypto.dylib instead of libcrypto.a
     elif test -r /usr/lib/libcrypto.dylib &&
	  test -r /usr/include/openssl/hmac.h; then
	       OSSL_ROOT="/usr/lib/"
	       MORELIBS="${MORELIBS} -lssl -lcrypto"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
     elif test -d $OSSL_ROOT &&
	  test -r $OSSL_ROOT/usr/lib/libcrypto.a &&
	  test -r $OSSL_ROOT/usr/lib/libssl.a &&
	  test -r $OSSL_ROOT/usr/include/openssl/hmac.h; then
	       OSSL_ROOT=`cd ${OSSL_ROOT} && pwd`
	       MORELIBS="${MORELIBS} -L$OSSL_ROOT/usr/lib -lssl -lcrypto"
	       INCS="${INCS} -I$OSSL_ROOT/usr/include"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
      else
	AC_MSG_RESULT([not found!])
	AC_MSG_WARN([ The Open SSL Library development tree seems corrupted or incomplete!])
	AC_MSG_RESULT([ Download, compile and, optionally, install it.])
	AC_MSG_RESULT([ When finished please re-run this program.])
	AC_MSG_ERROR([ You can download the latest source tarball at http://www.openssl.org/])
   fi
else
   AC_MSG_CHECKING([for openssl (required package)])
    if test ".${OSSL_ROOT}" != .; then
       if test -d $OSSL_ROOT &&
	  test -r $OSSL_ROOT/libcrypto.so &&
	  test -r $OSSL_ROOT/libssl.so &&
	  test -r $OSSL_ROOT/include/openssl/hmac.h; then
	       OSSL_ROOT=`cd ${OSSL_ROOT} && pwd`
	       MORELIBS="${MORELIBS} -L$OSSL_ROOT -lssl -lcrypto"
	       INCS="${INCS} -I$OSSL_ROOT/include"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
	  elif test -d $OSSL_ROOT &&
	       test -r $OSSL_ROOT/lib/libcrypto.so &&
	       test -r $OSSL_ROOT/lib/libssl.so &&
	       test -r $OSSL_ROOT/include/openssl/hmac.h; then
	       OSSL_ROOT=`cd ${OSSL_ROOT} && pwd`
	       MORELIBS="${MORELIBS} -L$OSSL_ROOT/lib -lssl -lcrypto"
	       INCS="${INCS} -I$OSSL_ROOT/include"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
	  else
		AC_MSG_RESULT([not found in ${OSSL_ROOT}])
		AC_MSG_WARN([ The Open SSL Library development tree seems corrupted or incomplete!])
		AC_MSG_RESULT([ It looks that you don't have some files needed to use the Open SSL library.])
		AC_MSG_RESULT([ Please check the source tree, compile and, optionally, install the software.])
		AC_MSG_RESULT([ When finished please re-run this program.])
		AC_MSG_ERROR([ You can download the latest source tarball at http://www.openssl.org/])
	fi
    elif test -d /usr/local/ssl &&
	 test -r /usr/local/ssl/lib/libcrypto.so &&
	 test -r /usr/local/ssl/lib/libssl.so &&
	 test -r /usr/local/ssl/include/openssl/hmac.h; then
	      OSSL_ROOT="/usr/local/ssl"
	      MORELIBS="${MORELIBS} -L$OSSL_ROOT/lib  -lssl -lcrypto"
	      INCS="${INCS} -I$OSSL_ROOT/include"
	      AC_DEFINE(HAVE_OPENSSL)
	      AC_MSG_RESULT([$OSSL_ROOT])
     elif test -d /usr/local/ &&
	  test -r /usr/local/lib/libcrypto.so &&
	  test -r /usr/local/lib/libssl.so &&
	  test -r /usr/local/include/openssl/hmac.h; then
	       OSSL_ROOT="/usr/local"
	       MORELIBS="${MORELIBS} -L$OSSL_ROOT/lib  -lssl -lcrypto"
	       INCS="${INCS} -I$OSSL_ROOT/include"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
     elif test -r /usr/lib/ssl/libcrypto.so &&
	  test -r /usr/lib/ssl/libssl.so &&
	  test -r /usr/include/ssl/hmac.h; then
	       OSSL_ROOT="/usr/lib/ssl"
	       MORELIBS="${MORELIBS}  -lssl -lcrypto"
	       INCS="${INCS} -I/usr/include/ssl"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
     elif test -r /usr/lib/libcrypto.so &&
	  test -r /usr/lib/libssl.so &&
	  test -r /usr/include/openssl/hmac.h; then
	       OSSL_ROOT="/usr/lib/"
	       MORELIBS="${MORELIBS}  -lssl -lcrypto"
	       INCS="${INCS} -I/usr/include/openssl"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
dnl Mac OS-X uses libcrypto.dylib instead of libcrypto.a
     elif test -r /usr/lib/libcrypto.dylib &&
	  test -r /usr/include/openssl/hmac.h; then
	       OSSL_ROOT="/usr/lib/"
	       MORELIBS="${MORELIBS} -lssl -lcrypto"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
     elif test -d $OSSL_ROOT &&
	  test -r $OSSL_ROOT/usr/lib/libcrypto.so &&
	  test -r $OSSL_ROOT/usr/lib/libssl.so &&
	  test -r $OSSL_ROOT/usr/include/openssl/hmac.h; then
	       OSSL_ROOT=`cd ${OSSL_ROOT} && pwd`
	       MORELIBS="${MORELIBS} -L$OSSL_ROOT/usr/lib -lssl -lcrypto"
	       INCS="${INCS} -I$OSSL_ROOT/usr/include"
	       AC_DEFINE(HAVE_OPENSSL)
	       AC_MSG_RESULT([$OSSL_ROOT])
      else
	AC_MSG_RESULT([not found!])
	AC_MSG_WARN([ The Open SSL Library development tree seems corrupted or incomplete!])
	AC_MSG_RESULT([ Download, compile and, optionally, install it.])
	AC_MSG_RESULT([ When finished please re-run this program.])
	AC_MSG_ERROR([ You can download the latest source tarball at http://www.openssl.org/])
   fi
fi

AC_MSG_CHECKING([for native frame interface])
case "$host_os" in
     *linux*)
	AC_LINK_FILES(src/cardif/Makefile.am.linux, src/cardif/Makefile.am)
	AC_LINK_FILES(src/cardif/linux/linux_core.c, src/core.c)
	AC_MSG_RESULT(linux)
	;;
     *)
	AC_DEFINE(GENERIC_FRAMER)
	AC_MSG_RESULT(generic)
	;;
esac

AC_MSG_CHECKING([for wireless extensions])
case "$host_os" in
     *linux*)
		if test -r /usr/include/linux/wireless.h; then
		   AC_MSG_RESULT(found for linux)
		   AC_DEFINE(LINUX_WIRELESS_EXT)
		else
		   AC_MSG_RESULT(not found)
		fi
		;;
      *)        
        AC_MSG_RESULT(not found)
        ;;
esac

AC_MSG_CHECKING([for procfs support])
if test -r /proc/net/dev; then
   AC_MSG_RESULT(okay)
else
   AC_MSG_ERROR([You must have ProcFS enabled in your kernel!]);
fi

CFLAGS="$GGDBFLAGS $CFLAGS"

dnl Touch the makefile.in to avoid running automake the next time we
dnl run.
touch Makefile.in

AC_SUBST(MORELIBS)
AC_SUBST(CORELIBS)
AC_SUBST(MOREDEFS)
AC_SUBST(LDFLAGS)
AC_SUBST(INCS)
AC_OUTPUT(Makefile src/Makefile src/cardif/Makefile tools/Makefile doc/Makefile etc/Makefile drivers/Makefile tools/config-parser/Makefile gui_tools/Makefile gui_tools/cli/Makefile gui_tools/cli/xsup_set_pwd/Makefile gui_tools/cli/xsup_monitor/Makefile)





