# SliTaz package receipt for Navette.
#
# Two intended uses:
#   1. `make tazpkg` at the top of the Navette tree copies this file into
#      a staged tree and runs `tazpkg pack` to produce a local
#      navette-VERSION.tazpkg from the current checkout. VERSION is
#      stamped in from the Makefile, so it is always in step.
#   2. The SliTaz wok. cook fetches the tarball straight from the hg
#      archive, the way spk does -- no separately published tarball to
#      keep in sync with the repository.

PACKAGE="navette"
VERSION="0.4.1"
CATEGORY="development"
SHORT_DESC="Agentic code editor, llama.cpp client"
MAINTAINER="pankso@slitaz.org"
LICENSE="BSD"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WEB_SITE="https://www.slitaz.org/"
# Tags are v-prefixed, so the archive unpacks to navette-v$VERSION/.
# cook renames a single extracted directory to navette-$VERSION itself,
# so the mismatch costs nothing.
WGET_URL="http://hg.slitaz.org/$PACKAGE/archive/v$VERSION.tar.gz"

# 64-bit only. Navette drives llama-server, which wants far more RAM than
# an i486 target implies, and it has never been built or tested there.
HOST_ARCH="x86_64"

# ncursesw, not ncurses: navette links the wide-character library so that
# accented input renders as glyphs. curl is not optional either -- `navette
# pull` shells out to it and BusyBox wget cannot follow HuggingFace's HTTPS
# redirects, so without it a fresh install runs but can never fetch a model.
DEPENDS="ncursesw llama.cpp curl"
BUILD_DEPENDS="ncursesw-dev"

current_version()
{
	wget -O - http://hg.slitaz.org/$PACKAGE/ 2>/dev/null | \
	sed '/^Changeset/!d;s|.*">|http://hg.slitaz.org/'$PACKAGE'/rev/|;s|<.*||' | \
	xargs wget -O - 2>/dev/null | sed '/rev /!d;s|.*rev ||;s| .*||;s|.|&.|g;s|.$||'
}

# Rules to configure and make the package.
compile_rules()
{
	# -L/usr/lib guards against an out-of-date ncursesw-dev. ld searches
	# /lib before /usr/lib, and an older ncursesw-dev installed
	# libncursesw.a into /lib while the shared library sat in /usr/lib --
	# so plain `-lncursesw` picked up the ARCHIVE and produced a binary
	# whose only NEEDED entry was libc. It ran, but carried its own copy
	# of ncurses and would never have picked up a security fix. A current
	# ncursesw-dev puts both in /lib and links dynamically on its own;
	# this flag simply keeps the outcome the same either way, since it
	# finds the .so in the old layout and is a no-op in the new one.
	# Checked with `readelf -d` against both layouts.
	make LIBS="-L/usr/lib -lncursesw" all
	make DESTDIR="$install" PREFIX=/usr install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p "$fs/usr"
	cp -a "$install/usr/." "$fs/usr/"
}
