# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ocaml-react
_pkgname=react
pkgver=1.2.0
pkgrel=1
pkgdesc="OCaml framework for Functional Reactive Programming (FRP)"
url="http://erratique.ch/software/react"
arch="all !x86 !armhf !s390x"  # limited by ocaml aport
license="ISC"
depends="ocaml-runtime"
makedepends="ncurses ocaml ocaml-compiler-libs ocaml-findlib ocamlbuild opam"
options="textrels"  # needed for ppc64le
subpackages="$pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/dbuenzli/$_pkgname/archive/v$pkgver.tar.gz
	fix-safe-string.patch"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	cd "$builddir"

	ocaml pkg/build.ml \
		native=true \
		native-dynlink=true

	ocamlbuild -use-ocamlfind test/tests.otarget
}

check() {
	cd "$builddir"

	./_build/test/test.native
}

package() {
	cd "$builddir"

	opam-installer -i \
		--prefix="$pkgdir/usr" \
		--libdir="$pkgdir/$(ocamlc -where)" \
		--docdir="$pkgdir/usr/share/doc/$pkgname" \
		$_pkgname.install

	# Remove annotation files.
	rm -Rf "$pkgdir"/usr/lib/ocaml/$_pkgname/*.cmt*
}

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/
}

sha512sums="929f0a5e84d6e92c366e3c43c582c48e639eab662f654ff65b4789155e96ce4bdd10c38acfb932a20ddce4042943baa2644934be4d7542a20b801203437c3d21  ocaml-react-1.2.0.tar.gz
8ac6aa6f703ab866abcae0640f539a9eb0f2796713306191d308f6988b186514dd3a5b70197a56ef6f83d62d5d179d2210241e001b8a944f5272757326e978fc  fix-safe-string.patch"
