SUMMARY="Fast C/C++ prime number generator library"
DESCRIPTION="primesieve is a program and C/C++ library that generates primes \
using a highly optimized sieve of Eratosthenes implementation. It counts the \
primes below 10^10 in just 0.45 seconds on an Intel Core i7-6700 CPU \
(4 x 3.4GHz). primesieve can generate primes and prime k-tuplets up to 2^64."
HOMEPAGE="https://primesieve.org/"
COPYRIGHT="2010-2019 Kim Walisch"
LICENSE="BSD (2-clause)"
REVISION="1"
SOURCE_URI="https://github.com/kimwalisch/primesieve/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="ff9b9e8c6ca3b5c642f9a334cc399dd55830a8d9c25afd066528aa2040032399"
SOURCE_FILENAME="primesieve-$portVersion.tar.gz"

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

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

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

PROVIDES="
	primesieve$secondaryArchSuffix = $portVersion
	cmd:primesieve$commandSuffix = $portVersion
	lib:libprimesieve$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	"

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

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

BUILD()
{
	mkdir -p build && cd build

	cmake .. \
		-DCMAKE_INSTALL_BINDIR="$commandBinDir" \
		-DCMAKE_INSTALL_LIBDIR="$libDir" \
		-DCMAKE_INSTALL_INCLUDEDIR="$includeDir" \
		-DCMAKE_INSTALL_DOCDIR="$docDir" \
		-DCMAKE_INSTALL_MANDIR="$manDir" \
		-DBUILD_TESTS=ON

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	prepareInstalledDevelLib libprimesieve
	fixPkgconfig

	packageEntries devel \
		$developDir \
		$libDir/cmake
}

TEST()
{
	cd build
	make test
}
