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."
COPYRIGHT="1998-2016 The OpenLDAP Foundation"
HOMEPAGE="https://www.openldap.org/"
LICENSE="OpenLDAP Public License"
REVISION="2"
SOURCE_URI="ftp://ftp.openldap.org/pub/OpenLDAP/openldap-release/openldap-$portVersion.tgz"
CHECKSUM_SHA256="d9523ffcab5cd14b709fcf3cb4d04e8bc76bb8970113255f372bc74954c6074d"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

libVersion="2.10.11"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"
portVers="${portVersion%.*}"

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

PROVIDES="
	openldap$secondaryArchSuffix = $portVersion
	lib:liblber$secondaryArchSuffix = $libVersionCompat
	lib:liblber_$portVers$secondaryArchSuffix = $libVersionCompat
	lib:libldap$secondaryArchSuffix = $libVersionCompat
	lib:libldap_$portVers$secondaryArchSuffix = $libVersionCompat
	lib:libldap_r$secondaryArchSuffix = $libVersionCompat
	lib:libldap_r_$portVers$secondaryArchSuffix = $libVersionCompat
	"
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
	"

PROVIDES_devel="
	openldap${secondaryArchSuffix}_devel = $portVersion
	devel:liblber$secondaryArchSuffix = $libVersionCompat
	devel:liblber_$portVers$secondaryArchSuffix = $libVersionCompat
	devel:libldap$secondaryArchSuffix = $libVersionCompat
	devel:libldap_$portVers$secondaryArchSuffix = $libVersionCompat
	devel:libldap_r$secondaryArchSuffix = $libVersionCompat
	devel:libldap_r_$portVers$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	openldap$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:make
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:soelim
	"

defineDebugInfoPackage openldap$secondaryArchSuffix \
	"$libDir"/liblber-$portVers.so.$libVersion \
	"$libDir"/libldap-$portVers.so.$libVersion \
	"$libDir"/libldap_r-$portVers.so.$libVersion

PATCH()
{
	sed \
		-e 's/-\<lnet\>/&work/g' \
		-e 's/net, socket/network, socket/g' \
		-i configure.in
}

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

	rm $libDir/lib*.la

	prepareInstalledDevelLibs \
		liblber \
		liblber-$portVers \
		libldap \
		libldap-$portVers \
		libldap_r \
		libldap_r-$portVers

	mkdir -p $dataDir/openldap
	mv $settingsDir/openldap/ldap.conf.default $dataDir/openldap/

	if [ -z "$secondaryArchSuffix" ]; then
# On primary architectures: move man3 to devel package
		packageEntries devel $developDir $documentationDir/man/man3
	else
# On secondary architectures: delete binDir and documentationDir
		rm -rf $binDir $documentationDir
		packageEntries devel $developDir
	fi
}

TEST()
{
	make check
}
