SUMMARY="Library for Factoring Large Integers"
DESCRIPTION="C library implementing a suite of algorithms to factor large integers"
HOMEPAGE="https://sourceforge.net/projects/msieve/"
COPYRIGHT="Public Domain"
LICENSE="Public Domain"
REVISION="1"
SOURCE_URI="https://downloads.sourceforge.net/msieve/msieve/Msieve%20v$portVersion/msieve${portVersion/./}_src.tar.gz"
CHECKSUM_SHA256="c5fcbaaff266a43aa8bca55239d5b087d3e3f138d1a95d75b776c04ce4d93bb4"
PATCHES="msieve-$portVersion.patchset"

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

PROVIDES="
	msieve$secondaryArchSuffix = $portVersion
	cmd:msieve$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libecm$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	msieve${secondaryArchSuffix}_devel = $portVersion
	devel:libmsieve$secondaryArchSuffix
	"
REQUIRES_devel="
	haiku${secondaryArchSuffix}_devel
	msieve$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libecm$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:sed
	"

PATCH()
{
	# Allow owns CFLAGS, could be useful when doing debug builds
	sed -e 's/^CFLAGS =/CFLAGS +=/' -i Makefile
	# Remove -march=native, while this flag provides speedup,
	# it's not suitable for binary distribution
	sed -e 's/-march=native//' -i Makefile
}

BUILD()
{
	make $jobArgs all ECM=1 HAIKU=1
}

INSTALL()
{
	install -d -m 755 "$binDir" "$docDir" "$includeDir" "$developLibDir"

	install -t "$binDir" -m 755 msieve
	install -t "$docDir" -m 644 Changes Readme*
	install -t "$includeDir" -m 644 include/*
	install -t "$developLibDir" -m 644 libmsieve.a

	packageEntries devel \
		"$developDir" \
		"$docDir/Changes"
}
