SUMMARY="Blocking, shuffling and lossless compression library"
DESCRIPTION="Blosc is a high performance compressor optimized for binary \
data. It has been designed to transmit data to the processor cache faster \
than the traditional, non-compressed, direct memory fetch approach via a \
memcpy() OS call. Blosc is the first compressor (that I'm aware of) that is \
meant not only to reduce the size of large datasets on-disk or in-memory, but \
also to accelerate memory-bound computations."
HOMEPAGE="https://www.blosc.org/"
COPYRIGHT="2012 Francesc Alted
	2019-2020 Blosc Development team"
LICENSE="MIT"
REVISION="1"
SOURCE_URI="https://github.com/Blosc/c-blosc/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="18730e3d1139aadf4002759ef83c8327509a9fca140661deb1d050aebba35afb"
SOURCE_FILENAME="c_blosc-$portVersion.tar.gz"
SOURCE_DIR="c-blosc-$portVersion"

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

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

PROVIDES="
	c_blosc$secondaryArchSuffix = $portVersion
	lib:libblosc$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:liblz4$secondaryArchSuffix
	lib:libsnappy$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libzstd$secondaryArchSuffix
	"

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

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:liblz4$secondaryArchSuffix
	devel:libsnappy$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libzstd$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:perl >= 5
	cmd:sed
	"

defineDebugInfoPackage c_blosc$secondaryArchSuffix \
	"$libDir"/libblosc.so.$portVersion

BUILD()
{
	mkdir -p haiku_build
	cd haiku_build

	cmake .. \
		-DPREFER_EXTERNAL_LZ4=ON \
		-DPREFER_EXTERNAL_SNAPPY=ON \
		-DPREFER_EXTERNAL_ZLIB=ON \
		-DPREFER_EXTERNAL_ZSTD=ON \
		-DDEACTIVATE_AVX2=ON \
		-DLIB_SUFFIX=$secondaryArchSubDir \
		$cmakeDirArgs

	make $jobArgs
}

INSTALL()
{
	cd haiku_build

	make install

	# move include dir to correct location
	mkdir -p $(dirname $includeDir)
	mv $prefix/include $includeDir

	if [ -n "$secondaryArchSuffix" ]; then
		# On secondary arch the pkgconfig subdir should also go to $libDir
		# instead of $prefix/lib
		mv "$prefix"/lib/pkgconfig "$libDir"
	fi

	# prepare develop/lib
	prepareInstalledDevelLibs libblosc
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
}

TEST()
{
	cd haiku_build
	make test
}
