# Template file for 'CLion'
pkgname=CLion
version=2019.3.4
revision=1
archs="i686 x86_64"
wrksrc="clion-${version}"
depends="jetbrains-jdk-bin giflib libXtst"
short_desc="Smart cross-platform IDE for C and C++"
maintainer="Anton Afanasyev <anton@doubleasoftware.com>"
license="custom:Commercial"
homepage="https://www.jetbrains.com/clion"
distfiles="https://download.jetbrains.com/cpp/CLion-${version}.tar.gz"
checksum=adb76d1d5b13b5fae3e3953c953ee16f3342ef36af404fc2873b9dc9d2190d72
repository=nonfree
restricted=yes
nopie=yes
# JetBrains' tools are self-sufficient and while they include code that appears to be linked to libs from other packages, these libs are either included in the tool package, or the code works by looking for one of several supported libs.
noverifyrdeps=yes

build_options="bundled_cmake bundled_gdb bundled_lldb"
build_options_default="bundled_cmake bundled_gdb bundled_lldb"
desc_option_bundled_cmake="Install bundled CMake"
desc_option_bundled_gdb="Install bundled GDB"
desc_option_bundled_lldb="Install bundled LLDB"

post_extract() {
	# Remove files for other CPU architectures
	rm -rf bin/fsnotifier-arm
	rm -rf lib/pty4j-native/linux/ppc64le

	case "$XBPS_TARGET_MACHINE" in
		x86_64)
			rm -rf bin/fsnotifier
			rm -rf bin/clion.vmoptions
			rm -rf bin/libyjpagent-linux.so
			rm -rf lib/pty4j-native/linux/x86
			;;
		i686)
			rm -rf bin/fsnotifier64
			rm -rf bin/clion64.vmoptions
			rm -rf bin/libyjpagent-linux64.so
			rm -rf lib/pty4j-native/linux/x86_64
			;;
	esac

	if [ ! "$build_option_bundled_cmake" ]; then
		rm -rf bin/cmake
	fi
	if [ ! "$build_option_bundled_gdb" ]; then
		rm -rf bin/gdb
	fi
	if [ ! "$build_option_bundled_lldb" ]; then
		rm -rf bin/lldb
	fi
}

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

	vmkdir usr/bin
	vmkdir ${TARGET_PATH}

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

	mkdir -p /usr/lib/jvm/jbrsdk
	ln -sf /usr/lib/jvm/jbrsdk ${DESTDIR}/${TARGET_PATH}/jbr
	vcopy bin ${TARGET_PATH}
	vcopy help ${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}/bin/clion.sh ${DESTDIR}/usr/bin/${pkgname}
}
