SUMMARY="UPnP IGD client lightweight library"
DESCRIPTION="The usage of the miniUPnP client library is useful whenever an \
application needs to listen for incoming connections.
Examples : P2P applications, FTP clients for active mode, IRC (for DCC)
or IM applications, network games, any server."
HOMEPAGE="http://miniupnp.free.fr/
	https://miniupnp.tuxfamily.org/"
COPYRIGHT="2005-2018 Thomas Bernard"
LICENSE="BSD (3-clause)"
REVISION="2"
SOURCE_URI="http://miniupnp.free.fr/files/miniupnpc-$portVersion.tar.gz
	https://miniupnp.tuxfamily.org/files/miniupnpc-$portVersion.tar.gz"
CHECKSUM_SHA256="e19fb5e01ea5a707e2a8cb96f537fbd9f3a913d53d804a3265e3aeab3d2064c6"
PATCHES="miniupnpc-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

libVersion="2.1"
libVersionCompat="$libVersion compat >= 2"

PROVIDES="
	miniupnpc$secondaryArchSuffix = $portVersion
	lib:libminiupnpc$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	miniupnpc${secondaryArchSuffix}_devel = $portVersion
	devel:libminiupnpc$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	miniupnpc$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	mkdir -p build && cd "$_"
	cmake \
		-DCMAKE_INSTALL_PREFIX=$prefix \
		-DCMAKE_BUILD_TYPE=release \
		-Wno-dev \
		-DUPNPC_BUILD_TESTS=OFF \
		-DUPNPC_BUILD_SAMPLE=OFF \
		..
	make $jobArgs
}

INSTALL()
{
	make -C build install

	mkdir -p $includeDir
	mv $prefix/include/* $includeDir
	rmdir $prefix/include

	if [ -n "$secondaryArchSuffix" ]; then
		mv $prefix/lib $prefix/lib2
		mkdir -p $libDir
		mv $prefix/lib2/* $libDir/
		rmdir $prefix/lib2
	fi
	prepareInstalledDevelLibs libminiupnpc
	packageEntries devel \
		$developDir
}

TEST()
{
	cd build
#	make check #currently broken
}
