dnl Process this file with autoconf to produce a configure script.
AC_INIT
AM_INIT_AUTOMAKE(shadow, 4.0.6)
AC_CONFIG_HEADERS([config.h])

dnl Some hacks...
test "$prefix" = "NONE" && prefix="/usr"
test "$prefix" = "/usr" && exec_prefix=""

AM_DISABLE_SHARED
AM_ENABLE_STATIC

AM_MAINTAINER_MODE

dnl Checks for programs.
AC_PROG_CC
AC_ISC_POSIX
AC_PROG_LN_S
AC_PROG_YACC
AM_C_PROTOTYPES
AM_PROG_LIBTOOL

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT

AC_CHECK_HEADERS(errno.h fcntl.h limits.h unistd.h sys/time.h utmp.h \
	utmpx.h termios.h termio.h sgtty.h sys/ioctl.h syslog.h paths.h \
	utime.h ulimit.h sys/resource.h gshadow.h shadow.h lastlog.h \
	locale.h rpc/key_prot.h)

AC_CHECK_FUNCS(a64l fchmod fchown fsync getgroups gethostname getspnam \
	gettimeofday getusershell getutent initgroups lchown lckpwdf lstat \
	memcpy memset setgroups sigaction strchr updwtmp updwtmpx)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_UID_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_MODE_T
AC_HEADER_STAT
AC_CHECK_MEMBERS([struct stat.st_rdev])
AC_HEADER_TIME
AC_STRUCT_TM

if test "$ac_cv_header_utmp_h" = "yes"; then
	AC_CACHE_CHECK(for ut_host in struct utmp,
		ac_cv_struct_utmp_ut_host,
		AC_COMPILE_IFELSE(
			[AC_LANG_PROGRAM([#include <utmp.h>],
				[struct utmp ut; char *cp = ut.ut_host;]
			)],
			[ac_cv_struct_utmp_ut_host=yes],
			[ac_cv_struct_utmp_ut_host=no]
		)
	)

	if test "$ac_cv_struct_utmp_ut_host" = "yes"; then
		AC_DEFINE(UT_HOST)
	fi

	AC_CACHE_CHECK(for ut_user in struct utmp,
		ac_cv_struct_utmp_ut_user,
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <utmp.h>],
				[struct utmp ut; char *cp = ut.ut_user;]
			)],
			[ac_cv_struct_utmp_ut_user=yes],
			[ac_cv_struct_utmp_ut_user=no]
		)
	)

	if test "$ac_cv_struct_utmp_ut_user" = "no"; then
		AC_DEFINE(ut_user, ut_name)
	fi
fi

if test "$ac_cv_header_lastlog_h" = "yes"; then
	AC_CACHE_CHECK(for ll_host in struct lastlog,
		ac_cv_struct_lastlog_ll_host,
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <lastlog.h>],
					[struct lastlog ll; char *cp = ll.ll_host;]
				)],
			[ac_cv_struct_lastlog_ll_host=yes],
			[ac_cv_struct_lastlog_ll_host=no]
		)
	)

	if test "$ac_cv_struct_lastlog_ll_host" = "yes"; then
		AC_DEFINE(HAVE_LL_HOST)
	fi
fi

dnl Checks for library functions.
AC_TYPE_GETGROUPS
AC_PROG_GCC_TRADITIONAL
AC_TYPE_SIGNAL
AC_FUNC_UTIME_NULL
AC_FUNC_STRFTIME
AC_REPLACE_FUNCS(mkdir putgrent putpwent putspent rename rmdir)
AC_REPLACE_FUNCS(sgetgrent sgetpwent sgetspent)
AC_REPLACE_FUNCS(snprintf strcasecmp strdup strerror strstr)

AC_CHECK_FUNC(setpgrp)
AC_FUNC_SETPGRP

if test "$ac_cv_header_shadow_h" = "yes"; then
AC_CACHE_CHECK(for working shadow group support,
	ac_cv_libc_shadowgrp,
	AC_RUN_IFELSE([AC_LANG_SOURCE([
			#include <shadow.h>
			main()
			{
				struct sgrp *sg = sgetsgent("test:x::");
				/* NYS libc on Red Hat 3.0.3 has broken shadow group support */
				return !sg || !sg->sg_adm || !sg->sg_mem;
			}]
		)],
		[ac_cv_libc_shadowgrp=yes],
		[ac_cv_libc_shadowgrp=no],
		[ac_cv_libc_shadowgrp=no]
	)
)

