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

Summary:          A language for data analysis and graphics
Summary(ja):      データ解析・グラフィック化の言語
Name:             R
Version:          %{pkg_version}
Release:          %{pkg_release}

License:          GPLv2+
Group:            Applications/Edutainment
URL:              http://www.r-project.org

Source0:          ftp://cran.r-project.org/pub/R/src/base/R-2/%{name}-%{version}.tar.gz
Source1:          R.desktop
#Patch0:           R-release.diff.gz

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: gcc-c++
BuildRequires: gcc-gfortran libgfortran
BuildRequires: texlive
BuildRequires: texlive-common
BuildRequires: texlive-collection-basic
BuildRequires: texlive-collection-texinfo
BuildRequires: texlive-collection-fontsextra
BuildRequires: texinfo tcl tk
BuildRequires: libpng-devel libjpeg-devel libtiff-devel
BuildRequires: readline-devel libtermcap-devel
BuildRequires: zlib-devel bzip2-devel 
BuildRequires: libSM-devel libX11-devel libICE-devel libXt-devel libXmu-devel
BuildRequires: cairo-devel pango-devel
BuildRequires: libicu-devel
Requires: libgfortran

Vendor: Project Vine
Distribution: Vine Linux
Packager: Toshiaki Ara <ara_t@384.jp>

%description
'GNU S' - A language and environment for statistical computing and
graphics. R is similar to the award-winning S system, which was
developed at Bell Laboratories by John Chambers et al. It provides
a wide variety of statistical and graphical techniques (linear and
nonlinear modelling, statistical tests, time series analysis,
classification, clustering, ...).

R is designed as a true computer language with control-flow
constructions for iteration and alternation, and it allows users to
add additional functionality by defining new functions. 
For computationally intensive tasks, C, C++ and Fortran code
can be linked and called at run time.

%description -l ja
'GNU S' - 統計解析とグラフィックスのプログラミング言語と環境。
Rは、ベル研究所のJohn Chambersらが開発した輝けるS言語に似ており、
線形・非線型モデル、統計検定、時系列分析、クラスター分析など
幅広い統計解析・視覚化手法を提供する。
Rは、条件分岐や反復計算などの制御構造を持つ正真正銘のコンピュータ言語
として設計されており、ユーザが新たに関数を組み込むことが可能である。
また、計算量が多いときにはC、 C++、Fortranなどのコードとリンクさせて
使用することができる。

%package devel
Summary:          files for development of R packages.
Summary(ja):      Rパッケージ開発用ファイル
Group:            Development/Libraries
Requires:         R = %{version}-%{release}

%description devel
Install R-devel if you are going to develop or compile R packages.

This is just a stub package containing the documentation on
"Writing R Extensions".  However, installing it will ensure that
the build environment for R packages is correct.

%description -l ja devel
Rパッケージを開発したりコンパイルする場合には、このR-develを
インストールします。R-exts.pdf ("Writing R Extensions": 英文)
が含まれているだけのサブパッケージですが、正しくRパッケージを
開発するための助けになるでしょう。

%package -n libRmath
Summary:          standalone math library from the R project
Summary(ja):      単独で動作するRプロジェクトの数理ライブラリ
Group:            System Environment/Libraries

%description -n libRmath
A standalone library of mathematical and statistical functions derived
from the R project.  This packages provides the shared libRmath library.

%description -l ja -n libRmath
単独で動作するRプロジェクトの数理統計ライブラリで、libRmath.soという
共有ライブラリを提供する。

%package -n libRmath-devel
Summary:          standalone math library from the R project
Summary(ja):      libRmathの開発ライブラリ
Group:            Development/Libraries
Requires:         libRmath = %{version}-%{release}

%description -n libRmath-devel
A standalone library of mathematical and statistical functions derived
from the R project.  This packages provides the header files.

%description -l ja -n libRmath-devel
libRmathのヘッダファイル（Rmath.h）

%package -n libRmath-static
Summary: Static R Standalone math library
Summary(ja): libRmath の静的ライブラリ
Group: Development/Libraries
Requires: libRmath-devel = %{version}-%{release}

%description -n libRmath-static
A standalone library of mathematical and statistical functions derived
from the R project.  This package provides the static libRmath library.


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q
#%patch0 -p1

