# Maintainer: FWS <maintainers@nocode-var.tech>
#
# Arch package for the FWS kitty fork. Built with makepkg from this directory:
#
#     cd packaging && makepkg -f
#
# The resulting fws-kitty-<version>-<rel>-<arch>.pkg.tar.zst is ready to be
# added to a pacman repository (see README.md in this directory).
#
# kitty installs its own binary under /usr/bin and cannot coexist with the
# upstream package, hence provides/conflicts.

pkgname=fws-kitty
pkgver=0.50.0
pkgrel=1
pkgdesc='Fast, feature-rich, GPU based terminal (FWS fork with the file-manager kitten)'
arch=('x86_64' 'aarch64')
url='https://gitea.nocode-var.tech/FWS/FWS-Kitty'
license=('GPL-3.0-only')

# Replace main with the tag or commit to ship once the release is cut.
_branch=main
_repo='https://gitea.nocode-var.tech/FWS/FWS-Kitty.git'

depends=(
    python harfbuzz zlib libpng lcms2 xxhash openssl
    pixman cairo freetype2 fontconfig
    libx11 libxcb libxrandr libxinerama libxcursor libxi libxrender
    libxkbcommon libxkbcommon-x11 mesa wayland dbus
    libcanberra systemd-libs
)
makedepends=(
    git go python pkgconf ncurses rsync which file simde shader-slang
)
optdepends=(
    'imagemagick: display uncommon image formats'
    'shader-slang: custom shaders'
)
provides=('kitty')
conflicts=('kitty')

source=(
    "$pkgname::git+$_repo#branch=$_branch"
    "nerdfonts-symbols.tar.xz::https://github.com/ryanoasis/nerd-fonts/releases/download/v3.5.1/NerdFontsSymbolsOnly.tar.xz"
)
sha256sums=('SKIP' '01172f37db8543edb102e5cb5c64101c9f4686630804d49b419aa07b23a69996')

prepare() {
    # kitty embeds the mono variant of the Nerd font at build time, but Arch
    # only packages the proportional one, so ship the font with the build.
    mkdir -p "$pkgname/fonts"
    cp "$srcdir/SymbolsNerdFontMono-Regular.ttf" "$pkgname/fonts/"

    cd "$pkgname"
    # linux-package regenerates the man pages and the HTML docs, and some of
    # their dependencies (furo, sphinx-design) are not packaged for Arch, so
    # keep a local throwaway environment instead of requiring the system ones.
    # Do not reuse the system packages: pip would then skip installing sphinx
    # itself and the venv would have no sphinx-build entry point.
    python -m venv .docs-venv
    .docs-venv/bin/pip install --disable-pip-version-check -q -r docs/requirements.txt
}

package() {
    cd "$pkgname"
    # kitty's linux-package target stages a full self-contained install, so
    # pointing --prefix at the package root is enough; no manual file copying.
    PATH="$srcdir/$pkgname/.docs-venv/bin:$PATH" python setup.py linux-package --prefix "$pkgdir/usr"
    install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
