SUMMARY="A download utility with segmented downloading and BitTorrent support"
DESCRIPTION="aria2 is a utility for downloading files. The supported \
protocols are HTTP(S), FTP, BitTorrent, and Metalink. aria2 can download a \
file from multiple sources/protocols and tries to utilize your maximum \
download bandwidth. It supports downloading a file from HTTP(S)/FTP and \
BitTorrent at the same time, while the data downloaded from HTTP(S)/FTP \
is uploaded to the BitTorrent swarm. Using Metalink's chunk checksums, \
aria2 automatically validates chunks of data while downloading a file like \
BitTorrent."
HOMEPAGE="https://aria2.github.io/"
COPYRIGHT="2006-2018 Tatsuhiro Tsujikawa"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/aria2/aria2/releases/download/release-$portVersion/aria2-$portVersion.tar.xz"
CHECKSUM_SHA256="58d1e7608c12404f0229a3d9a4953d0d00c18040504498b483305bcb3de907a5"
PATCHES="aria2-$portVersion.patchset"

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

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

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

PROVIDES="
	aria2$secondaryArchSuffix = $portVersion compat >= 1
	cmd:aria2c$commandSuffix = $portVersion
	lib:libaria2$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
#	lib:libcares$secondaryArchSuffix
#	lib:libexpat$secondaryArchSuffix
#	lib:libgcrypt$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
#	lib:libgnutls$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
#	lib:libnettle$secondaryArchSuffix
#	lib:libsqlite3$secondaryArchSuffix
#	lib:libssh2$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	aria2${secondaryArchSuffix}_devel = $portVersion compat >= 1
	devel:libaria2$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	aria2$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
#	devel:libcares$secondaryArchSuffix
#	devel:libcppunit$secondaryArchSuffix
#	devel:libexpat$secondaryArchSuffix
#	devel:libgcrypt$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
#	devel:libgnutls$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
#	devel:libnettle$secondaryArchSuffix
#	devel:libsqlite3$secondaryArchSuffix
#	devel:libssh2$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:aclocal
	cmd:automake
	cmd:autoreconf
	cmd:find
	cmd:gettext
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

TEST_REQUIRES="
	devel:libcppunit$secondaryArchSuffix
	"

defineDebugInfoPackage aria2$secondaryArchSuffix \
	"$libDir"/libaria2.so.$libVersion

BUILD()
{
	autoreconf -fi
	CPPFLAGS="-D_BSD_SOURCE" runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir \
		--enable-libaria2
	make $jobArgs
}

INSTALL()
{
	make install

	rm $libDir/libaria2.la

	prepareInstalledDevelLib libaria2

	fixPkgconfig

	# devel package
	packageEntries devel $developDir
}

TEST()
{
	make check
}
