SUMMARY="Utility for verifying hash sums of files"
DESCRIPTION="RHash (Recursive Hasher) is a console utility for computing and \
verifying hash sums of files. It supports CRC32, MD4, MD5, SHA1, SHA256, \
SHA512, Tiger, DC++ TTH, BitTorrent BTIH, ED2K, AICH, GOST R 34.11-94, \
RIPEMD-160, HAS-160, EDON-R 256/512, Whirlpool and Snefru-128/256 algorithms. \
Hash sums are used to ensure and verify integrity of large volumes of data for\
 a long-term storing or transferring.
"
HOMEPAGE="https://github.com/rhash/RHash"
COPYRIGHT="2005-2020 Aleksey Kravchenko"
LICENSE="MIT"
REVISION="1"
SOURCE_URI="https://github.com/rhash/RHash/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="600d00f5f91ef04194d50903d3c79412099328c42f28ff43a0bdb777b00bec62"
SOURCE_DIR="RHash-$portVersion"
PATCHES="rhash-$portVersion.patchset"

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

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

if [ -z "$commandSuffix" ]; then
GLOBAL_WRITABLE_FILES="
	settings/rhashrc keep-old
	"
USER_SETTINGS_FILES="
	settings/rhashrc
	"
fi

PROVIDES="
	rhash$secondaryArchSuffix = $portVersion
	lib:librhash$secondaryArchSuffix = 0
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

RHASH_BIN="
	cmd:ed2k_link$commandSuffix = $portVersion
	cmd:edonr256_hash$commandSuffix = $portVersion
	cmd:edonr512_hash$commandSuffix = $portVersion
	cmd:gost_hash$commandSuffix = $portVersion
	cmd:gost12_256_hash$commandSuffix = $portVersion
	cmd:gost12_512_hash$commandSuffix = $portVersion
	cmd:has160_hash$commandSuffix = $portVersion
	cmd:magnet_link$commandSuffix = $portVersion
	cmd:rhash$commandSuffix = $portVersion
	cmd:sfv_hash$commandSuffix = $portVersion
	cmd:tiger_hash$commandSuffix = $portVersion
	cmd:tth_hash$commandSuffix = $portVersion
	cmd:whirlpool_hash$commandSuffix = $portVersion
	"
if [ -z "$commandSuffix" ]; then
PROVIDES="$PROVIDES
	$RHASH_BIN
	"
else
PROVIDES_bin="
	rhash_bin = $portVersion
	$RHASH_BIN
	"
REQUIRES_bin="
	haiku$secondaryArchSuffix
	rhash$secondaryArchSuffix == $portVersion base
	"
fi

PROVIDES_devel="
	rhash${secondaryArchSuffix}_devel = $portVersion
	devel:librhash$secondaryArchSuffix = 0
	"
REQUIRES_devel="
	haiku${secondaryArchSuffix}_devel
	rhash$secondaryArchSuffix == $portVersion base
	"

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

BUILD()
{
	INSTALL_INCDIR="$includeDir" \
	./configure --prefix="$prefix" --bindir="$commandBinDir" \
		--libdir="$libDir" --localedir="$dataDir"/locale --mandir="$manDir" \
		--sysconfdir="$sysconfDir"
	make $jobArgs
}

INSTALL()
{
	make install install-pkg-config
	make -C librhash install-lib-headers
	make -C librhash install-so-link

	prepareInstalledDevelLib librhash
	fixPkgconfig

	packageEntries devel \
		"$developDir"

	if [ -n "$commandSuffix" ]; then
		packageEntries bin \
			"$commandBinDir" \
			"$manDir"
		rm "$settingsDir"/rhashrc
	fi
}

TEST()
{
	cd tests
	LIBRARY_PATH="$sourceDir/librhash${LIBRARY_PATH:+:$LIBRARY_PATH}" \
		./test_rhash.sh --full ../rhash
}
