# Template file for 'kitty'
pkgname=kitty
version=0.39.0
revision=1
build_helper="python3"
pycompile_dirs="usr/lib/kitty"
hostmakedepends="go pkg-config python3 wayland-devel wayland-protocols nerd-fonts-symbols-ttf"
makedepends="gettext-devel glfw-devel harfbuzz-devel libxkbcommon-devel
 python3-devel wayland-devel wayland-protocols libcanberra-devel
 openssl-devel dbus-devel libXcursor-devel libXrandr-devel libXi-devel
 fontconfig-devel libxcb-devel lcms2-devel xxHash-devel simde"
depends="kitty-terminfo-${version}_${revision} kitty-shell-integration-${version}_${revision}
 kitty-kitten-${version}_${revision}"
short_desc="Modern, hackable, featureful, OpenGL based terminal emulator"
maintainer="classabbyamp <void@placeviolette.net>"
license="GPL-3.0-only"
homepage="https://sw.kovidgoyal.net/kitty/"
changelog="https://sw.kovidgoyal.net/kitty/changelog.html"
distfiles="https://github.com/kovidgoyal/kitty/releases/download/v${version}/kitty-${version}.tar.xz"
checksum=c3f5d2371ce78ae29475d21d31264d41478357024f267d9f6038bb4bcdbc972b
python_version=3
nopie_files="/usr/bin/kitten"

LDFLAGS+=" -Wl,-z,stack-size=2097152"

# TIOCSWINSZ on ppc overflows signed int, used in ioctl()
# glibc defines it with ulong, musl with int (should be harmless)
case "$XBPS_TARGET_MACHINE" in
	ppc*-musl) CFLAGS+=" -Wno-error=overflow";;
esac

if [ "$CROSS_BUILD" ]; then
	# cursed but this build system is a hot mess
	hostmakedepends+=" $makedepends"
fi

do_build() {
	local _cross_args
	if [ "$CROSS_BUILD" ]; then
		# hot mess, continued
		env CC="cc" CFLAGS="$XBPS_CFLAGS" LDFLAGS="$XBPS_LDFLAGS" python3 setup.py build \
			--prefix="${DESTDIR}/usr" --update-check-interval=0 --verbose --debug
		python3 setup.py clean --clean-for-cross-compile
		_cross_args=(--skip-code-generation)
	fi
	. /void-packages/common/environment/build-style/go.sh
	python3 setup.py linux-package --prefix="${DESTDIR}/usr" --update-check-interval=0 \
		--verbose --debug "${_cross_args[@]}"
}

do_install() {
	vsconf $(find ${DESTDIR}/usr/share/doc/kitty/html/_downloads/ -name "kitty.conf")
}

kitty-terminfo_package() {
	short_desc+=" - terminfo data"
	pkg_install() {
		vmove usr/share/terminfo
	}
}

kitty-shell-integration_package() {
	short_desc+=" - shell integration scripts"
	pkg_install() {
		vmove usr/lib/kitty/shell-integration
	}
}

kitty-kitten_package() {
	short_desc+=" - kitten client"
	pkg_install() {
		vmove usr/bin/kitten
	}
}
