AC_INIT(mod_ldap_userdir.c)

AC_ARG_WITH(apxs,
	[AS_HELP_STRING(
		[--with-apxs],
		[Path to Apache's apxs command (version 1.3.x or 2.0.x)]
	)],
	APXS=$withval)
AC_ARG_WITH(activate,
	[AS_HELP_STRING(
		[--with-activate],
		[Activate mod_ldap_userdir in httpd.conf]
	)],
	test "$withval" != no && ACTIVATE=-a
)
AC_ARG_WITH(sdk-headers,
	[AS_HELP_STRING(
		[--with-sdk-headers],
		[Specify the path to the LDAP SDK header files]
	)],
	[CPPFLAGS="-I$withval"]
)
AC_ARG_WITH(sdk-libdir,
	[AS_HELP_STRING(
		[--with-sdk-libdir],
		[Specify the path to the LDAP SDK libraries]
	)],
	[LDFLAGS="-L$withval"]
)

AC_PROG_CC
dnl We need to reset CFLAGS after AC_PROG_CC sets it. apxs will provide
dnl its own CFLAGS and gets confused when we try to feed ours to it.
CFLAGS=

if test -z "$APXS" || test "$APXS" = yes; then
	APXS=apxs
	for location in /usr/local/apache/bin/apxs \
		/usr/local/apache2/bin/apxs /opt/csw/apache2/sbin/apxs; do

		if test -e $location; then
			APXS=$location
		fi
	done
fi

AC_MSG_CHECKING(whether apxs works)
if $APXS -q CFLAGS >/dev/null; then
	AC_MSG_RESULT(yes)
else
	AC_MSG_RESULT(no)
	AC_MSG_ERROR(Cannot build mod_ldap_userdir without a valid apxs program)
fi

AC_CHECK_LIB(lber, ber_init)
AC_CHECK_LIB(ldap, ldap_init,
	found_openldap_libs=yes; LIBS="-lldap $LIBS",
	AC_MSG_ERROR(You must have libldap to build mod_ldap_userdir.)
)

AC_CHECK_HEADERS(lber.h, ,
	AC_MSG_ERROR(You must have lber.h to build mod_ldap_userdir.)
)
AC_CHECK_HEADERS(ldap.h, ,
	AC_MSG_ERROR(You must have ldap.h to build mod_ldap_userdir.),
	[#include <lber.h>]
)

AC_CHECK_MEMBER(LDAPURLDesc.lud_scheme,
	[AC_DEFINE(HAVE_LDAPURLDESC_LUD_SCHEME, 1, [Define if your LDAPURLDesc has a lud_scheme member.])], ,
	[#include <lber.h>
#include <ldap.h>])

AC_ARG_ENABLE([tls],
	[AS_HELP_STRING(
		[--disable-tls],
		[Don't build with LDAP TLS support]
	)],
	[enable_tls=$enableval],
	[enable_tls=yes]
)
AS_IF([test "x$enable_tls" != xno],
	[AC_CHECK_FUNC(ldap_start_tls_s, TLS=-DTLS)]
)

AC_SUBST(APXS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(LIBS)
AC_SUBST(TLS)
AC_SUBST(ACTIVATE)

AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile)
