# Template file for 'rstudio'
pkgname=rstudio
version=1.4.1717
revision=7
build_style=cmake
configure_args="-DRSTUDIO_TARGET=Desktop
 -DRSTUDIO_USE_SYSTEM_BOOST=ON
 -DRSTUDIO_USE_SYSTEM_SOCI=TRUE
 -DRSTUDIO_USE_SYSTEM_YAML_CPP=TRUE
 -DRSTUDIO_BOOST_SIGNALS_VERSION=2
 -DQT_QMAKE_EXECUTABLE=/usr/lib/qt5/bin/qmake
 -DCMAKE_INSTALL_PREFIX=/usr/lib/rstudio"
hostmakedepends="unzip pandoc openjdk8 apache-ant R qt5-qmake
 qt5-host-tools which nodejs"
makedepends="zlib-devel libuuid-devel openssl-devel pam-devel R mathjax
 boost-devel pango-devel hunspell-devel qt5-devel qt5-webkit-devel
 qt5-declarative-devel qt5-location-devel qt5-sensors-devel qt5-svg-devel
 qt5-xmlpatterns-devel qt5-webchannel-devel qt5-webengine-devel sqlite-devel
 qt5-plugin-pgsql qt5-plugin-mysql qt5-plugin-sqlite qt5-plugin-tds qt5-plugin-odbc
 soci-devel yaml-cpp-devel"
depends="R mathjax"
short_desc="Integrated development environment (IDE) for R"
maintainer="John <me@johnnynator.dev>"
license="AGPL-3.0-only"
homepage="https://www.rstudio.com"
distfiles="https://github.com/rstudio/rstudio/archive/v${version}.tar.gz
 https://s3.amazonaws.com/rstudio-dictionaries/core-dictionaries.zip
 https://github.com/catchorg/Catch2/releases/download/v2.13.10/catch.hpp"
checksum="3af234180fd7cef451aef40faac2c7b52860f14a322244c1c7aede029814d261
 4341a9630efb9dcf7f215c324136407f3b3d6003e1c96f2e5e1f9f14d5787494
 3725c0f0a75f376a5005dde31ead0feb8f7da7507644c201b814443de8355170"
skip_extraction="core-dictionaries.zip catch.hpp"

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

post_extract() {
	_srcdir="${XBPS_SRCDISTDIR}/${pkgname}-${version}"

	unzip -qd ${wrksrc}/dependencies/dictionaries ${_srcdir}/core-dictionaries.zip
	cp ${_srcdir}/catch.hpp src/cpp/tests/cpp/tests/vendor/catch.hpp
}

pre_configure() {
	_node_ver="10.19.0"
	_pandoc_ver="2.11.4"
	ln -s /usr/share/mathjax dependencies/common/mathjax-27
	mkdir -p dependencies/common/pandoc/$_pandoc_ver/bin
	ln -s /usr/bin/pandoc dependencies/common/pandoc/$_pandoc_ver/bin
	mkdir -p dependencies/common/node/$_node_ver/bin
	ln -s /usr/bin/node dependencies/common/node/$_node_ver/bin/node
	cd src/gwt
	ant draft

	_maj_min=${version%*.*}
	export RSTUDIO_VERSION_MAJOR=${_maj_min%.*}
	export RSTUDIO_VERSION_MINOR=${_maj_min#*.}
	export RSTUDIO_VERSION_PATCH=${version#*.*.*}
	export PACKAGE_OS=VoidLinux
}

post_install() {
	mkdir -p ${DESTDIR}/usr/bin

	for f in {diagnostics,rpostback,rsession,rstudio}; do
		ln -sf /usr/lib/rstudio/bin/${f} ${DESTDIR}/usr/bin/
	done
	vlicense COPYING
}
