# Template file for 'textadept'
pkgname=textadept
version=12.9
revision=1
build_style=cmake
hostmakedepends="tar unzip pkg-config qt6-base"
makedepends="qt6-base-private-devel qt6-qt5compat-devel gtk+3-devel ncurses-devel"
short_desc="Fast, minimalist, and extensible text editor for programmers"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT"
homepage="https://orbitalquark.github.io/textadept/"
# Note: The dependency urls and filenames must be checked and updated manually
# for distfiles and skip_extraction variables on every new release (and
# checksums updated accordingly). This is so that XBPS can cache them. Details:
# https://github.com/void-linux/void-packages/pull/15627#issuecomment-549018252
# This goes for cmake.patch as well.
distfiles="https://github.com/orbitalquark/textadept/archive/textadept_${version}.tar.gz
 https://www.scintilla.org/scintilla557.tgz
 https://github.com/orbitalquark/scinterm/archive/scinterm_5.5.zip
 https://github.com/orbitalquark/scintillua/archive/scintillua_6.6.zip
 https://www.lua.org/ftp/lua-5.4.8.tar.gz
 https://www.inf.puc-rio.br/~roberto/lpeg/lpeg-1.1.0.tar.gz
 https://github.com/keplerproject/luafilesystem/archive/v1_8_0.zip
 https://github.com/orbitalquark/lua-std-regex/archive/1.0.zip
 https://github.com/ThomasDickey/cdk-snapshots/archive/refs/tags/t20240619.tar.gz
 https://www.leonerd.org.uk/code/libtermkey/libtermkey-0.22.tar.gz
 https://github.com/DaanDeMeyer/reproc/archive/refs/tags/v14.2.5.zip
 https://github.com/itay-grudev/SingleApplication/archive/refs/tags/v3.5.3.zip"
checksum="b675549ea3a77638f7bc02cf0f065c35eb2b3eb8ea721c40ea4539752a14b08b
 b37e1a239ff8c77cebd72db6ce25264b35cbecbbffad60f9ce7e838f5195a21e
 1bf084ccd564c0997c0881664a3b5510e5f56c3aa79e73bd8494775632d07f79
 ac5cdaf7f21279eb771ac122f6608cea6525f66a6d05f38a59bc4cc98290bc60
 4f18ddae154e793e46eeab727c59ef1c0c0c2b744e7b94219710d76f530629ae
 4b155d67d2246c1ffa7ad7bc466c1ea899bbc40fef0257cc9c03cecbaed4352a
 e3a6beca7a8a90522eed31db6ccdc5ed65a433826500c6862784e27671b9e18a
 5b684a1ce7ea632a37aa4f98bcf265cd97d9d70c5998c56985295c6aa97e74e1
 69a2c96ce23b3137929ecc011c67b030554cc532ab00a011cbbccf01dacaa611
 6945bd3c4aaa83da83d80a045c5563da4edd7d0374c62c0d35aec09eb3014600
 21b168c38adb22f4b48391d8193dbc3927f1f2e678c2058d6944a29b64acc6c9
 ec8a68a24da974397668370a5a9d1fe281bfcbd7390ed1b14642921634f1881f"
skip_extraction="
 scintilla557.tgz
 scinterm_5.5.zip
 scintillua_6.6.zip
 lua-5.4.8.tar.gz
 lpeg-1.1.0.tar.gz
 v1_8_0.zip
 1.0.zip
 t20240619.tar.gz
 libtermkey-0.22.tar.gz
 v14.2.5.zip
 v3.5.3.zip"

post_extract() {
	# We copy the downloaded dep files to build directory so that cmake doesn't try to redownload them.
	# This prevents build errors (xbps-src cmake can't use FetchContent) and improves caching.
	mkdir -p "${wrksrc}/${build_wrksrc}/${cmake_builddir:=build}/_deps"
	while read archive; do
		if [ -f "${XBPS_SRCDISTDIR}/${sourcepkg}-${version}/${archive}" ]; then
			cp "${XBPS_SRCDISTDIR}/${sourcepkg}-${version}/${archive}" \
				"${wrksrc}/${build_wrksrc}/${cmake_builddir:=build}/_deps"
		fi
	done< <(echo "${skip_extraction}")
}

post_install() {
	# Binaries in /usr/share/textadept are not allowed, so we relocate to /usr/lib/textadept
	mkdir -p "${DESTDIR}/usr/bin"
	mv "${DESTDIR}/usr/share/textadept" "${DESTDIR}/usr/lib/textadept"
	ln -sf "/usr/lib/textadept/textadept" "${DESTDIR}/usr/bin/textadept"
	ln -sf "/usr/lib/textadept/textadept-gtk" "${DESTDIR}/usr/bin/textadept-gtk"
	ln -sf "/usr/lib/textadept/textadept-curses" "${DESTDIR}/usr/bin/textadept-curses"

	# Link icons
	mkdir -p "${DESTDIR}/usr/share/pixmaps"
	ln -s "/usr/lib/textadept/core/images/textadept.svg" \
		"${DESTDIR}/usr/share/pixmaps/textadept.svg"
	ln -s "/usr/lib/textadept/core/images/ta_48x48.png" \
		"${DESTDIR}/usr/share/pixmaps/textadept.png"

	# Link .desktop entries
	# We don't link the GTK entry, as it has the same name as the QT entry
	mkdir -p "${DESTDIR}/usr/share/applications"
	ln -s "/usr/lib/textadept/textadept.desktop" "${DESTDIR}/usr/share/applications"
	ln -s "/usr/lib/textadept/textadept-curses.desktop" "${DESTDIR}/usr/share/applications"

	vlicense "${wrksrc}/${build_wrksrc}/LICENSE"
}