if test "$ac_cv_libc_shadowgrp" = "yes"; then
	AC_DEFINE(HAVE_SHADOWGRP)
fi
fi

AC_CACHE_CHECK([location of shared mail directory], shadow_cv_maildir,
[for shadow_cv_maildir in /var/mail /var/spool/mail /usr/spool/mail /usr/mail none; do
	if test -d $shadow_cv_maildir; then
		break
	fi
done])
if test $shadow_cv_maildir != none; then
	AC_DEFINE_UNQUOTED(MAIL_SPOOL_DIR, "$shadow_cv_maildir")
fi

AC_CACHE_CHECK([location of user mail file], shadow_cv_mailfile,
[for shadow_cv_mailfile in Mailbox mailbox Mail mail .mail none; do
	if test -f $HOME/$shadow_cv_mailfile; then
		break
	fi
done])
if test $shadow_cv_mailfile != none; then
	AC_DEFINE_UNQUOTED(MAIL_SPOOL_FILE, "$shadow_cv_mailfile")
fi

AC_CACHE_CHECK([location of utmp], shadow_cv_utmpdir,
[for utmpdir in /var/run /var/adm /usr/adm /etc none; do
	if test -f $shadow_cv_utmpdir/utmp; then
		break
	fi
done])
if test "$shadow_cv_utmpdir" = "none"; then
	AC_MSG_WARN(utmp file not found)
fi
AC_DEFINE_UNQUOTED(_UTMP_FILE, "$shadow_cv_utmpdir/utmp")

AC_CACHE_CHECK([location of faillog/lastlog/wtmp], shadow_cv_logdir,
[for shadow_cv_logdir in /var/log /var/adm /usr/adm /etc; do
	if test -d $logdir; then
		break
	fi
done])
AC_DEFINE_UNQUOTED(_WTMP_FILE, "$shadow_cv_logdir/wtmp")
AC_DEFINE_UNQUOTED(LASTLOG_FILE, "$shadow_cv_logdir/lastlog")
AC_DEFINE_UNQUOTED(FAILLOG_FILE, "$shadow_cv_logdir/faillog")

AC_CACHE_CHECK([location of the passwd program], shadow_cv_passwd_dir,
[if test -f /usr/bin/passwd; then
	shadow_cv_passwd_dir=/usr/bin
else
	shadow_cv_passwd_dir=/bin
fi])
AC_DEFINE_UNQUOTED(PASSWD_PROGRAM, "$shadow_cv_passwd_dir/passwd")

dnl XXX - quick hack, should disappear before anyone notices :).
AC_DEFINE(SHADOWPWD)
AC_DEFINE(USG)
AC_DEFINE(USE_SYSLOG)
AC_DEFINE(RLOGIN)
AC_DEFINE(RUSEROK, 0)

dnl Use our own version of getpass(), which handles long passwords
dnl (unlike many systems which have a limit of 8 characters), and can
dnl be interrupted with Ctrl-C (unlike Linux libc).
AC_DEFINE(getpass, libshadow_getpass)

AC_ARG_ENABLE(desrpc, [  --enable-desrpc         try to use secure RPC in login (default if found)])
AC_ARG_ENABLE(shadowgrp, [  --enable-shadowgrp      enable shadow group support [default=yes]])

AC_ARG_WITH(libcrack, [  --with-libcrack	try to use libcrack (default if found)])
AC_ARG_WITH(libcrypt, [  --with-libcrypt	try to use libcrypt (default if found)])
AC_ARG_WITH(libopie,  [  --with-libopie		use libopie for OPIE support])
AC_ARG_WITH(libpam,   [  --with-libpam 		use libpam for PAM support])
AC_ARG_WITH(libskey,  [  --with-libskey		use libskey for S/Key support])
AC_ARG_WITH(selinux,  [  --with-selinux		use SELinux support])

dnl Check for some functions in libc first, only if not found check for
dnl other libraries.  This should prevent linking libnsl if not really
dnl needed (Linux glibc, Irix), but still link it if needed (Solaris).

AC_SEARCH_LIBS(inet_ntoa, inet)
AC_SEARCH_LIBS(socket, socket)
AC_SEARCH_LIBS(gethostbyname, nsl)

