# Contributor: Michael Mason <ms13sp@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=nano
pkgver=2.9.4
pkgrel=0
pkgdesc="Enhanced clone of the Pico text editor"
url="https://www.nano-editor.org"
arch="all"
license="GPL-3.0-or-later"
makedepends="file-dev linux-headers ncurses-dev"
subpackages="$pkgname-doc $pkgname-syntax::noarch"
source="https://www.nano-editor.org/dist/v${pkgver%.*}/$pkgname-$pkgver.tar.xz"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--disable-nls \
		--with-wordbounds
	make
}

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

package() {
	cd "$builddir"

	make DESTDIR="$pkgdir" install
	install -Dm644 doc/sample.nanorc \
		"$pkgdir"/etc/nanorc

	# Proper syntax highlighting for APKBUILDs
	sed -i "/syntax/s/\"$/\" \"APKBUILD&/" \
		"$pkgdir"/usr/share/nano/sh.nanorc

	rm -rf "$pkgdir"/usr/lib/charset.alias
}

syntax() {
	pkgdesc="Syntax highlighting definitions for $pkgname"

	mkdir -p "$subpkgdir"/usr/share/$pkgname/
	mv "$pkgdir"/usr/share/$pkgname/*.nanorc \
		"$subpkgdir"/usr/share/$pkgname/
}

sha512sums="d8ef564ab9db2cd5f230061e5bb55f6bc36b6450c7585562ee32a27702a44276d94febd3c988b70eaf5b2e1a453426042c079a9eb40a4e71744da1ddde269863  nano-2.9.4.tar.xz"
