SUMMARY="Optimized C library for EC operations on curve libsecp256k1"
DESCRIPTION="Optimized C library for ECDSA signatures and secret/public key \
operations on curve libsecp256k1.

This library is intended to be the highest quality publicly available \
library for cryptography on the libsecp256k1 curve. However, the primary focus \
of its development has been for usage in the Bitcoin system and usage unlike \
Bitcoin's may be less well tested, verified, or suffer from a less well \
thought out interface. Correct usage requires some care and consideration \
that the library is fit for your application's purpose.

Features:
* libsecp256k1 ECDSA signing/verification and key generation.
* Additive and multiplicative tweaking of secret/public keys.
* Serialization/parsing of secret keys, public keys, signatures.
* Constant time, constant memory access signing and public key generation.
* Derandomized ECDSA (via RFC6979 or with a caller provided function.)
* Very efficient implementation.
* Suitable for embedded systems.
* Optional module for public key recovery.
* Optional module for ECDH key exchange (experimental)."
HOMEPAGE="https://github.com/bitcoin-core/secp256k1"
COPYRIGHT="2013 Pieter Wuille"
LICENSE="MIT"
REVISION="1"
srcGitRev="4f27e344c69c33b4f3f448baa0196b9892287081"
SOURCE_URI="https://github.com/bitcoin-core/secp256k1/archive/$srcGitRev.zip"
CHECKSUM_SHA256="3bcb4b1143ecf781623af412d73edc827cfa76dd260d93faadb2d32799a197f9"
SOURCE_FILENAME="secp256k1-$portVersion.zip"
SOURCE_DIR="secp256k1-$srcGitRev"

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

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

PROVIDES="
	libsecp256k1$secondaryArchSuffix = $portVersion
	lib:libsecp256k1$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	"

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

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libgmp$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage libsecp256k1$secondaryArchSuffix \
	"$libDir"/libsecp256k1.so.$libVersion

BUILD()
{
	autoreconf -vfi
	runConfigure ./configure \
		--enable-module-recovery \
		--enable-experimental \
		--enable-module-ecdh \
		--disable-tests \
		--disable-static \
		--enable-shared
	make $jobArgs
}

INSTALL()
{
	make install

	#remove libtool file
	rm -f "$libDir"/libsecp256k1.la

	prepareInstalledDevelLib libsecp256k1
	fixPkgconfig

	# devel package
	packageEntries devel \
		"$developDir"
}
