# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ocaml-cppo
_pkgname=cppo
pkgver=1.6.4
pkgrel=4
pkgdesc="C-style preprocessor for OCaml"
url="https://github.com/mjambon/cppo"
arch="all !x86 !armhf !s390x"  # limited by ocaml
license="BSD-3-Clause"
makedepends="dune ocaml ocaml-ocamlbuild-dev ocaml-findlib opam"
options="textrels"  # needed for ppc64le
subpackages="$pkgname-dev $pkgname-ocamlbuild"
source="$pkgname-$pkgver.tar.gz::https://github.com/mjambon/$_pkgname/archive/v$pkgver.tar.gz
	ppc64le-asr.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	cd "$builddir"
	jbuilder build --root . @install @DEFAULT
}

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"

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

	# Nothing interesting here.
	rm -Rf usr/doc
}

ocamlbuild() {
	pkgdesc="$pkgdesc (Ocamlbuild plugin)"
	depends="ocaml-runtime ocaml-ocamlbuild"

	mkdir -p "$subpkgdir"/usr/lib/ocaml
	mv "$pkgdir"/usr/lib/ocaml/${_pkgname}_ocamlbuild \
		"$subpkgdir"/usr/lib/ocaml/
}

dev() {
	default_dev

	depends="$pkgname=$pkgver-r$pkgrel $pkgname-ocamlbuild=$pkgver-r$pkgrel"
	local sitelib="usr/lib/ocaml/${_pkgname}_ocamlbuild"

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

sha512sums="89c6df66d597d929be7532ad82f0206b028bdbd79a0b4b39451bce3fa5bd63a80dce931d575f69bd7066de829347498c736657dfe9610b20700a652b9b542a4d  ocaml-cppo-1.6.4.tar.gz
718b0bfb4c0106e153bde9cf9a52f79858f113b3a8ffd6c9f887c2b2fec16dd330e952786e322a3532200e34ae533828d9d98c3fa784910cd3f92fec56250533  ppc64le-asr.patch"