dnl XXX - getsecretkey() causes login to hang for 5 minutes on at least
dnl one RH 4.0 system.  Use --disable-desrpc if you have this problem.
dnl Reported by Mohan Khurana <mohan@stealth.net>.

if test "$enable_desrpc" != "no" -a "$ac_cv_header_rpc_key_prot_h" = "yes" ; then
	AC_CHECK_FUNC(getsecretkey, AC_DEFINE(DES_RPC),
		AC_CHECK_LIB(rpcsvc, getsecretkey, AC_DEFINE(DES_RPC)))
fi

if test "$enable_shadowgrp" != "no"; then
	AC_DEFINE(SHADOWGRP)
fi

AC_SUBST(LIBCRYPT)
if test "$with_libcrypt" != "no"; then
	AC_CHECK_LIB(crypt, crypt, [AC_DEFINE(HAVE_LIBCRYPT) LIBCRYPT=-lcrypt])
fi

AC_SUBST(LIBCRACK)
if test "$with_libcrack" != "no"; then
	echo "checking cracklib flavour, don't be surprised by the results"
	AC_CHECK_LIB(crack, FascistCheck, AC_DEFINE(HAVE_LIBCRACK) LIBCRACK=-lcrack)
	AC_CHECK_LIB(crack, FascistHistory, AC_DEFINE(HAVE_LIBCRACK_HIST))
	AC_CHECK_LIB(crack, FascistHistoryPw, AC_DEFINE(HAVE_LIBCRACK_PW))
fi

AC_SUBST(LIBSKEY)
AC_SUBST(LIBMD)
if test "$with_libskey" = "yes"; then
	AC_CHECK_LIB(md, MD5Init, LIBMD=-lmd)
	AC_CHECK_LIB(skey, skeychallenge, AC_DEFINE(SKEY) LIBSKEY=-lskey, [], $LIBMD $LIBCRYPT)
elif test "$with_libopie" = "yes"; then
	AC_CHECK_LIB(opie, opiechallenge, AC_DEFINE(OPIE) LIBSKEY=-lopie, [], $LIBCRYPT)
fi

if test "$with_selinux" = "yes"; then
	AC_CHECK_LIB(selinux, is_selinux_enabled, [LIBSELINUX="-lselinux"], [SELinuux enabled but libselinux not found])
	AC_SUBST(LIBSELINUX)
	AC_CHECK_HEADERS(selinux/selinux.h, [], [selinux/selinux.h is missing])
	AC_DEFINE(WITH_SELINUX, 1, [Build shadow with SELinux support])
fi

AC_SUBST(LIBPAM)
if test "$with_libpam" = "yes"; then
	AC_CHECK_LIB(pam, pam_start,
		[AC_DEFINE(USE_PAM, 1, [Define to support Pluggable Authentication Modules])
		LIBPAM="-lpam"
		AC_CHECK_LIB(pam_misc, main,
			[LIBPAM="$LIBPAM -lpam_misc"],
			AC_MSG_ERROR(libpam_misc is missing)
		)]
		[AC_MSG_CHECKING(use login access checking if PAM not used)
		AC_DEFINE(LOGIN_ACCESS)
		AC_MSG_RESULT(yes)]
	)
	AC_MSG_CHECKING(use login and su access checking if PAM not used)
	AC_MSG_RESULT(no)
else
	AC_MSG_CHECKING(use login and su access checking if PAM not used)
	AC_DEFINE(LOGIN_ACCESS)
	AC_DEFINE(SU_ACCESS)
	AC_MSG_RESULT(yes)
fi

AM_GNU_GETTEXT_VERSION(0.12.1)
AM_GNU_GETTEXT([external])
AC_DEFINE_UNQUOTED(LOCALEDIR, "${datadir}/locale", [locale directory])

AC_CONFIG_FILES([
	Makefile
	po/Makefile.in
	doc/Makefile
	man/Makefile
	man/cs/Makefile
	man/de/Makefile
	man/es/Makefile
	man/fr/Makefile
	man/hu/Makefile
	man/id/Makefile
	man/it/Makefile
	man/ja/Makefile
	man/ko/Makefile
	man/pl/Makefile
	man/pt_BR/Makefile
	man/ru/Makefile
	man/zh_CN/Makefile
	man/zh_TW/Makefile
	libmisc/Makefile
	lib/Makefile
	src/Makefile
	contrib/Makefile
	etc/Makefile
	etc/pam.d/Makefile
	shadow.spec
])
AC_OUTPUT
