# nano - Simple console editor
# Generated from manifest.tsv by gen-ports.py. Edit the manifest, not this file,
# unless the package needs something the template cannot express - in which case
# drop a `recipe.local` beside it and it will be preserved.
name=nano
version=9.2
release=1
desc="Simple console editor"
url="https://nano-editor.org/"
license="GPL-3.0-or-later"
depend="glibc netbsd-curses"
makedepend=""
source="https://www.nano-editor.org/dist/v9/nano-9.2.tar.xz"
sha256="SKIP"

build() {
	cd "nano-9.2"
	# See recipe.local: scope curses detection to ScrapLinux's own
	# netbsd-curses, not whatever the build host happens to have.
	_cdeps="$srcdir/.curses-deps"
	rm -rf "$_cdeps"; mkdir -p "$_cdeps"
	_cpkg=$(ls -t /home/apiwo/scraplinux-build/repo/main/x86_64/netbsd-curses-*.scrapsz 2>/dev/null | head -1)
	[ -n "$_cpkg" ] || die "netbsd-curses has no binary package built yet"
	( cd "$_cdeps" && untar "$_cpkg" . )
	export CPPFLAGS="-I$_cdeps/usr/include ${CPPFLAGS:-}"
	export LDFLAGS="-L$_cdeps/usr/lib -Wl,-rpath-link,$_cdeps/usr/lib ${LDFLAGS:-}"
	export PKG_CONFIG_PATH="$_cdeps/usr/lib/pkgconfig"
	export PKG_CONFIG_LIBDIR="$_cdeps/usr/lib/pkgconfig"
	# Not every configure script accepts the same options - sqlite rejects
	# --disable-nls outright, for instance - so only pass the ones this one
	# actually advertises. Guessing wrong fails the whole build.
	_opts="--prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib"
	_help=$(./configure --help 2>/dev/null)
	case "$_help" in *--disable-static*)  _opts="$_opts --disable-static" ;; esac
	case "$_help" in *--disable-nls*)     _opts="$_opts --disable-nls" ;; esac
	# Auto-detects libmagic on the build host and links against it if
	# found, which was not shipped on the ISO - nano failed to start at
	# all with "cannot open shared object file: libmagic.so.1".
	case "$_help" in *--disable-libmagic*) _opts="$_opts --disable-libmagic" ;; esac
	# shellcheck disable=SC2086
	./configure $_opts
	make -j"$JOBS"
}

package() {
	cd "nano-9.2"
	make DESTDIR="$pkgdir" install
}
