SUMMARY="A cross-platform open source BitTorrent client"
DESCRIPTION="Transmission has the features you want from a BitTorrent client: \
encryption, a web interface, peer exchange, magnet links, DHT, µTP, UPnP and \
NAT-PMP port forwarding, webseed support, watch directories, tracker editing, \
global and per-torrent speed limits, and more."
HOMEPAGE="https://www.transmissionbt.com/"
COPYRIGHT="2005-2020 Transmission authors and contributors
	2015-2018 Sandro Tos
	2001-2004 Unicode, Inc
	2006-2010 JSON.org
	2007-2016 Mnemosyne LLC
	2009-2011 Juliusz Chroboczek
	2005-2011, Thomas BERNARD
	2010 BitTorrent, Inc.
	2009 Nokia Corporation
	Chris Venter
	Matthieu James
	"
LICENSE="Transmission
	MIT
	GNU GPL v2"
REVISION="2"
SOURCE_URI="https://github.com/transmission/transmission-releases/raw/master/transmission-$portVersion.tar.xz"
CHECKSUM_SHA256="9144652fe742f7f7dd6657716e378da60b751aaeda8bef8344b3eefc4db255f2"
PATCHES="transmission-$portVersion.patchset"
ADDITIONAL_FILES="
	transmission.rdef.in
	userlaunch.in
	"

ARCHITECTURES="all !x86_gcc2"
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
fi

transmissionUserHomeDir="$dataDir"/transmission/empty
PACKAGE_USERS="
	transmissiond real-name \"transmission user\" home \"$transmissionUserHomeDir\" shell \"/bin/true\"
	"
PACKAGE_GROUPS="transmissiond"

PROVIDES="
	transmission$secondaryArchSuffix = $portVersion
	app:Transmission
	cmd:Transmission$secondaryArchSuffix
	cmd:transmission_cli$secondaryArchSuffix
	cmd:transmission_create$secondaryArchSuffix
	cmd:transmission_daemon$secondaryArchSuffix
	cmd:transmission_edit$secondaryArchSuffix
	cmd:transmission_remote$secondaryArchSuffix
	cmd:transmission_show$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libdht$secondaryArchSuffix
	lib:libevent_2.1$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libminiupnpc$secondaryArchSuffix
	lib:libnatpmp$secondaryArchSuffix >= 1
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5DBus$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcurl$secondaryArchSuffix
	devel:libdht$secondaryArchSuffix
	devel:libevent_2.1$secondaryArchSuffix
	devel:libgettextlib$secondaryArchSuffix >= 0.14.1
	devel:libiconv$secondaryArchSuffix
	devel:libminiupnpc$secondaryArchSuffix
	devel:libnatpmp$secondaryArchSuffix >= 1
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5DBus$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:cmake
	cmd:curl
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5.11
	cmd:make
	cmd:patch
	cmd:pkg_config$secondaryArchSuffix
	cmd:tar
	"

defineDebugInfoPackage transmission$secondaryArchSuffix \
	"$appsDir"/Transmission \
	"$binDir"/transmission-cli \
	"$binDir"/transmission-create \
	"$binDir"/transmission-daemon \
	"$binDir"/transmission-edit \
	"$binDir"/transmission-remote \
	"$binDir"/transmission-show

BUILD()
{
	mkdir -p build
	cd build
	cmake \
		$cmakeDirArgs \
		-DENABLE_QT=ON \
		-DENABLE_DAEMON=ON \
		-DENABLE_CLI=ON \
		-DUSE_SYSTEM_DHT=ON \
		-DUSE_SYSTEM_EVENT2=ON \
		-DUSE_SYSTEM_MINIUPNPC=ON \
		-DUSE_SYSTEM_NATPMP=ON \
		-DWITH_CRYPTO=openssl \
		-DENABLE_TESTS=OFF \
		..
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	# Cleanup
	rm -rf $dataDir/applications
	mkdir -p $appsDir
	mv $binDir/transmission-qt $binDir/Transmission
	ln -s $binDir/Transmission $appsDir/Transmission

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
#	local MINOR="`echo "$portVersion" | cut -d. -f3`" # not used currently
	local MINOR="0"
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/transmission.rdef.in > transmission.rdef

	addResourcesToBinaries transmission.rdef \
		$appsDir/Transmission

	mimeset -f $appsDir/Transmission

	addAppDeskbarSymlink $appsDir/Transmission

	mkdir -p $dataDir/user_launch
	sed \
		-e "s|@APP@|transmission-daemon|" \
		-e "s|@BIN@|"$binDir"/transmission-daemon$secondaryArchSuffix|" \
		$portDir/additional-files/userlaunch.in > \
			$dataDir/user_launch/Transmission
}

TEST()
{
	cd build
	make test
}