%build
export R_PDFVIEWER="%{_bindir}/xdg-open"
export R_PRINTCMD="lpr"
export R_BROWSER="%{_bindir}/xdg-open"

%configure --enable-R-shlib

%{__make} %{?_smp_mflags}
(cd src/nmath/standalone; %{__make} %{?_smp_mflags})
LANG=C make check-all
%{__make} pdf
#We can only "make info" if we have an up to date version of texinfo
%{?INFO: %{__make} info}


%install
%{__make} install DESTDIR=${RPM_BUILD_ROOT} install-pdf %{?INFO:install-info}
%{__rm} -f ${RPM_BUILD_ROOT}%{_infodir}/dir
%{__rm} -f ${RPM_BUILD_ROOT}%{_infodir}/dir.old

#Install libRmath files
(cd src/nmath/standalone; %{__make} install DESTDIR=${RPM_BUILD_ROOT})

mkdir -p ${RPM_BUILD_ROOT}/etc/ld.so.conf.d
echo "%{_libdir}/R/lib" > ${RPM_BUILD_ROOT}/etc/ld.so.conf.d/%{name}-%{_arch}.conf

#Fix lication of R_HOME_DIR in shell wrapper
sed -e "s@R_HOME_DIR=.*@R_HOME_DIR=%{_libdir}/R@" bin/R \
  > ${RPM_BUILD_ROOT}%{_libdir}/R/bin/R
chmod 755 ${RPM_BUILD_ROOT}%{_libdir}/R/bin/R
sed -e "s@R_HOME_DIR=.*@R_HOME_DIR=%{_libdir}/R@" bin/R \
  > ${RPM_BUILD_ROOT}%{_bindir}/R
chmod 755 ${RPM_BUILD_ROOT}%{_bindir}/R

# add R into menu
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/applications
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/icons

cp -a %{SOURCE1} ${RPM_BUILD_ROOT}%{_datadir}/applications/
cp -a doc/html/logosm.jpg ${RPM_BUILD_ROOT}%{_datadir}/icons/


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


%post 
%if 0%{?INFO}
   # Create directory entries for info files
   # (optional doc files, so we must check that they are installed)
   for doc in admin data exts FAQ intro lang; do
      file=%{_infodir}/R-${doc}.info.gz
      if [ -e $file ]; then
         /sbin/install-info ${file} %{_infodir}/dir 2>/dev/null
      fi
   done
%endif
%{_syssbindir}/ldconfig


%preun 
%if 0%{?INFO}
   if [ $1 = 0 ]; then
      # Delete directory entries for info files (if they were installed)
      for doc in admin data exts FAQ intro lang; do
         file=%{_infodir}/R-${doc}.info.gz
         if [ -e ${file} ]; then
            /sbin/install-info --delete R-${doc} %{_infodir}/dir 2>/dev/null
         fi
      done
   fi
%endif

%postun -p %{_syssbindir}/ldconfig

%post -n libRmath -p %{_syssbindir}/ldconfig

%postun -n libRmath -p %{_syssbindir}/ldconfig


