SUMMARY="Open source LDAP suite of applications and development tools"
DESCRIPTION="The OpenLDAP Project is a collaborative effort to develop a \
robust, commercial-grade, fully featured, and open source LDAP suite of \
applications and development tools. The project is managed by a worldwide \
coummunity of volunteers that use the Internet to communicate, plan, and \
develop the OpenLDAP Suite and its related documentation."
HOMEPAGE="http://www.openldap.org/"
SOURCE_URI="ftp://ftp.openldap.org/pub/OpenLDAP/openldap-release/openldap-2.4.40.tgz"
CHECKSUM_SHA256="d12611a5c25b6499293c2bb7b435dc2b174db73e83f5a8cb7e34f2ce5fa6dadb"
REVISION="1"
LICENSE="OpenLDAP Public License"
COPYRIGHT="1998-2014 The OpenLDAP Foundation"

ARCHITECTURES="?x86_gcc2 x86 x86_64"
SECONDARY_ARCHITECTURES="?x86_gcc2 ?x86"

GLOBAL_WRITABLE_FILES="settings/openldap/ldap.conf keep-old"
USER_SETTINGS_FILES="
	settings/openldap/ldap.conf template data/openldap/ldap.conf.default
"

PATCH()
{
	sed -i 's/-lnet/-lnetwork/g' configure.in
	sed -i 's/net, socket/network, socket/g' configure.in
}

PROVIDES="
	openldap$secondaryArchSuffix = $portVersion
	lib:liblber$secondaryArchSuffix = 2.10.3
	lib:liblber_2.4$secondaryArchSuffix = 2.10.3
	lib:libldap$secondaryArchSuffix = 2.10.3
	lib:libldap_2.4$secondaryArchSuffix = 2.10.3
	lib:libldap_r$secondaryArchSuffix = 2.10.3
	lib:libldap_r_2.4$secondaryArchSuffix = 2.10.3
"

if [ -z "$secondaryArchSuffix" ]; then
	PROVIDES="$PROVIDES
		cmd:ldapadd
		cmd:ldapcompare
		cmd:ldapdelete
		cmd:ldapexop
		cmd:ldapmodify
		cmd:ldapmodrdn
		cmd:ldappasswd
		cmd:ldapsearch
		cmd:ldapurl
		cmd:ldapwhoami
	"
fi

REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
"

BUILD_PREREQUIRES="
	cmd:libtoolize
	cmd:aclocal
	cmd:autoconf
	cmd:make
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:soelim
"

BUILD()
{
	# TODO: openldap uses it's own variation of autotools
	libtoolize --force --copy --install
	aclocal
	autoconf
	runConfigure ./configure --enable-slapd=no --with-tls=openssl
	make $jobArgs depend
	make $jobArgs
}

INSTALL()
{
	make install
	
	prepareInstalledDevelLibs liblber liblber-2.4 libldap libldap-2.4 \
		libldap_r libldap_r-2.4
	
	mkdir -p $dataDir/openldap
	mv $settingsDir/openldap/ldap.conf.default $dataDir/openldap/
	
	packageEntries devel $developDir $documentationDir/man/man3
	
	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf $binDir
	fi
}

PROVIDES_devel="
	openldap${secondaryArchSuffix}_devel = $portVersion
	devel:liblber$secondaryArchSuffix = 2.10.3
	devel:liblber_2.4$secondaryArchSuffix = 2.10.3
	devel:libldap$secondaryArchSuffix = 2.10.3
	devel:libldap_2.4$secondaryArchSuffix = 2.10.3
	devel:libldap_r$secondaryArchSuffix = 2.10.3
	devel:libldap_r_2.4$secondaryArchSuffix = 2.10.3
"

REQUIRES_devel="
	openldap$secondaryArchSuffix == $portVersion base
"
