# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ocaml-tyxml
_pkgname=tyxml
pkgver=4.2.0
pkgrel=0
pkgdesc="OCaml library for building statically correct HTML and SVG documents"
url="https://ocsigen.org/tyxml/"
arch="all !x86 !armhf !s390x"  # limited by ocaml aport
license="LGPL-2.1-or-later"
depends="ocaml-runtime ocaml-re ocaml-uchar ocaml-uutf"
depends_dev="$pkgname=$pkgver-r$pkgrel $pkgname-ppx=$pkgver-r$pkgrel"
makedepends="
	ocaml
	ocaml-compiler-libs
	ocaml-ocamldoc
	ocaml-findlib
	ocaml-markup-dev
	ocaml-migrate-parsetree-dev
	ocaml-ocamlbuild-dev
	ocaml-ppx_tools_versioned-dev
	ocaml-re-dev
	ocaml-result-dev
	ocaml-uchar-dev
	ocaml-uutf-dev
	ocamlbuild
	"
options="!check"  # requires additional dependencies
subpackages="$pkgname-dev $pkgname-ppx"
source="$pkgname-$pkgver.tar.gz::https://github.com/ocsigen/$_pkgname/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

_sitelib="usr/lib/ocaml/$_pkgname"

build() {
	cd "$builddir"

	# --disable-syntax - Camlp4-based syntax is deprecated
	./configure \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--disable-syntax \
		--disable-tests
	make
}

package() {
	cd "$builddir"

	mkdir -p "$pkgdir"/usr/lib/ocaml
	make install OCAMLFIND_DESTDIR="$pkgdir/usr/lib/ocaml"

	# Remove annotation files and sources.
	cd "$pkgdir"/usr/lib/ocaml/$_pkgname
	rm -f *.annot *.cmt* *.ml
}

dev() {
	default_dev

	cd "$pkgdir"/$_sitelib
	_mv *.cmx *.cmxa *.mli "$subpkgdir"/$_sitelib/
}

ppx() {
	pkgdesc="$pkgdesc (ppx syntax extension)"
	depends="$pkgname=$pkgver-r$pkgrel ocaml-markup ocaml-ppx_tools_versioned"

	_mv "$pkgdir"/$_sitelib/ppx_* "$subpkgdir"/$_sitelib/
}

_mv() {
	local dest; for dest; do true; done  # get last argument
	mkdir -p "$dest"
	mv "$@"
}

sha512sums="555df1fdf5eb30592a3bd93b7d08345964b1cd6e16c2f746ef777cb3c5fc9a31dddf316432e0457d317eaf7728c5d1156982956169a7b1eb9b660eedcf89ca58  ocaml-tyxml-4.2.0.tar.gz"
