# Contributor: Daniel Sabogal <dsabogalcc@gmail.com>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
#
# secfixes:
#   0.1.6-r1:
#     - CVE-2016-1248
#   0.2.0-r0:
#     - CVE-2017-5953
#     - CVE-2017-6349
#     - CVE-2017-6350

# TODO: Try to trim the base package to include only common syntax files etc.
# NOTE: ignore-st-cursor-shape.patch will be in neovim 0.2.3
pkgname=neovim
pkgver=0.2.2
pkgrel=2
pkgdesc="Vim-fork focused on extensibility and agility"
url="https://neovim.io"
arch="all !s390x" # needs luajit
license="Apache-2.0 custom"
depends=""
makedepends="cmake gettext-dev gperf libtermkey-dev libuv-dev libvterm-dev
	lua5.1-lpeg lua5.1-mpack luajit-dev msgpack-c-dev unibilium-dev"
subpackages="$pkgname-lang $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/neovim/$pkgname/archive/v$pkgver.tar.gz
	ignore-st-cursor-shape.patch
	nodoc.txt"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	mkdir -p "$builddir"/build
	cd "$builddir"/build

	cmake .. \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DENABLE_JEMALLOC=FALSE \
		-DCMAKE_VERBOSE_MAKEFILE=TRUE \
		|| return 1
	make || return 1
}

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

doc() {
	default_doc || return 1

	pkgdesc="$pkgdesc (documentation and help pages)"
	replaces="$pkgname"
	local docdir="usr/share/nvim/runtime/doc"

	mkdir -p "$subpkgdir"/$docdir
	mv "$pkgdir"/$docdir/*.txt "$subpkgdir"/$docdir/ || return 1

	# When user execute ":help <pattern>", neovim will open nodoc.txt
	# with information why docs are not available and how to install them.
	install -D "$srcdir"/nodoc.txt \
		"$pkgdir"/$docdir/nodoc.txt || return 1
	local f; for f in "$subpkgdir"/$docdir/*.txt; do
		ln -s nodoc.txt "$pkgdir"/$docdir/$(basename $f) || return 1
	done
}

sha512sums="5609defe86ac98356f1b9ae9adc6049bb4df920a9a2ae3104f761d52d4dd54cbc84d2596231595dd9b0aa97201fef2121e6c5c86a19267ab6b871dbf4b568209  neovim-0.2.2.tar.gz
46663e6d71a0cbd501fc62c97940e9e8438190080eea442fd060ae4b60ac6f8d656578df83f26a3210ced90db034038c8da0746b7161a6636a4d9275860be716  ignore-st-cursor-shape.patch
72ab288f53acddc088c567aafe8c5afa6835325fab7879e782d1d62f87a662f3a6bac123c450debbae1b32336cc60b2830b429838ee3dfcc7524773b5069f4f0  nodoc.txt"
