%define pkg_version 1.2.5001
%define pkg_release 1%{?_dist_release}

Summary:     An integrated development environment (IDE) for R
Summary(ja): Rのための統合開発環境
Name:        rstudio
Version:     %{pkg_version}
Release:     %{pkg_release}

License: AGPLv3
Group:   Applications/Edutainment
URL:     https://www.rstudio.com/
Source0: rstudio-%{version}.tar.gz

Source11: core-dictionaries.zip
Source12: mathjax-26.zip

# document for setting when RStudio crashs
Source101: Caution
Source102: Caution.ja

# patch to avoid download necessary files
Patch1: rstudio-1.2-dependencies_common_not_download.patch

# patches to use system pandoc
Patch2: rstudio-1.2-rsession-dev.conf.patch
Patch3: rstudio-1.2-SessionOptions.cpp.patch
Patch4: rstudio-1.2-session_CMakeLists.txt.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root

BuildRequires: rstudio-gwt
BuildRequires: cmake
BuildRequires: R >= 3.6
BuildRequires: pandoc pandoc-citeproc

# java-1.8.0-openjdk-devel is needed
BuildRequires: java-1.8.0-openjdk-devel
BuildRequires: ant >= 1.9
BuildRequires: xml-commons-apis
BuildRequires: libuuid-devel
BuildRequires: openssl-devel
BuildRequires: pam-devel
BuildRequires: pango-devel
BuildRequires: bzip2-devel zlib-devel

# libboost >= 1.63.0
BuildRequires: libboost-devel
BuildRequires: libboost
BuildRequires: libboost-atomic
BuildRequires: libboost-date-time
BuildRequires: libboost-filesystem
BuildRequires: libboost-iostreams
BuildRequires: libboost-program-options
BuildRequires: libboost-random
BuildRequires: libboost-regex
BuildRequires: libboost-signals
BuildRequires: libboost-system
BuildRequires: libboost-thread
BuildRequires: libboost-chrono

# qt5 >= 5.12.1
BuildRequires: qt5-qtbase-devel
BuildRequires: qt5-qtdeclarative-devel
BuildRequires: qt5-qtlocation-devel
BuildRequires: qt5-qtsensors-devel
BuildRequires: qt5-qtsvg-devel
BuildRequires: qt5-qtwebchannel-devel
BuildRequires: qt5-qtwebengine-devel
BuildRequires: qt5-qtxmlpatterns-devel

Requires: R >= 3.6
Requires: pandoc pandoc-citeproc
Requires: java-1.8.0-openjdk


Vendor: Project Vine
Distribution: Vine Linux
Packager: ara_t


%description
RStudio is a set of integrated tools designed to help you be more productive
with R. It includes a console, syntax-highlighting editor that supports
direct code execution, as well as tools for plotting, history, debugging
and workspace management.


[Caution]
If RStudio crashs, please use 'Software Rendering'.
  Within Tools -> Global Options... -> General -> Advanced
Select 'Software' among Rendering engine in OS Integration,
 and restart RStudio.

In detail, please see
  https://support.rstudio.com/hc/en-us/articles/360017886674-Troubleshooting-RStudio-Rendering-Errors


%description -l ja
RStudio™ はRのための新しい統合開発環境(IDE)です。RStudioは、あなたがRを
最大限利用する手助けとなるよう直感的なユーザインターフェイスと強力な
コーディングツールを結合させたものです。


【注意】
もしRStudioがクラッシュする場合には
'Software Rendering'を使用して下さい。

メニューの
 Tools -> Global Options... -> General -> Advanced
のタブに存在する OS Integration の Rendering engine で
 'Software' を選択してから Rstudio を再起動して下さい。

詳しくは
  https://support.rstudio.com/hc/en-us/articles/360017886674-Troubleshooting-RStudio-Rendering-Errors
を参照して下さい。


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q

# patch to avoid download necessary files
%patch1

# patches to use system pandoc
%patch2
%patch3
%patch4

%{__cp} /usr/src/rstudio-gwt/* \
 %{_builddir}/%{name}-%{version}/dependencies/common

%{__cp} \
 %{SOURCE11} %{SOURCE12} \
 %{_builddir}/%{name}-%{version}/dependencies/common

pushd dependencies/common
 sh install-gwt;
 sh install-dictionaries;
 sh install-mathjax;
popd

%build
IFS=. read -ra VER <<< %{version}
export RSTUDIO_VERSION_MAJOR=${VER[0]}
export RSTUDIO_VERSION_MINOR=${VER[1]}
export RSTUDIO_VERSION_PATCH=${VER[2]}

%{__mkdir_p} build
pushd build
cmake .. \
      -DRSTUDIO_TARGET=Desktop \
      -DCMAKE_BUILD_TYPE=Release \
      -DQT_QMAKE_EXECUTABLE=%{_bindir}/qmake-qt5 \
      -DCMAKE_INSTALL_PREFIX=%{_libdir}/rstudio
%{__make} %{?_smp_mflags}
popd

%install
pushd build
%{make_install}
popd

# make "/usr/bin/rstudio"
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_bindir}
echo "%{_libdir}/rstudio/bin/rstudio" > ${RPM_BUILD_ROOT}%{_bindir}/rstudio
%{__chmod} +x ${RPM_BUILD_ROOT}%{_bindir}/rstudio


# document for setting when RStudio crashs
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_docdir}/%{name}-%{version}
%{__cp} \
 %{SOURCE101} %{SOURCE102} \
 ${RPM_BUILD_ROOT}%{_docdir}/%{name}-%{version}


%clean
%{__rm} -rf ${RPM_BUILD_ROOT}

%post -p %{_syssbindir}/ldconfig

%postun -p %{_syssbindir}/ldconfig


%files
%defattr(-, root, root)
%doc COPYING NOTICE *.md
%{_bindir}/
%{_libdir}/rstudio/
%{_datadir}/applications/rstudio.desktop
%{_datadir}/icons/
%{_datadir}/mime/
%{_datadir}/pixmaps/
%{_docdir}/%{name}-%{version}/Caution*


%changelog
* Tue Oct 29 2019 Toshiaki Ara <ara_t@384.jp> 1.2.5000-1
- update to 1.2.5001

* Fri Nov 16 2018 Toshiaki Ara <ara_t@384.jp> 1.1.463-1
- new upstream release

* Sun Aug 19 2018 Toshiaki Ara <ara_t@384.jp> 1.1.456-1
- new upstream release
- drop SOURCE13 and SOURCE14

* Fri Jan 12 2018 Toshiaki Ara <ara_t@384.jp> 1.1.412-1
- new upstream release
- add BuildRequires: libboost-random
- add BuildRequires: qt5-qtwebchannel-devel
- update Patches

* Thu Aug 04 2016 Toshiaki Ara <ara_t@384.jp> 0.99.1274-2
- correct package desctiption

* Thu Aug 04 2016 Toshiaki Ara <ara_t@384.jp> 0.99.1274-1
- new package

