SUMMARY="A virtual layer that helps you improve privacy and anonymity"
DESCRIPTION="Tor is a network of virtual tunnels that allows people and groups to improve \
their privacy and security on the Internet. It also enables software \
developers to create new communication tools with built-in privacy features. \
Tor provides the foundation for a range of applications that allow \
organizations and individuals to share information over public networks \
without compromising their privacy."
HOMEPAGE="https://www.torproject.org/"
COPYRIGHT="2007-2021 The Tor Project, Inc.
	2004-2006 Nick Mathewson
	2001-2006 Roger Dingledine"
LICENSE="Tor"
REVISION="1"
SOURCE_URI="https://dist.torproject.org/tor-$portVersion.tar.gz"
CHECKSUM_SHA256="15ce1a37b4cc175b07761e00acdcfa2c08f0d23d6c3ab9c97c464bd38cc5476a"
PATCHES="tor-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2"
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

GLOBAL_WRITABLE_FILES="
	settings/tor/torrc.sample auto-merge
	"
USER_SETTINGS_FILES="
	settings/tor directory
	"

PROVIDES="
	tor$secondaryArchSuffix = $portVersion
	cmd:tor$commandSuffix
	cmd:tor_gencert$commandSuffix
	cmd:tor_print_ed_signing_cert$commandSuffix
	cmd:tor_resolve$commandSuffix
	cmd:torify$commandSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libexecinfo$secondaryArchSuffix
	lib:libevent_2.1$secondaryArchSuffix
	lib:liblzma$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libzstd$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libexecinfo$secondaryArchSuffix
	devel:libevent_2.1$secondaryArchSuffix
	devel:liblzma$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libzstd$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage tor$secondaryArchSuffix \
	"$commandBinDir"/tor \
	"$commandBinDir"/tor-gencert \
	"$commandBinDir"/tor-resolve

BUILD()
{
	export CPPFLAGS="-D_BSD_SOURCE"
	export LDFLAGS="-lbsd"

	autoreconf -vfi

	runConfigure --omit-dirs "binDir sbinDir" \
		./configure \
			--bindir="$commandBinDir" \
			--sbindir="$commandBinDir" \
			--disable-gcc-hardening

	make $jobArgs
}

INSTALL()
{
	make install
}

TEST()
{
	make check
}
