SUMMARY="A password-hashing function"
DESCRIPTION="Argon2 is a password-hashing function that summarizes the state \
of the art in the design of memory-hard functions and can be used to hash \
passwords for credential storage, key derivation, or other applications."
HOMEPAGE="https://github.com/p-h-c/phc-winner-argon2"
COPYRIGHT="2015-2017 Daniel Dinu
	2013-2017 Samuel Neves
	2015-2017 Dmitry Khoravich
	2015-2017 Jean-Philippe Aumasson
	2015 Thomas Pornin"
LICENSE="Apache v2
	Public Domain"
REVISION="1"
srcGitRev="440ceb9612d5a20997e3e12728542df2de713ca4"
SOURCE_URI="https://github.com/P-H-C/phc-winner-argon2/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="bb7a9d6fa631fdb61b95a93596f2c9c38ad3035b774459b793acf46cd3502647"
SOURCE_FILENAME="argon2-$srcGitRev.tar.gz"
SOURCE_DIR="phc-winner-argon2-$srcGitRev"
PATCHES="argon2-$portVersion.patchset"
if [ "$effectiveTargetArchitecture" = x86_gcc2 ]; then
	PATCHES="$PATCHES
	argon2-$portVersion-gcc2.patchset"
fi

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	argon2$secondaryArchSuffix = $portVersion
	lib:libargon2$secondaryArchSuffix = 1
	"
if [ -z "$secondaryArchSuffix" ]; then
PROVIDES="$PROVIDES
	cmd:argon2 = $portVersion
	"
fi

REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	argon2${secondaryArchSuffix}_devel = $portVersion
	devel:libargon2$secondaryArchSuffix = 1
	"
REQUIRES_devel="
	argon2$secondaryArchSuffix == $portVersion base
	"

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

TEST_REQUIRES="
	cmd:diff
	"

defineDebugInfoPackage argon2$secondaryArchSuffix \
	$libDir/libargon2.so.1

PATCH()
{
	if [ -n "$secondaryArchSuffix" ]; then
		sed -i 's,develop/headers,develop/headers/x86,g' Makefile
		sed -i 's,LIBRARY_REL ?= lib,LIBRARY_REL ?= lib/x86,g' Makefile
	fi
	sed -i 's/-march=\$(OPTTARGET)//' Makefile
}

BUILD()
{
	export ARGON2_VERSION=$portVersion
	make PREFIX=$prefix
}

INSTALL()
{
	make install PREFIX=$prefix

	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf $prefix/bin
		rm -rf $manDir
	fi

	prepareInstalledDevelLib libargon2
	fixPkgconfig

	packageEntries devel \
		$developDir
}

TEST()
{
	make OPTTARGET=none test
}
