SUMMARY="Fork of the zlib data compression library"
DESCRIPTION="Zlib replacement with optimizations for next generation systems"
HOMEPAGE="https://github.com/zlib-ng/zlib-ng"
COPYRIGHT="1995-2013 Jean-loup Gailly and Mark Adler"
LICENSE="Zlib"
REVISION="1"
SOURCE_URI="https://github.com/zlib-ng/zlib-ng/archive/refs/tags/$portVersion.tar.gz"
CHECKSUM_SHA256="eca3fe72aea7036c31d00ca120493923c4d5b99fe02e6d3322f7c88dbdcd0085"
SOURCE_DIR="zlib-ng-$portVersion"

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

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

PROVIDES="
	zlib_ng$secondaryArchSuffix = $portVersion
	lib:libz_ng$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

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

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

defineDebugInfoPackage zlib_ng$secondaryArchSuffix \
	$libDir/libz-ng.so.$libVersion

BUILD()
{
	rm -rf build
	cmake -B build -S . \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX:PATH=$prefix \
		-DINC_INSTALL_DIR=$includeDir \
		-DLIB_INSTALL_DIR=$libDir \
		-DZLIB_ENABLE_TESTS=ON \
		-DWITH_OPTIM=ON \
		-DWITH_UNALIGNED=OFF \
		-DWITH_AVX2=OFF \
		-DWITH_SSSE3=OFF \
		-DWITH_SSE4=OFF \
		-DWITH_PCLMULQDQ=OFF \
		-DAVX2_SLIDEHASH=OFF \
		-DAVX_CHUNKSET=OFF \
		-DAVX2_COMPARE258=OFF \
		-DAVX2_ADLER32=OFF \
		-DSSE42_CRC=OFF \
		-DSSE42_COMPARE258=OFF \
		-DSSSE3_ADLER32=OFF \
		-DPCLMUL_CRC=OFF \
		-DWITH_NATIVE_INSTRUCTIONS=OFF

	make $jobArgs -C build
}

INSTALL()
{
	make -C build install

	prepareInstalledDevelLib libz-ng
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
}

TEST()
{
	make -C build test
}
