SUMMARY="A standalone and lightweight BitTorrent tracker"
DESCRIPTION="Hefur is a standalone C++ BitTorrent tracker.

Features:
 - support HTTP, HTTPS and UPD announce and scrape
 - support both IPv4 and IPv6
 - no database required (everything in memory)
 - should be efficient
 - perfect for small setup
 - info_hash white list based on .torrent in a directory tree
 - control interface
 - control program: hefurctl"
HOMEPAGE="https://github.com/abique/hefur"
COPYRIGHT="2012 Alexandre Bique"
LICENSE="MIT"
REVISION="4"
SOURCE_URI="https://github.com/abique/hefur/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="ce693eb5f0410e47cd1f65906b77c9b0179eb807943119b900a8fa8f630d0d7b"
SOURCE_FILENAME="hefur-$portVersion.tar.gz"
PATCHES="hefur-$portVersion.patchset" # Merged upstream
srcGitRev2="22137aa7f90b0f90bc48172d964deb82d6e4f2f9"
SOURCE_URI_2="https://github.com/abique/mimosa/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="abe7992fd45d9a458ebc8786de750ebbe6b961076065f4b6f6f7a870d524fc29"
SOURCE_FILENAME_2="mimosa-$srcGitRev2.tar.gz"
SOURCE_DIR_2="mimosa-$srcGitRev2"
PATCHES_2="mimosa-$srcGitRev2.patchset" # Merged upstream

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

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ -z "${ARCHITECTURES##*!$targetArchitecture*}" ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

PROVIDES="
	hefur$secondaryArchSuffix = $portVersion
	cmd:hefurctl$commandSuffix = $portVersion
	cmd:hefurd$commandSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:liblzma$secondaryArchSuffix
	lib:libgnutls$secondaryArchSuffix
	lib:libnettle$secondaryArchSuffix
	lib:libprotobuf$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libarchive$secondaryArchSuffix
	devel:libgnutls$secondaryArchSuffix
	devel:liblzma$secondaryArchSuffix
	devel:libprotobuf$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	docbook_xsl_stylesheets
	cmd:bison$secondaryArchSuffix
	cmd:cc$secondaryArchSuffix
	cmd:cmake
	cmd:flex
	cmd:make
	cmd:protoc$secondaryArchSuffix
	cmd:xsltproc$secondaryArchSuffix
	"

TEST_REQUIRES="
	devel:libgtest$secondaryArchSuffix
	devel:libgtest_main$secondaryArchSuffix
	"
BUILD_REQUIRES+="$TEST_REQUIRES"

BUILD()
{
	cp -rt mimosa "$sourceDir2"/*

	cmake . \
		$cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_BINDIR=$commandBinDir \
		-DCMAKE_CXX_FLAGS="-D_BSD_SOURCE" \
		-DCMAKE_EXE_LINKER_FLAGS="-lnetwork -lgnu"
	make $jobArgs

	local systemData="$(finddir B_SYSTEM_DATA_DIRECTORY)"
	local docBookXsl=(
		$systemData/xml/docbook/xsl-stylesheets-*/html/docbook.xsl
		)
	cd manual
	xsltproc -o manual.html \
		"$docBookXsl" \
		manual.xml
}

INSTALL()
{
	make install
}

TEST()
{
	make check
}
