
dnl this is for kdm:

KDE_EXPAND_MAKEVAR(KDE_CONFDIR, kde_confdir)
AC_DEFINE_UNQUOTED(KDE_CONFDIR, "$KDE_CONFDIR", [KDE's configuration directory])
KDE_EXPAND_MAKEVAR(KDE_DATADIR, kde_datadir)
AC_DEFINE_UNQUOTED(KDE_DATADIR, "$KDE_DATADIR", [KDE's static data directory])
KDE_EXPAND_MAKEVAR(KDE_BINDIR, kde_bindir)
AC_DEFINE_UNQUOTED(KDE_BINDIR, "$KDE_BINDIR", [KDE's binaries directory])
AC_SUBST(KDE_BINDIR)

KDE_FIND_PATH(xmkmf, XMKMF, [], [AC_MSG_ERROR([xmkmf/imake not found. Please make sure it's in PATH!])])

dnl ask imake about various X settings
AC_MSG_CHECKING([X paths])
imkv=8
test "$kde_cv_defines_imake_version" = $imkv || unset kde_cv_defines_imake
AC_CACHE_VAL(kde_cv_defines_imake, [
  rm -fr conftestdir
  if mkdir conftestdir; then
    cd conftestdir
    cat > Imakefile <<'EOF'[

acimake:
	@echo "XBINDIR=\"$(BINDIR)\" XLIBDIR=\"$(LIBDIR)\""

]EOF
    if $XMKMF >&5 2>&1 && test -f Makefile; then
	kde_cv_defines_imake=`${MAKE-make} acimake 2> /dev/null | grep -v "^make"`
	kde_cv_defines_imake_version=$imkv
    else
        AC_MSG_RESULT([failed])
	AC_MSG_ERROR([$XMKMF (imake) failed.
Make sure you have all necessary X development packages installed.
On some systems a missing /lib/cpp symlink is at fault.])
    fi
    cd ..
    rm -fr conftestdir
  else
    AC_MSG_RESULT([failed])
    AC_MSG_ERROR([cannot create temporary directory])
  fi
])
AC_MSG_RESULT([done])
eval "$kde_cv_defines_imake"
AC_DEFINE_UNQUOTED(XBINDIR, "$XBINDIR", [X binaries directory])
AC_DEFINE_UNQUOTED(XLIBDIR, "$XLIBDIR", [X libraries directory])

if test -f /etc/ttys; then
  AC_DEFINE(BSD_INIT, 1, [Define if the system uses a BSD-style init])
fi

AC_CHECK_FUNCS([getttyent])
case $host_os in
	linux*) ac_cv_func_getutxent=no;;
	darwin*) ac_cv_func_getutxent=no;;
	*) AC_CHECK_FUNC([getutxent]);;
esac
if test $ac_cv_func_getutxent = yes; then
	AC_DEFINE(HAVE_UTMPX, 1, [Define if the system uses extended utmp])
else
	AC_CHECK_FUNC([getutent], ,
		[AC_DEFINE(BSD_UTMP, 1, [Define if the system has no getutent])])
fi

AC_CHECK_MEMBERS([struct utmp.ut_user], , , [#include <utmp.h>])
AC_CHECK_MEMBERS([struct passwd.pw_expire], , , [#include <pwd.h>])
AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , , [
#include <sys/socket.h>
#include <netinet/in.h>
])

ac_save_libs=$LIBS
LIBS="$LIBS $LIBUTIL"
AC_CHECK_FUNCS([setlogin setusercontext getusershell login_getclass auth_timeok])
LIBS=$ac_save_libs

dnl is getifaddrs always available without additional libs?
AC_CHECK_FUNCS([mkstemp setproctitle sysinfo strnlen getifaddrs])

AC_CHECK_FUNCS([arc4random], ,
	[
dnl assume that /dev/random is non-blocking if /dev/urandom does not exist
for i in urandom random; do
  if test -c /dev/$i; then
    AC_DEFINE_UNQUOTED(DEV_RANDOM, "/dev/$i", [Define the system's entropy device])
    break
  fi
done
	])

AC_CHECK_FUNC(vsyslog, [
  AC_DEFINE(USE_SYSLOG, 1, [Define if kdm should be built with syslog support])])

AC_CHECK_LIB(Xau, main, [:], 
	[
	  AC_MSG_WARN([Cannot build KDM! Make sure that libXau.a is installed!])
	  DO_NOT_COMPILE="$DO_NOT_COMPILE kdm"
	], 
	  $X_LDFLAGS -lX11 $LIBSOCKET)

AC_ARG_WITH(xdmcp,
        AC_HELP_STRING([--without-xdmcp],[build kdm without xdmcp support [default=with xdmcp]]), ,
	[with_xdmcp=yes])
if test "x$with_xdmcp" = xyes; then
  AC_CHECK_LIB(Xdmcp, main, [LIBXDMCP="-lXdmcp"], , $X_LDFLAGS -lX11 $LIBSOCKET)
  if test -n "$LIBXDMCP"; then
    cppflags_safe=$CPPFLAGS
    CPPFLAGS="$CPPFLAGS $X_INCLUDES"
    AC_CHECK_HEADER(X11/Xdmcp.h, [HAVE_X11_XDMCP_H=1], , [#include <X11/Xmd.h>])
    CPPFLAGS=$cppflags_safe
  fi
  if test -z "$HAVE_X11_XDMCP_H"; then
    AC_MSG_WARN([Cannot build KDM! Make sure that libXdmcp.a and Xdmcp.h 
are installed or use --without-xdmcp to disable XDMCP support!])
    DO_NOT_COMPILE="$DO_NOT_COMPILE kdm"
  fi
  AC_DEFINE(XDMCP, 1, [Define if kdm should be built with XDMCP support])
  ac_save_libs=$LIBS
  LIBS="$LIBS $LIBXDMCP"
  AC_CHECK_FUNC(XdmcpWrap, [
    AC_DEFINE(HASXDMAUTH, 1, [Define if kdm should be built with XDMAUTH support])
  ])
  LIBS=$ac_save_libs
fi
AC_SUBST(LIBXDMCP)

KRB4_INCS=
KRB4_LIBS=
KRB4_RPATH=

AC_MSG_CHECKING(whether to use Kerberos v4)
AC_ARG_WITH(krb4,
AC_HELP_STRING([--with-krb4=PATH],[Compile in Kerberos v4 support]),
[ test "x$with_krb4" = xyes && with_krb4=/usr/kerberos ],
[ with_krb4=no ]
)
case "$with_krb4" in
no)
  AC_MSG_RESULT(no)
  ;;
*)
  AC_MSG_RESULT(yes)
  AC_DEFINE_UNQUOTED(KRB4, 1, [define if you have Kerberos IV])
  KRB4_INCS="-I$with_krb4/include"
  KRB4_LIBS="-L$with_krb4/lib -lkrb -ldes"
  if test "$USE_RPATH" = "yes" ; then
    KRB4_RPATH="-R $with_krb4/lib"
  fi
  AC_CHECK_LIB(resolv, dn_expand, KRB4_LIBS="$KRB4_LIBS -lresolv")
  ;;
esac

AC_MSG_CHECKING(whether to use AFS)
AC_ARG_WITH(afs,
  AC_HELP_STRING([--with-afs],[Compile in AFS support (requires KTH krb4)]), , 
  [ with_afs=no ])
if test "$with_afs" = no; then
  AC_MSG_RESULT(no)
else
  if test "$with_krb4" = no; then
    AC_MSG_RESULT(no)
    AC_MSG_WARN("AFS requires Kerberos v4 support.")
    with_afs=no
  else
    AC_MSG_RESULT(yes)
    AC_DEFINE_UNQUOTED(AFS, 1, [define if you have KTH Kerberos IV and AFS])
    KRB4_LIBS="$KRB4_LIBS -lkafs"
    if test -n "$os_aix"; then
      KRB4_LIBS="$KRB4_LIBS -lld"
    fi
  fi
fi

AC_SUBST(KRB4_INCS)
AC_SUBST(KRB4_LIBS)
AC_SUBST(KRB4_RPATH)

AC_CHECK_LIB(s, main, [LIB_LIBS="-ls"]) dnl for AIX
AC_SUBST(LIB_LIBS)

AC_CHECK_LIB(posix4, sched_yield, [LIBPOSIX4=-lposix4])
AC_SUBST(LIBPOSIX4)

KRB5_INCS=
KRB5_LIBS=
KRB5_RPATH=

AC_MSG_CHECKING([whether to use Kerberos5 for Xauth cookies in kdm])
AC_ARG_WITH(krb5auth,
  AC_HELP_STRING([--with-krb5auth=PATH],[Use Kerberos5 for Xauth cookies in kdm]), ,
  [ with_krb5auth=no ])
if test "x$with_krb5auth" = xno; then
  AC_MSG_RESULT(no)
else
  AC_MSG_RESULT(yes)
  if test "x$with_krb5auth" != xyes; then
    KRB5_INCS="-I$with_krb5auth/include"
    KRB5_LIBS="-L$with_krb5auth/lib"
    if test "$USE_RPATH" = "yes" ; then
      KRB5_RPATH="-R $with_krb5auth/lib"
    fi
  fi
  KRB5_LIBS="$KRB5_LIBS -lkrb5" dnl -lk5crypto -lcom_err -lresolv
  keepcflags=$CFLAGS
  CFLAGS="$KRB5_INCS $CFLAGS"
  AC_CHECK_HEADER(krb5/krb5.h, 
    [ AC_DEFINE(K5AUTH, 1, [Define if kdm should use Kerberos 5 for Xauth cookies.]) ],
    [ AC_MSG_ERROR([--with-krb5auth requires Kerberos5 header files.
Due to a problem with X includes you probably have to run "ln -s . krb5"
in the directory where the krb5.h include resides to make things actually work.])])
  CFLAGS="$keepcflags"
fi

AC_SUBST(KRB5_INCS)
AC_SUBST(KRB5_LIBS)
AC_SUBST(KRB5_RPATH)

AC_MSG_CHECKING([whether to use Sun's secure RPC for Xauth cookies in kdm])
AC_ARG_WITH(rpcauth,
  AC_HELP_STRING([--with-rpcauth],[Use Sun's secure RPC for Xauth cookies in kdm.]), , 
  [ with_rpcauth=no ])
if test "x$with_rpcauth" = xno; then
  AC_MSG_RESULT(no)
else
  AC_MSG_RESULT(yes)
  AC_CHECK_HEADER(rpc/rpc.h, 
    [ AC_DEFINE(SECURE_RPC, 1, [Define if kdm should use Sun's secure RPC for Xauth cookies.]) ],
    [ AC_MSG_ERROR([--with-rpcauth requires Sun RPC header files.])])
fi

if test "x$use_pam" = xyes; then
    AC_DEFINE(USE_PAM, 1, [Define if kdm should use PAM])
elif test "x$use_shadow" = xyes; then
    AC_DEFINE(USESHADOW, 1, [Define if kdm should use shadow passwords])
fi
if test "x$with_krb4" != xno; then
    AC_DEFINE(KERBEROS, 1, [Define if kdm should use Kerberos IV])
    if test "x$with_afs" = xno; then
        AC_DEFINE(NO_AFS, 1, [Define if kdm should not use AFS])
    fi
fi

AC_ARG_WITH(kdm-xconsole,
	AC_HELP_STRING([--with-kdm-xconsole],[build kdm with built-in xconsole [default=no]]), ,
	[with_kdm_xconsole=no])
if test "x$with_kdm_xconsole" = xyes; then
    AC_DEFINE(WITH_KDM_XCONSOLE, 1, [Build kdm with built-in xconsole])
fi

dnl AC_OUTPUT(kdm/kfrontend/sessions/kde.desktop)
