SUMMARY="A library for IM communication"
DESCRIPTION="libpurple is a library for IM communication used by many open \
source IM clients. It implements a variety of protocols, for example IRC, \
Jabber or ICQ."
HOMEPAGE="https://pidgin.im/"
COPYRIGHT="1998-2021 Rob Flynn et al."
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="http://downloads.sourceforge.net/project/pidgin/Pidgin/$portVersion/pidgin-$portVersion.tar.bz2"
CHECKSUM_SHA256="3f8085c0211c4ca1ba9f8a03889b3d60738432c1673b57b0086070ef6e094cca"
SOURCE_DIR="pidgin-$portVersion"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

libVersion=0.14.8
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	libpurple$secondaryArchSuffix = $portVersion
	lib:libjabber$secondaryArchSuffix = 0.0.0 compat >= 0
	lib:libpurple$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libffi$secondaryArchSuffix
	lib:libfreebl3$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgmodule_2.0$secondaryArchSuffix
	lib:libgnt$secondaryArchSuffix
	lib:libgobject_2.0$secondaryArchSuffix
	lib:libgthread_2.0$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libidn$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libncursesw$secondaryArchSuffix
	lib:libnspr4$secondaryArchSuffix
	lib:libnss3$secondaryArchSuffix
	lib:libnssckbi$secondaryArchSuffix
	lib:libnssdbm3$secondaryArchSuffix
	lib:libnssutil3$secondaryArchSuffix
	lib:libpanelw$secondaryArchSuffix
#	lib:libperl
	lib:libsmime3$secondaryArchSuffix
	lib:libsoftokn3$secondaryArchSuffix
	lib:libpython3.7m$secondaryArchSuffix
	lib:libsasl2$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libssl3$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	libpurple${secondaryArchSuffix}_devel = $portVersion
	devel:libpurple$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	haiku${secondaryArchSuffix}_devel
	libpurple$secondaryArchSuffix == $portVersion base
	"

PROVIDES_finch="
	libpurple${secondaryArchSuffix}_finch = $portVersion
	cmd:finch$secondaryArchSuffix
	"
REQUIRES_finch="
	haiku${secondaryArchSuffix}
	libpurple$secondaryArchSuffix == $portVersion base
	lib:libffi$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgmodule_2.0$secondaryArchSuffix
	lib:libgnt$secondaryArchSuffix
	lib:libgobject_2.0$secondaryArchSuffix
	lib:libgthread_2.0$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libidn$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libpanelw$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfreebl3$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgmodule_2.0$secondaryArchSuffix
	devel:libgnt$secondaryArchSuffix
	devel:libgobject_2.0$secondaryArchSuffix
	devel:libgthread_2.0$secondaryArchSuffix
	devel:libidn$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	devel:libnspr4$secondaryArchSuffix
	devel:libnss3$secondaryArchSuffix
	devel:libnssckbi$secondaryArchSuffix
	devel:libnssdbm3$secondaryArchSuffix
	devel:libnssutil3$secondaryArchSuffix
	devel:libsmime3$secondaryArchSuffix
	devel:libsoftokn3$secondaryArchSuffix
	devel:libpython3.7m$secondaryArchSuffix
	devel:libsasl2$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libssl3$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:autoreconf
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:gettext
	cmd:intltool_update
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

PATCH()
{
	sed -i 's/resolv/network/g' configure.ac
}

defineDebugInfoPackage libpurple$secondaryArchSuffix \
	"$libDir"/libpurple.so.$libVersion

BUILD()
{
	autoreconf -vfi
	CPPFLAGS="-D_BSD_SOURCE" \
	LIBS="-lbsd" \
	runConfigure ./configure \
		--disable-avahi \
		--disable-dbus \
		--disable-dependency-tracking \
		--disable-gnutls \
		--disable-gstreamer \
		--disable-gtkui \
		--disable-meanwhile \
		--disable-schemas-install \
		--disable-screensaver \
		--disable-tcl \
		--disable-vv \
		--enable-consoleui \
		--enable-cyrus-sasl \
		--with-nspr-includes=$(finddir B_SYSTEM_HEADERS_DIRECTORY)/${secondaryArchSubDir} \
		--with-nspr-libs=$(finddir B_SYSTEM_LIB_DIRECTORY)/${secondaryArchSubDir} \
		--with-nss-includes=$(finddir B_SYSTEM_HEADERS_DIRECTORY)/${secondaryArchSubDir}/nss \
		--with-nss-libs=$(finddir B_SYSTEM_LIB_DIRECTORY)/${secondaryArchSubDir} \
		--with-ncurses-headers=$(finddir B_SYSTEM_HEADERS_DIRECTORY)/${secondaryArchSubDir} \
		--with-system-ssl-certs=$(finddir B_SYSTEM_DATA_DIRECTORY)/ssl/certs \
		--with-python3=$(finddir B_SYSTEM_HEADERS_DIRECTORY)/python3.7m
	make $jobArgs
}

INSTALL()
{
	make install
	cd pidgin/pixmaps/
	make install

	rm -rf $prefix/share
	rm -f \
		$libDir/finch/*.la \
		$libDir/gnt/*.la \
		$libDir/purple-2/*.la \
		$libDir/lib*.la

	ln -s $libDir/purple-2/libjabber.so.0.0.0 $libDir/libjabber.so.0

	prepareInstalledDevelLib libpurple
	fixPkgconfig

	packageEntries devel \
		$developDir

	packageEntries finch \
		$binDir \
		$manDir
}

TEST()
{
	make check
}
