SUMMARY="A fast non-cryptographic hash algorithm"
DESCRIPTION="xxHash is an extremely fast non-cryptographic hash algorithm, \
working at speeds close to RAM limits."
HOMEPAGE="https://cyan4973.github.io/xxHash/
	http://www.xxhash.com/"
COPYRIGHT="2014-2017 Yann Collet"
LICENSE="BSD (2-clause)"
REVISION="1"
SOURCE_URI="http://github.com/Cyan4973/xxHash/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="7054c3ebd169c97b64a92d7b994ab63c70dd53a06974f1f630ab782c28db0f4f"
SOURCE_FILENAME="xxHash-$portVersion.tar.gz"
SOURCE_DIR="xxHash-$portVersion"
PATCHES="xxhash-$portVersion.patchset"

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

# Provide cmd:xxhash on all primary architectures except x86_gcc2,
# as well as on x86 secondary arch if the primary arch is x86_gcc2.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
provideRuntime=yes
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
else
	if [ -n "$secondaryArchSuffix" ]; then
		provideRuntime=no
	fi
fi
if [ "$effectiveTargetArchitecture" = x86_gcc2 ]; then
	provideRuntime=no
fi

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

PROVIDES="
	xxhash$secondaryArchSuffix = $portVersion
	lib:libxxhash$secondaryArchSuffix = $libVersionCompat
	"
if [ "$provideRuntime" = yes ]; then
PROVIDES="$PROVIDES
	cmd:xxh32sum$commandSuffix = $portVersion
	cmd:xxh64sum$commandSuffix = $portVersion
	cmd:xxh128sum$commandSuffix = $portVersion
	cmd:xxhsum$commandSuffix = $portVersion
	"
fi
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	xxhash${secondaryArchSuffix}_devel = $portVersion
	devel:libxxhash$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	xxhash$secondaryArchSuffix == $portVersion base
	"

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

debugList=(
	"$libDir"/libxxhash.so.$libVersion
	)
if [ "$provideRuntime" = yes ]; then
	debugList+=("$commandBinDir"/xxhsum)
fi
defineDebugInfoPackage xxhash$secondaryArchSuffix "${debugList[@]}"

PATCH()
{
	if [ "$effectiveTargetArchitecture" = x86_gcc2 ]; then
		sed -i \
			-e "s/ -Wextra//" \
			-e "s/ -Wstrict-aliasing=1//" \
			-e "s/ -Wswitch-enum//" \
			-e "s/ -Wdeclaration-after-statement//" \
			Makefile
	fi
}

TEST_REQUIRES="
	cmd:awk
	cmd:find
	devel:libclang$secondaryArchSuffix
	"

BUILD()
{
	make $jobArgs
}

INSTALL()
{
	make PREFIX="$prefix" BINDIR="$commandBinDir" INCLUDEDIR="$includeDir" \
		LIBDIR="$libDir" MANDIR="$manDir/man1" install

	if [ "$provideRuntime" != yes ]; then
		rm -rf "$commandBinDir" "$manDir"
	fi

	prepareInstalledDevelLib libxxhash
	fixPkgconfig

	packageEntries devel \
		"$developDir"
}

TEST()
{
	make ENABLE_UNICODE=1 test-all
}
