# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ocaml-camomile
_pkgname=camomile
pkgver=0.8.7
pkgrel=2
pkgdesc="A Unicode library for OCaml"
url="https://github.com/yoriyuki/Camomile"
# x86, armhf, s390x: limited by ocaml aport
arch="all !x86 !armhf !s390x"
license="LGPL-2.0-or-later"
depends="$pkgname-data=$pkgver-r$pkgrel ocaml-runtime"
makedepends="dune ocaml ocaml-compiler-libs ocaml-cppo ocaml-findlib opam"
subpackages="$pkgname-dev $pkgname-data::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/yoriyuki/$_pkgname/archive/rel-$pkgver.tar.gz"
builddir="$srcdir/Camomile-rel-$pkgver"

build() {
	cd "$builddir"

	# Workaround for https://github.com/yoriyuki/Camomile/issues/39.
	if [ "$CARCH" = ppc64le ]; then
		ulimit -Hs unlimited
		ulimit -Ss 65536
	fi

	jbuilder build @install
}

check() {
	cd "$builddir"
	jbuilder runtest
}

package() {
	cd "$builddir"

	mkdir -p "$pkgdir"/usr/lib/ocaml
	jbuilder install \
		--destdir="$pkgdir/usr" \
		--libdir="$pkgdir/usr/lib/ocaml"

	cd "$pkgdir"

	# There's just a readme.
	rm -Rf usr/doc

	# Remove annotation files and sources.
	rm -Rf usr/lib/ocaml/$_pkgname/*.cmt*
	rm -Rf usr/lib/ocaml/$_pkgname/*.ml
}

dev() {
	default_dev
	depends="$pkgname=$pkgver-r$pkgrel"
	local sitelib="usr/lib/ocaml/$_pkgname"

	cd "$pkgdir"/$sitelib

	mkdir -p "$subpkgdir"/$sitelib
	mv *.cmx *.cmxa *.mli "$subpkgdir"/$sitelib/
}

data() {
	pkgdesc="$pkgdesc (data files)"
	depends=""

	mkdir -p "$subpkgdir"/usr/share
	mv "$pkgdir"/usr/share/$_pkgname "$subpkgdir"/usr/share/
}

sha512sums="a8db2086030b703e1ada0e2cc195e1c6338946439b3a6b6a05febb3a0d24388add9fe06961025e043181a885bb085e33cebc8027c66c7dbbe1cc30e18df27cf2  ocaml-camomile-0.8.7.tar.gz"