%files
%defattr(-, root, root)
%{_bindir}/R
%{_bindir}/Rscript
%{_libdir}/R
%{_datadir}/applications/*
%{_datadir}/icons/*
%{?INFO:%{_infodir}/R-*.info*}
%{_mandir}/man1/*
/etc/ld.so.conf.d/*

%files devel
%defattr(-, root, root)
%doc doc/manual/R-exts.pdf

%files -n libRmath
%defattr(-, root, root)
%{_libdir}/libRmath.so

%files -n libRmath-devel
%defattr(-, root, root)
%{_libdir}/pkgconfig/*.pc
%{_includedir}/Rmath.h

%files -n libRmath-static
%defattr(-, root, root)
%{_libdir}/libRmath.a


%changelog
* Mon Oct 29 2012 Toshiaki Ara <ara_t@384.jp> 2.15.2-1
- Updated to 2.15.2

* Sat Sep 08 2012 Toshiaki Ara <ara_t@384.jp> 2.15.1-2
- changed group to Applications/Edutainment
- added R to menu

* Sat Jun 25 2012 Toshiaki Ara <ara_t@384.jp> 2.15.1-1
- Updated to 2.15.1

* Sat Mar 31 2012 Toshiaki Ara <ara_t@384.jp> 2.15.0-1
- Updated to 2.15.0

* Thu Mar 01 2012 Toshiaki Ara <ara_t@384.jp> 2.14.2-1
- Updated to 2.14.2

* Sat Dec 24 2011 Toshiaki Ara <ara_t@384.jp> 2.14.1-1
- Updated to 2.14.1

* Tue Nov 01 2011 Toshiaki Ara <ara_t@384.jp> 2.14.0-1
- Updated to 2.14.0
- add BuildRequires: texlive-collection-fontsextra

* Thu Oct 27 2011 Toshiaki Ara <ara_t@384.jp> 2.13.2-1
- Updated to 2.13.2
- add BuildRequires: texlive-common
- use texlive instead of tetex on Vine5 because of failure to create R-exts.pdf
- removed --enable-R-shlib option to %%configure on Vine5 because of segmentation fault

* Sat Sep  3 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.13.1-2
- synchronized to VinePlus/5 package
  * Sat Jul 09 2011 Toshiaki Ara <ara_t@384.jp> 2.13.1-1vl5
  - Updated to 2.13.1
  * Wed Apr 14 2011 Toshiaki Ara <ara_t@384.jp> 2.13.0-1vl5
  - Updated to 2.13.0
  * Wed Mar 02 2011 Toshiaki Ara <ara_t@384.jp> 2.12.2-1vl5
  - Updated to 2.12.2

* Sun Feb 27 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.12.1-3
- add BuildRequires: libicu-devel

* Fri Feb 25 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.12.1-2
- synchronized to VinePlus/5 package
  * Tue Dec 21 2010 Toshiaki Ara <ara_t@384.jp> 2.12.1-1vl5
  - Updated to 2.12.1
- added --enable-R-shlib option to %%configure
- added static subpackage
- use BR: texlive instead of tetex on VineSeed 

* Sun Sep 26 2010 Shu KONNO <owa@bg.wakwak.com> 2.11.0-3
- rebuilt with rpm-4.8.1 for pkg-config

* Thu Apr 24 2010 Toshiaki Ara <ara_t@384.jp> 2.11.0-2vl5
- recompiled because tcl/tk were not linked 

* Thu Apr 23 2010 Toshiaki Ara <ara_t@384.jp> 2.11.0-1vl5
- Updated to 2.11.0
- added Requires: libgfortran

* Thu Dec 15 2009 Toshiaki Ara <ara_t@384.jp> 2.10.1-1vl5
- Updated to 2.10.1

* Thu Nov 06 2009 Toshiaki Ara <ara_t@384.jp> 2.10.0-3vl5
- patched to 2.10.0

* Sat Oct 31 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.10.0-2
- spec in UTF-8

* Thu Oct 27 2009 Toshiaki Ara <ara_t@384.jp> 2.10.0-1vl5
- Updated to 2.10.0

* Thu Sep 23 2009 Toshiaki Ara <ara_t@384.jp> 2.9.2-1vl5
- Updated to 2.9.2
- deleted BuildRequires: lapack-devel blas-devel
- rewrote SPEC file

* Thu Aug 16 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1:2.5.1-0vl1
- Updated to 2.5.1
- added BuildRequires: gcc-gfortran for VineSeed
- added BuildRequires: lapack-devel blas-devel
- fixed %preun script

* Wed Dec 20 2006 Susumu Tanimura <stanimura-ngs@umin.ac.jp> 1:2.4.1-0vl1
- Updated to 2.4.1
- Added INFO option
- Exclude Japanese Rprofile.site

* Mon Oct 30 2006 Susumu Tanimura <stanimura-ngs@umin.ac.jp>
- Updated to 2.4.0

* Mon Oct 2 2006 Martyn Plummer <plummer@iarc.fr> 1:2.3.1-2
- Added optimization flags

* Tue Jun  6 2006 Susumu Tanimura <stanimura-ngs@umin.ac.jp> 1:2.3.1-0vl1
- Packaged for VineLinux3.2

* Tue May  9 2006 Susumu Tanimura <stanimura-ngs@umin.ac.jp> 1:2.3.0-0vl2
- Use JAVA_HOME for R_JAVA_LD_LIBRARY_PATH 

* Mon May  8 2006 Susumu Tanimura <stanimura-ngs@umin.ac.jp> 1:2.3.0-0vl1
- Packaged for VineLinux3.2
- Slipped texinfo
- Fixed preun error
- Preset Japanese fonts

* Thu Jan 12 2006 Susumu Tanimura <stanimura-ngs@umin.ac.jp>
- Packaged for VineLinux3.2

* Tue Jan 3 2006 Martyn Plumer <plummber@iarc.fr> 1:2.2.1-1
- Restored CAPABILITIES file lost in 2.2.1beta

* Mon Dec 12 2005 Martyn Plummer <plummer@iarc.fr> 1:2.2.1beta-1
- Configure uses --without-blas by default.
- Install pdf manuals.
- All toplevel documentation files are installed into _libdir/R
  as they may be required by R (qv note on AUTHORS and THANKS below).
- Legacy scripts for rebuilding package indices removed.

* Mon Sep 19 2005 Martyn Plummer <plummer@iarc.fr> 1:2.2.0-0
- R now compiles with gcc 4.0.1 and default rpm optimization flags.

* Wed Jul 13 2005 Martyn Plummer <plummer@iarc.fr> 1:2.1.1-2
- The files AUTHORS and THANKS need to be installed into _libdir/R
  as they are required by the function contributors().  Previously
  they were installed only as documentation files.

* Tue Jun 21 2005 Martyn Plummer <plummer@iarc.fr>
- Corrected date error in SPEC file.

* Sun Jun 19 2005 Martyn Plummer <plummer@iarc.fr>
- Dropped support for Red Hat boxed set.
- Synchronized with Fedora Extras 4 RPM by Tom Calloway
  including support for shared R library.
- Added gfortran support. However, gcc 4.0.0 will not compile R correctly
  with the default optimization flags, so there is a temporary work-around.

* Wed Jun 15 2005 Gernot Stocker <gernot.stocker@tugraz.at>
- Adaptations for CentOS and Rocks-Linux, tested under Release 4.0

* Sat Apr 30 2005 Joseph P. Skudlarek <Jskud@Jskud.com> 0:2.1.0-0.fdr.3
- Install R-data.info file as well.
- Make info processing conditional on texinfo version, not platform release,
  so that if a new enough version is installed, we will build and install info.

* Mon Apr 18 2005 Martyn Plummer <plummer@iarc.fr> 0:2.1.0-0.fdr.1
- Built R 2.1.0.  R now supports internationalization, so the patch
  to set the locale to "C" is now dropped.
- install.packages() exits gracefully with a helpful message if
  the file INSTALL is not present, so this is now included in the
  R-devel package.

* Mon Mar 14 2005 Martyn Plummer <plummer@iarc.fr> 0:2.0.1-0.fdr.5
- Added support for Scientific Linux (http://www.scientificlinux.org)
  A distribution based on RHEL. Thanks to Jon Peatfield.

* Mon Feb 28 2005 Martyn Plummer <plummer@iarc.fr> 0:2.0.1-0.fdr.4
- Fixed file ownership in R-devel and libRmath packages

* Wed Feb 16 2005 Martyn Plummer <plummer@iarc.fr> 0:2.0.1-0.fdr.3
- R-devel package is now a stub package with no files, except a documentation
  file (RPM won't accept sub-packages with no files). R now conflicts
  with earlier (i.e 0:2.0.1-0.fdr.2) versions of R-devel.
- Created libRmath subpackage with shared library.

* Mon Jan 31 2005 Martyn Plummer <plummer@iarc.fr> 0:2.0.1-0.fdr.2
- Created R-devel and libRmath-devel subpackages

* Mon Nov 15 2004 Martyn Plummer <plummer@iarc.fr> 0:2.0.1-0.fdr.1
- Built R 2.0.1

* Wed Nov 10 2004 Martyn Plummer <plummer@iarc.fr> 0:2.0.0-0.fdr.3
- Set R_PRINTCMD at configure times so that by default getOption(printcmd)
  gives "lpr".
- Define macro fcx for all Fedora distributions. This replaces Rinfo

* Tue Oct 12 2004 Martyn Plummer <plummer@iarc.fr> 0:2.0.0-0.fdr.2
- Info support is now conditional on the macro Rinfo, which is only
  defined for Fedora 1 and 2. 

* Thu Oct 7 2004 Martyn Plummer <plummer@iarc.fr> 0:2.0.0-0.fdr.1
- Built R 2.0.0
- There is no longer a BUGS file, so this is not installed as a
  documentation file.
