# Template file for 'PhpStorm'
pkgname=PhpStorm
version=2024.2.1
revision=1
archs="x86_64 aarch64"
depends="virtual?java-environment"
short_desc="Lightning-smart PHP IDE"
maintainer="Anton Afanasyev <anton@doubleasoftware.com>"
license="custom:Commercial"
homepage="https://www.jetbrains.com/phpstorm"

case "$XBPS_TARGET_MACHINE" in
	x86_64)
		distfiles="https://download.jetbrains.com/webide/PhpStorm-${version}.tar.gz"
		checksum=a9df519875815cd05b65324b4f0343584bd88f72df88d82a8dd87fc501b2c001
		;;

	aarch64)
		distfiles="https://download.jetbrains.com/webide/PhpStorm-${version}-aarch64.tar.gz"
		checksum=c360347841f3631e09b91a99e73433525508ef2b9ebac10ae6f0a518335a815e
		;;
esac

repository=nonfree
restricted=yes
nopie=yes
python_version=3

post_extract() {
	rm -rf plugins/gateway-plugin/lib/remote-dev-workers/remote-dev-worker-windows-amd64.exe
	rm -rf plugins/gateway-plugin/lib/remote-dev-workers/remote-dev-worker-windows-arm64.exe
	rm -rf plugins/gateway-plugin/lib/remote-dev-workers/remote-dev-worker-darwin-amd64
	rm -rf plugins/gateway-plugin/lib/remote-dev-workers/remote-dev-worker-darwin-arm64

	case "$XBPS_TARGET_MACHINE" in
		x86_64)
			rm -rf lib/async-profiler/aarch64
			rm -rf plugins/platform-ijent-impl/ijent-aarch64-unknown-linux-musl-release
			;;
		aarch64)
			rm -rf lib/pty4j/linux/x86_64
			rm -rf lib/native/linux-x86_64
			rm -rf lib/async-profiler/amd64
			rm -rf lib/jna/amd64
			rm -rf plugins/gateway-plugin/lib/remote-dev-workers/remote-dev-worker-linux-amd64
			rm -rf plugins/platform-ijent-impl/ijent-x86_64-unknown-linux-musl-release
			rm -rf plugins/cwm-plugin/quiche-native/linux-x86-64
			;;
	esac
}

do_install() {
	TARGET_PATH="usr/lib/${pkgname}"

	vmkdir usr/bin
	vmkdir ${TARGET_PATH}

	local i
	for i in license/* ; do
		vlicense $i
	done

	local launcher_path="bin/phpstorm.sh"
	sed -i '1 s/$/\nPHPSTORM_JDK=${PHPSTORM_JDK:-${IDEA_JDK}}/' "${launcher_path}"
	vcopy bin ${TARGET_PATH}
	vcopy help ${TARGET_PATH}
	vcopy jbr ${TARGET_PATH}
	vcopy lib ${TARGET_PATH}
	vcopy plugins ${TARGET_PATH}
	vcopy product-info.json ${TARGET_PATH}
	vcopy build.txt ${TARGET_PATH}

	ln -sf "/${TARGET_PATH}/${launcher_path}" "${DESTDIR}/usr/bin/${pkgname}"
	vdoc "${FILESDIR}/README.voidlinux"
}
