dnl Process this file with autoconf to produce a configure script.
AC_INIT(pam_unix2, 2.4.1, http://www.suse.de/feedback, pam_unix2)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/support.c])
AM_CONFIG_HEADER(config.h)
AC_PREFIX_DEFAULT(/usr)

dnl Set of available languages.

dnl Some hacks for correct paths ...
test "${prefix}" = "NONE" && prefix="/usr"
if test ${prefix} = '/usr'
then
dnl If we use /usr as prefix, use /etc for sysconfdir
        if test ${sysconfdir} = '${prefix}/etc'
        then
           sysconfdir="/etc"
        fi
dnl Change libdir to /lib
	if test ${libdir} = '${exec_prefix}/lib'
	then
	  libdir='/lib'
	fi
dnl If we use /usr as prefix, use /usr/share/man for manual pages
        if test ${mandir} = '${prefix}/man'
        then
           mandir='${prefix}/share/man'
        fi
fi

dnl Try to set usefull CFLAGS
test "$CFLAGS" = "" && CFLAGS="-O2 -Wall"
CFLAGS="$CFLAGS -fPIC -DPIC"

dnl Check for programs
AC_PROG_CC
AC_PROG_MAKE_SET
AC_PROG_INSTALL

AC_GNU_SOURCE

AC_SEARCH_LIBS(crypt, xcrypt crypt)
AC_CHECK_LIB(dl, dlerror)
AC_CHECK_LIB(nsl, yp_get_default_domain)
AC_CHECK_LIB(pam, pam_start)

dnl Should we compile with SELinux support? default: yes
AC_ARG_ENABLE([selinux],
   AC_HELP_STRING([--disable-selinux],[Enable SELinux support (default=yes)]),
   WITH_SELINUX=$enableval, WITH_SELINUX=yes)
if test "$WITH_SELINUX" == "yes" ; then
   AC_CHECK_LIB(selinux,is_selinux_enabled,
        [AC_DEFINE(WITH_SELINUX,1,
                [Define if you want to compile in SELinux support])
         LIBS="$LIBS -lselinux"])
fi

dnl Check standard headers
AC_HEADER_STDC
AC_CHECK_HEADERS(xcrypt.h crypt.h)
AC_CHECK_HEADERS(stdlib.h pwd.h sys/types.h syslog.h sys/syslog.h string.h strings.h, , AC_MSG_ERROR(some basic headers are missing))
AC_CHECK_HEADERS(security/pam_appl.h security/pam_modules.h, , AC_MSG_ERROR(broken libpam installation))

dnl Check for Linux-PAM 0.99.x
AC_CHECK_HEADERS(security/pam_ext.h)
AC_CHECK_FUNCS(pam_vprompt pam_prompt pam_syslog)

AC_CHECK_HEADERS([sys/xattr.h attr/xattr.h],[break])
if test x$ac_cv_header_attr_xattr_h = xyes
then
  AC_CHECK_LIB(attr, main)
fi
AC_CHECK_FUNCS(llistxattr lgetxattr lsetxattr)

dnl Various function checking
AC_CHECK_FUNCS(fprintf snprintf syslog strncmp, , AC_MSG_ERROR(some basic C functions cannot be found))
AC_CHECK_FUNCS(getline getdelim)

dnl Function check for blowfish crypt
AC_CHECK_FUNCS(crypt crypt_r crypt_rn crypt_gensalt_rn bigcrypt)

dnl Check against -G linker flag
hold_ldflags=$LDFLAGS
AC_MSG_CHECKING(for the ld -shared flag)
LDFLAGS="${LDFLAGS} -shared"
AC_TRY_LINK([#include <stdio.h>], [void blahblah(){fprintf(stderr, "");}],
found=yes, found=no)
LDFLAGS=$hold_ldflags
AC_MSG_RESULT($found)
if test "$found" = "yes"; then
  LDFLAGS="${LDFLAGS} -shared"
else
  LDFLAGS="${LDFLAGS} -G"
fi

AM_GNU_GETTEXT_VERSION
AM_GNU_GETTEXT([external])

AC_SUBST(LIBPAM)

AC_OUTPUT([doc/Makefile etc/Makefile src/Makefile Makefile po/Makefile.in
	m4/Makefile])
