+dnl Checks the compiler and UNIX Variants
+
+if test $cross_compiling = yes -a $ol_enable_x_compile = yes; then
+ AC_MSG_WARN([cross compiling.... some functionality will be removed.])
+
+elif test $cross_compiling = no -a $ol_enable_x_compile = yes; then
+ AC_MSG_WARN([programs compiled here do run here...])
+ AC_MSG_ERROR([ if not cross compiling, use --disable-x-compile.])
+
+elif test $cross_compiling = yes -a $ol_enable_x_compile = no; then
+ AC_MSG_WARN([programs compiled here do not run here...])
+ AC_MSG_ERROR([ if cross compiling, add --enable-x-compile.])
+fi
+
+AC_PROG_CPP
+
+AC_AIX
+AC_ISC_POSIX
+AC_MINIX
+
+dnl OpenLDAP requires STDC features
+AM_PROG_CC_STDC
+if test "X${am_cv_prog_cc_stdc}" = "Xno" ; then
+ AC_MSG_ERROR([OpenLDAP requires compiler to support STDC prototypes.])
+fi
+
+dnl AM_C_PROTOTYPES
+
+dnl Checks for libraries
+
+dnl Find socket()
+dnl Likely combinations:
+dnl -lsocket [ -lnsl_s | -lnsl ]
+dnl -linet
+
+AC_CHECK_FUNC(socket, [have_socket=yes], [
+dnl
+dnl hopefully we won't include too many libraries
+dnl
+ AC_CHECK_LIB(socket, main)
+ AC_CHECK_LIB(net, main)
+ AC_CHECK_LIB(nsl_s, main)
+ AC_CHECK_LIB(nsl, main)
+ AC_CHECK_LIB(inet, socket)
+ AC_CHECK_LIB(gen, main)
+])
+
+dnl Check for resolv
+AC_CHECK_LIB(resolv, res_search)
+
+dnl HP-UX requires -lV3
+AC_CHECK_LIB(V3, sigset)
+
+# ISODE tests
+ol_link_isode=no
+if test $ol_enable_ldapd != no ; then
+ dnl look for ISODE libraries
+ AC_CHECK_LIB(xtpp, main, [
+ ol_link_isode=yes
+ AC_DEFINE(HAVE_XTPP,1)
+ LDAPD_LIBS="$LDAPD_LIBS -lxtpp -lxtdsap -lxtisode -losi"
+ ],:,[-lxtdsap -lxtisode -losi])
+ AC_CHECK_LIB(dsap, main, [
+ ol_link_isode=yes
+ AC_DEFINE(HAVE_DSAP,1)
+ LDAPD_LIBS="$LDAPD_LIBS -ldsap"
+ ],:,[-lisode])
+ AC_CHECK_LIB(isode, main, [
+ ol_link_isode=yes
+ AC_DEFINE(HAVE_ISODE,1)
+ LDAPD_LIBS="$LDAPD_LIBS -lisode"
+ ],:)
+fi
+
+if test $ol_link_isode != no; then
+ AC_CHECK_LIB(pp, main, [
+ AC_DEFINE(HAVE_PP,1)
+ LDAPD_LIBS="-lpp $LDAPD_LIBS"
+ ],:)
+
+ AC_PATH_PROG(PEPSY, pepsy)
+fi
+
+if test $ol_with_kerberos = auto -o $ol_with_kerberos = k5 ; then
+ AC_CHECK_HEADERS(kerberosIV/krb.h kerberosIV/des.h)
+
+ if test $ac_cv_header_kerberosIV_krb_h = yes ; then
+ AC_CHECK_LIB(krb4, main, [have_k5=yes], [have_k5=no],
+ [-lkrb5 -ldes425])
+
+ if test $have_k5 = yes ; then
+ ol_with_kerberos=found
+ ol_link_kerberos=yes
+
+ AC_DEFINE(HAVE_KERBEROS)
+
+ KRB_LIBS="-lkrb4 -lkrb5 -ldes425"
+ fi
+ fi
+fi
+if test $ol_with_kerberos = auto -o $ol_with_kerberos = k4 ; then
+ AC_CHECK_HEADERS(krb.h des.h)
+
+ if test $ac_cv_header_krb_h = yes ; then
+ AC_CHECK_LIB(krb, main, [have_k4=yes], [have_k4=no], [-ldes])
+
+ if test $have_k4 = yes ; then
+ ol_with_kerberos=found
+ ol_link_kerberos=yes
+
+ AC_DEFINE(HAVE_KERBEROS)
+ KRB_LIBS="-lkrb -ldes"
+
+ AC_CHECK_FUNCS(des_string_to_key)
+ fi
+ fi
+fi
+
+ol_link_threads=no
+if test $ol_with_threads = auto -o $ol_with_threads = posix ; then
+ AC_CHECK_HEADERS(pthread.h sched.h)
+
+ if test $ac_cv_header_pthread_h = yes ; then
+ OL_POSIX_THREAD_VERSION
+
+ if test $ol_cv_pthread_version = final ; then
+ AC_DEFINE(HAVE_PTHREADS_FINAL)
+ elif test $ol_cv_pthread_version = draft4 ; then
+ AC_DEFINE(HAVE_PTHREADS_D4)
+ else
+ AC_MSG_ERROR([unknown pthread version])
+ fi
+
+ # consider threads found
+ ol_with_threads=found
+
+ OL_LINUX_THREADS
+
+ if test $ol_cv_linux_threads = yes ; then
+ AC_DEFINE(HAVE_LINUX_THREADS,1)
+ fi
+
+ dnl Now the hard part, how to link
+
+ dnl Check for pthread support in current $LIBS
+ AC_CHECK_FUNC(pthread_create,[ol_link_threads=yes])
+
+ if test $ol_link_threads = no ; then
+ dnl try -pthread
+ AC_CACHE_CHECK([for pthread_create with -pthread],
+ [ol_cv_pthread_flag], [
+ dnl save the flags
+ save_LIBS="$LIBS"
+ LIBS="-pthread $LIBS"
+ AC_TRY_LINK([char pthread();],[
+ pthread_create();
+ ], ol_cv_pthread_flag=yes, ol_cv_pthread_flag=no)
+ dnl restore the LIBS
+ LIBS="$save_LIBS"
+ ])
+
+ if test $ol_cv_pthread_flag = yes ; then
+ LTHREAD_LIBS="$LTHREAD_LIBS -pthread"
+ ol_link_threads=posix
+ fi
+ fi
+
+ if test $ol_link_threads = no ; then
+ dnl try -thread
+ AC_CACHE_CHECK([for pthread_create with -thread],
+ [ol_cv_thread_flag], [
+ dnl save the flags
+ save_LIBS="$LIBS"
+ LIBS="-thread $LIBS"
+ AC_TRY_LINK([char pthread();],[
+ pthread_create();
+ ], ol_cv_thread_flag=yes, ol_cv_thread_flag=no)
+ dnl restore the LIBS
+ LIBS="$save_LIBS"
+ ])