# Contributor: Maya <hello@unw.re>
# Maintainer: Maya <hello@unw.re>
pkgname=cm256cc
pkgver=1.1.1
pkgrel=1
pkgdesc="Fast GF(256) Cauchy MDS Block Erasure Codec library in C++"
url="https://github.com/f4exb/cm256cc"
license="GPL-3.0-only AND MIT AND BSD-3-Clause"
# requires ssse3/neon and does not build anything otherwise
arch="aarch64 x86_64"
makedepends="
	cmake
	samurai
	"
subpackages="$pkgname-dev"
checkdepends="xvfb-run"
source="$pkgname-$pkgver.tar.gz::https://github.com/f4exb/cm256cc/archive/refs/tags/v$pkgver.tar.gz"

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DENABLE_DISTRIBUTION=ON \
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DBUILD_TOOLS="$(want_check && echo ON || echo OFF)"
	cmake --build build
}

check() {
	./build/cm256_test
	./build/cm256_rx
	./build/cm256_tx
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	# these are just unit tests
	# shellcheck disable=2115
	rm -rfv "$pkgdir"/usr/bin/
}

sha512sums="
fcda338b766bcae1af1e25ab6237c30ed60722b2e6e679e13623005d441d3e8daa462c7a7735ca239c0a1fa5f2d8b28455fe40f40762ebefa997c2ebd3731082  cm256cc-1.1.1.tar.gz
"
