35f7ce8af6b077820e50b4b835c1080178794fa8
[gentoo.git] / dev-lang / R / R-3.6.0.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 inherit bash-completion-r1 autotools eutils flag-o-matic fortran-2 multilib toolchain-funcs
7
8 # latest git commit for R bash completion: https://github.com/deepayan/rcompletion
9 BCPV=78d6830e28ea90a046da79a9b4f70c39594bb6d6
10
11 DESCRIPTION="Language and environment for statistical computing and graphics"
12 HOMEPAGE="http://www.r-project.org/"
13 SRC_URI="
14         mirror://cran/src/base/R-3/${P}.tar.gz
15         https://raw.githubusercontent.com/deepayan/rcompletion/${BCPV}/bash_completion/R -> ${PN}-${BCPV}.bash_completion"
16
17 LICENSE="|| ( GPL-2 GPL-3 ) LGPL-2.1"
18 SLOT="0"
19 KEYWORDS="~amd64 ~arm64 ~hppa ~ia64 ~sparc ~x86 ~amd64-linux ~x86-linux ~x64-macos"
20 IUSE="cairo doc icu java jpeg lapack minimal nls openmp perl png prefix profile readline static-libs tiff tk X"
21 REQUIRED_USE="png? ( || ( cairo X ) ) jpeg? ( || ( cairo X ) ) tiff? ( || ( cairo X ) )"
22
23 CDEPEND="
24         app-arch/bzip2:0=
25         app-arch/xz-utils:0=
26         app-text/ghostscript-gpl
27         >=dev-libs/libpcre-8.35:3=
28         net-libs/libtirpc
29         net-misc/curl
30         virtual/blas:0
31         || ( >=sys-apps/coreutils-8.15 app-misc/realpath )
32         cairo? ( x11-libs/cairo:0=[X=] x11-libs/pango:0= )
33         icu? ( dev-libs/icu:= )
34         jpeg? ( virtual/jpeg:0 )
35         lapack? ( virtual/lapack:0 )
36         perl? ( dev-lang/perl )
37         png? ( media-libs/libpng:0= )
38         readline? ( sys-libs/readline:0= )
39         tiff? ( media-libs/tiff:0= )
40         tk? ( dev-lang/tk:0= )
41         X? ( x11-libs/libXmu:0= x11-misc/xdg-utils )"
42
43 DEPEND="${CDEPEND}
44         virtual/pkgconfig
45         doc? (
46                 virtual/latex-base
47                 dev-texlive/texlive-fontsrecommended
48         )"
49
50 RDEPEND="${CDEPEND}
51         >=sys-libs/zlib-1.2.5.1-r2:0[minizip]
52         java? ( >=virtual/jre-1.5 )"
53
54 RESTRICT="minimal? ( test )"
55
56 PATCHES=(
57         "${FILESDIR}"/${PN}-3.4.1-parallel.patch
58         "${FILESDIR}"/${PN}-3.4.1-rmath-shared.patch
59 )
60
61 pkg_pretend() {
62         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
63 }
64
65 pkg_setup() {
66         if [[ ${MERGE_TYPE} != binary ]] && use openmp; then
67                 if ! tc-check-openmp; then
68                         ewarn "OpenMP is not available in your current selected compiler"
69                         die "need openmp capable compiler"
70                 fi
71                 FORTRAN_NEED_OPENMP=1
72         fi
73         fortran-2_pkg_setup
74         filter-ldflags -Wl,-Bdirect -Bdirect
75         # avoid using existing R installation
76         unset R_HOME
77         # Temporary fix for bug #419761
78         if [[ ($(tc-getCC) == *gcc) && ($(gcc-version) == 4.7) ]]; then
79                 append-flags -fno-ipa-cp-clone
80         fi
81 }
82
83 src_prepare() {
84         default
85
86         # fix packages.html for doc (gentoo bug #205103)
87         sed -e "s:../../../library:../../../../$(get_libdir)/R/library:g" \
88                 -i src/library/tools/R/Rd.R || die
89
90         # fix Rscript path when installed (gentoo bug #221061)
91         sed -e "s:-DR_HOME='\"\$(rhome)\"':-DR_HOME='\"${EROOT}/usr/$(get_libdir)/${PN}\"':" \
92                 -i src/unix/Makefile.in || die "sed unix Makefile failed"
93
94         # fix HTML links to manual (gentoo bug #273957)
95         sed -e 's:\.\./manual/:manual/:g' \
96                 -i $(grep -Flr ../manual/ doc) || die "sed for HTML links failed"
97
98         use lapack && \
99                 export LAPACK_LIBS="$($(tc-getPKG_CONFIG) --libs lapack)"
100
101         if use X; then
102                 export R_BROWSER="$(type -p xdg-open)"
103                 export R_PDFVIEWER="$(type -p xdg-open)"
104         fi
105         use perl && \
106                 export PERL5LIB="${S}/share/perl:${PERL5LIB:+:}${PERL5LIB}"
107
108         # don't search /usr/local
109         sed -i -e '/FLAGS=.*\/local\//c\: # removed by ebuild' configure.ac || die
110         # Fix for Darwin (OS X)
111         if use prefix; then
112                 if [[ ${CHOST} == *-darwin* ]] ; then
113                         sed -e 's:-install_name libR.dylib:-install_name ${libdir}/R/lib/libR.dylib:' \
114                                 -e 's:-install_name libRlapack.dylib:-install_name ${libdir}/R/lib/libRlapack.dylib:' \
115                                 -e 's:-install_name libRblas.dylib:-install_name ${libdir}/R/lib/libRblas.dylib:' \
116                                 -e "/SHLIB_EXT/s/\.so/.dylib/" \
117                                 -i configure.ac || die
118                         # sort of "undo" 2.14.1-rmath-shared.patch
119                         sed -e "s:-Wl,-soname=libRmath.so:-install_name ${EROOT}/usr/$(get_libdir)/libRmath.dylib:" \
120                                 -i src/nmath/standalone/Makefile.in || die
121                 else
122                         append-ldflags -Wl,-rpath="${EROOT}/usr/$(get_libdir)/R/lib"
123                 fi
124         fi
125         AT_M4DIR=m4
126         eautoreconf
127 }
128
129 src_configure() {
130         #       --with-system-tre \
131         # tre is patched from upstream
132         econf \
133                 --enable-byte-compiled-packages \
134                 --enable-R-shlib \
135                 --disable-R-framework \
136                 --with-blas="$($(tc-getPKG_CONFIG) --libs blas)" \
137                 --docdir="${EPREFIX}/usr/share/doc/${PF}" \
138                 rdocdir="${EPREFIX}/usr/share/doc/${PF}" \
139                 $(use_enable java) \
140                 $(use_enable nls) \
141                 $(use_enable openmp) \
142                 $(use_enable profile R-profiling) \
143                 $(use_enable profile memory-profiling) \
144                 $(use_enable static-libs static) \
145                 $(use_enable static-libs R-static-lib) \
146                 $(use_with cairo) \
147                 $(use_with icu ICU) \
148                 $(use_with jpeg jpeglib) \
149                 $(use_with lapack) \
150                 $(use_with !minimal recommended-packages) \
151                 $(use_with png libpng) \
152                 $(use_with readline) \
153                 $(use_with tiff libtiff) \
154                 $(use_with tk tcltk) \
155                 $(use_with tk tk-config "${EPREFIX}"/usr/$(get_libdir)/tkConfig.sh) \
156                 $(use_with tk tcl-config "${EPREFIX}"/usr/$(get_libdir)/tclConfig.sh) \
157                 $(use_with X x)
158 }
159
160 src_compile() {
161         export VARTEXFONTS="${T}/fonts"
162         emake AR="$(tc-getAR)"
163         emake -C src/nmath/standalone \
164                 shared $(use static-libs && echo static) AR="$(tc-getAR)"
165         use doc && emake info pdf
166 }
167
168 src_install() {
169         default
170         emake -j1 -C src/nmath/standalone DESTDIR="${D}" install
171
172         if use doc; then
173                 emake DESTDIR="${D}" install-info install-pdf
174                 dosym ../manual /usr/share/doc/${PF}/html/manual
175         fi
176
177         cat > 99R <<-EOF
178                 LDPATH=${EROOT}/usr/$(get_libdir)/${PN}/lib
179                 R_HOME=${EROOT}/usr/$(get_libdir)/${PN}
180         EOF
181         doenvd 99R
182         newbashcomp "${DISTDIR}"/${PN}-${BCPV}.bash_completion ${PN}
183         # The buildsystem has a different understanding of install_names than
184         # we require.  Since it builds modules like shared objects (wrong), many
185         # objects (all modules) get an incorrect install_name.  Fixing the build
186         # system here is not really trivial.
187         if [[ ${CHOST} == *-darwin* ]] ; then
188                 local mod
189                 pushd "${ED}"/usr/$(get_libdir)/R > /dev/null
190                 for mod in $(find . -name "*.dylib") ; do
191                         mod=${mod#./}
192                         install_name_tool -id "${EPREFIX}/usr/$(get_libdir)/R/${mod}" \
193                                 "${mod}"
194                 done
195                 popd > /dev/null
196         fi
197         docompress -x /usr/share/doc/${PF}/{BioC_mirrors.csv,CRAN_mirrors.csv,KEYWORDS.db,NEWS.rds}
198 }
199
200 pkg_postinst() {
201         if use java; then
202                 einfo "Re-initializing java paths for ${P}"
203                 R CMD javareconf
204         fi
205 }