# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=merlin
pkgver=3.0.5
pkgrel=0
pkgdesc="Context sensitive completion for OCaml"
url="https://ocaml.github.io/merlin/"
arch="all !x86 !armhf !s390x"  # limited by ocaml aport
license="MIT"
depends="ocaml ocaml-findlib"
makedepends="
	ocaml
	ocaml-findlib-dev
	ocaml-yojson-dev
	"
options="!check"  # XXX: tests are broken, see https://github.com/ocaml/merlin/issues/766
subpackages="$pkgname-emacs::noarch $pkgname-vim::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/ocaml/$pkgname/archive/v$pkgver.tar.gz"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	cd "$builddir"
	./configure --prefix /usr
	make
}

check() {
	cd "$builddir"
	make test
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
}

emacs() {
	pkgdesc="$pkgdesc in Emacs"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel emacs"

	_submv usr/share/emacs
}

vim() {
	pkgdesc="$pkgdesc in vim"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel vim"

	_submv usr/share/ocamlmerlin/vim
}

_submv() {
	local path="$1"
	mkdir -p "$subpkgdir"/${path%/*}
	mv "$pkgdir"/$path "$subpkgdir"/${path%/*}/
	rmdir -p "$pkgdir"/${path%/*} 2>/dev/null || true
}

sha512sums="bc9790d72caaec2824fe66c3ed439961a00285cd3f7e59cea8f16283a4f489a89d8ac231d2d0da1000e0f03fa6f7b52c04fa4aff6459df5bd17322693493088d  merlin-3.0.5.tar.gz"
