# Contributor: River Dillon <oss@outerpassage.net>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-zarith
pkgver=1.12
pkgrel=5
pkgdesc="Arithmetic and logical operations over arbitrary-precision integers"
url="https://github.com/ocaml/Zarith"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-2.0-only WITH OCaml-LGPL-linking-exception"
depends="gmp-dev" # zarith is not split into a -dev subpackage
makedepends="
	ocaml
	ocaml-findlib
	ocaml-compiler-libs
	ocaml-ocamldoc
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/ocaml/Zarith/archive/refs/tags/release-$pkgver.tar.gz"
builddir="$srcdir/Zarith-release-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	./configure -installdir "$pkgdir"/usr/lib/ocaml
	make
	make doc
}

check() {
	make tests
}

package() {
	mkdir -p "$pkgdir"/usr/lib/ocaml "$pkgdir"/usr/lib/ocaml/stublibs
	OCAMLFIND_LDCONF=ignore make install

	install -Dm644 README.md -t "$pkgdir"/usr/share/doc/$pkgname/
	install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
8075573ae65579a2606b37dd1b213032a07d220d28c733f9288ae80d36f8a2cc4d91632806df2503c130ea9658dc207ee3a64347c21aa53969050a208f5b2bb4  ocaml-zarith-1.12.tar.gz
"
