# Template file for 'textadept'
pkgname=textadept
version=11.1
revision=1
wrksrc="textadept-textadept_${version}"
build_wrksrc="src"
hostmakedepends="tar unzip pkg-config"
makedepends="gtk+3-devel ncurses-devel"
short_desc="Fast, minimalist, and extensible text editor for programmers"
maintainer="reback00 <reback00@protonmail.com>"
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
distfiles="https://github.com/orbitalquark/textadept/archive/textadept_${version}.tar.gz
 https://www.scintilla.org/scintilla445.tgz
 https://github.com/orbitalquark/scinterm/archive/6a774158d8a3c7bc7ea120bc01cdb016fa351a7e.zip
 https://github.com/orbitalquark/scintillua/archive/scintillua_4.4.5-2.zip
 https://www.lua.org/ftp/lua-5.3.5.tar.gz
 http://www.inf.puc-rio.br/~roberto/lpeg/lpeg-1.0.2.tar.gz
 https://github.com/keplerproject/luafilesystem/archive/v1_8_0.zip
 https://github.com/orbitalquark/gtdialog/archive/64587546482a1a6324706d75c80b77d2f87118a4.zip
 https://invisible-mirror.net/archives/cdk/cdk-5.0-20200923.tgz
 http://www.leonerd.org.uk/code/libtermkey/libtermkey-0.20.tar.gz"
checksum="87d67975b22952344e1bdcb330301b88cdfe8242e7710526cd344ab252499c2a
 4f2168684b4024dc3d6b267320fff1d729192047f4a1b79aeab9ec7c64f733ec
 3b1e3cc3ee48bb158d1d666c7c86d190905c973918914876f6ab3712f8dd7d20
 ccd5b3d615116b8c4376086cf1d03b6ef1f67a565e57446b15eba3f39ef0c180
 0c2eed3f960446e1a3e4b9a1ca2f3ff893b6ce41942cf54d5dd59ab4b3b058ac
 48d66576051b6c78388faad09b70493093264588fcd0f258ddaab1cdd4a15ffe
 e3a6beca7a8a90522eed31db6ccdc5ed65a433826500c6862784e27671b9e18a
 093a4f973196083610c4489e8d9272f340ebf82d48c064f1542c6464eda2af82
 007f5de880cb2eebd8556df7e4cd8673d5e64c9970147eee6923a814c29faaed
 6c0d87c94ab9915e76ecd313baec08dedf3bd56de83743d9aa923a081935d2f5"
skip_extraction="scintilla445.tgz
 6a774158d8a3c7bc7ea120bc01cdb016fa351a7e.zip
 scintillua_4.4.5-2.zip
 lua-5.3.5.tar.gz
 lpeg-1.0.2.tar.gz
 v1_8_0.zip
 64587546482a1a6324706d75c80b77d2f87118a4.zip
 cdk-5.0-20200923.tgz
 libtermkey-0.20.tar.gz"

post_extract() {
	# We copy the downloaded dep files to src directory so that they are found
	# and not downloaded again by the build process. This helps to utilize caching.
	echo "${skip_extraction}" | while read archive; do
		if [ -f "${XBPS_SRCDISTDIR}/${sourcepkg}-${version}/${archive}" ]; then
			cp "${XBPS_SRCDISTDIR}/${sourcepkg}-${version}/${archive}" \
				"${wrksrc}/${build_wrksrc}/"
		fi
	done
}

pre_configure() {
	# For cross builds
	vsed -i \
		-e '/^CC =/d' \
		-e '/^CFLAGS =/d' \
		-e '/^CXX =/d' \
		-e 's/^CXXFLAGS =.*/CXXFLAGS += -std=c++17/' Makefile
}

do_build() {
	make deps
	make ${makejobs} GTK3=1
	make ${makejobs} curses
}

do_install() {
	make PREFIX=/usr DESTDIR="${DESTDIR}" install
	make curses PREFIX=/usr DESTDIR="${DESTDIR}" install

	# Binaries in /usr/share/textadept are not allowed
	# So we relocate to /usr/lib/textadept
	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-curses" \
		"${DESTDIR}/usr/bin/textadept-curses"

	# For 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"

	vlicense ../LICENSE
}
