sci-libs/brial: amd64 stable wrt bug #717386
[gentoo.git] / dev-lang / ruby / ruby-2.4.10.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 autotools flag-o-matic multilib
7
8 MY_P="${PN}-$(ver_cut 1-3)"
9 S=${WORKDIR}/${MY_P}
10
11 SLOT=$(ver_cut 1-2)
12 MY_SUFFIX=$(ver_rs 1 '' ${SLOT})
13 RUBYVERSION=${SLOT}.0
14
15 DESCRIPTION="An object-oriented scripting language"
16 HOMEPAGE="https://www.ruby-lang.org/"
17 SRC_URI="https://cache.ruby-lang.org/pub/ruby/${SLOT}/${MY_P}.tar.xz"
18
19 LICENSE="|| ( Ruby-BSD BSD-2 )"
20 KEYWORDS="~alpha amd64 arm arm64 hppa ~mips ppc ppc64 s390 sparc x86"
21 IUSE="berkdb debug doc examples gdbm ipv6 jemalloc libressl +rdoc rubytests socks5 +ssl static-libs tk xemacs"
22
23 RDEPEND="
24         berkdb? ( sys-libs/db:= )
25         gdbm? ( sys-libs/gdbm:= )
26         jemalloc? ( dev-libs/jemalloc )
27         ssl? (
28                 !libressl? ( dev-libs/openssl:0= )
29                 libressl? ( dev-libs/libressl )
30         )
31         socks5? ( >=net-proxy/dante-1.1.13 )
32         tk? (
33                 dev-lang/tcl:0=[threads]
34                 dev-lang/tk:0=[threads]
35         )
36         dev-libs/libyaml
37         dev-libs/libffi:=
38         sys-libs/readline:0=
39         sys-libs/zlib
40         >=app-eselect/eselect-ruby-20161226
41         !<dev-ruby/rdoc-3.9.4
42         !<dev-ruby/rubygems-1.8.10-r1"
43
44 DEPEND="${RDEPEND}"
45
46 BUNDLED_GEMS="
47         >=dev-ruby/did_you_mean-1.1.0:2.4[ruby_targets_ruby24]
48         >=dev-ruby/minitest-5.10.1[ruby_targets_ruby24]
49         >=dev-ruby/net-telnet-0.1.1[ruby_targets_ruby24]
50         >=dev-ruby/power_assert-0.4.1[ruby_targets_ruby24]
51         >=dev-ruby/rake-12.0.0[ruby_targets_ruby24]
52         >=dev-ruby/test-unit-3.2.3[ruby_targets_ruby24]
53         >=dev-ruby/xmlrpc-0.2.1[ruby_targets_ruby24]
54 "
55
56 PDEPEND="
57         ${BUNDLED_GEMS}
58         virtual/rubygems[ruby_targets_ruby24]
59         >=dev-ruby/json-2.0.2[ruby_targets_ruby24]
60         rdoc? ( >=dev-ruby/rdoc-5.1.0-r1[ruby_targets_ruby24] )
61         xemacs? ( app-xemacs/ruby-modes )"
62
63 src_prepare() {
64         eapply "${FILESDIR}"/${SLOT}/{002,005,009,012}*.patch
65
66         einfo "Unbundling gems..."
67         cd "$S"
68         # Remove bundled gems that we will install via PDEPEND, bug
69         # 539700. Use explicit version numbers to ensure rm fails when they
70         # change so we can update dependencies accordingly.
71         rm -f gems/{did_you_mean-1.1.0,minitest-5.10.1,net-telnet-0.1.1,power_assert-0.4.1,rake-12.0.0,test-unit-3.2.3,xmlrpc-0.2.1}.gem || die
72
73         einfo "Removing bundled libraries..."
74         rm -fr ext/fiddle/libffi-3.2.1 || die
75
76         # Fix a hardcoded lib path in configure script
77         sed -i -e "s:\(RUBY_LIB_PREFIX=\"\${prefix}/\)lib:\1$(get_libdir):" \
78                 configure.in || die "sed failed"
79
80         eapply_user
81
82         eautoreconf
83 }
84
85 src_configure() {
86         local modules= myconf=
87
88         # -fomit-frame-pointer makes ruby segfault, see bug #150413.
89         filter-flags -fomit-frame-pointer
90         # In many places aliasing rules are broken; play it safe
91         # as it's risky with newer compilers to leave it as it is.
92         append-flags -fno-strict-aliasing
93         # SuperH needs this
94         use sh && append-flags -mieee
95
96         # Socks support via dante
97         if use socks5 ; then
98                 # Socks support can't be disabled as long as SOCKS_SERVER is
99                 # set and socks library is present, so need to unset
100                 # SOCKS_SERVER in that case.
101                 unset SOCKS_SERVER
102         fi
103
104         # Increase GC_MALLOC_LIMIT if set (default is 8000000)
105         if [ -n "${RUBY_GC_MALLOC_LIMIT}" ] ; then
106                 append-flags "-DGC_MALLOC_LIMIT=${RUBY_GC_MALLOC_LIMIT}"
107         fi
108
109         # ipv6 hack, bug 168939. Needs --enable-ipv6.
110         use ipv6 || myconf="${myconf} --with-lookup-order-hack=INET"
111
112         # Determine which modules *not* to build depending in the USE flags.
113         if ! use berkdb ; then
114                 modules="${modules},dbm"
115         fi
116         if ! use gdbm ; then
117                 modules="${modules},gdbm"
118         fi
119         if ! use ssl ; then
120                 modules="${modules},openssl"
121         fi
122         if ! use tk ; then
123                 modules="${modules},tk"
124         fi
125
126         # Provide an empty LIBPATHENV because we disable rpath but we do not
127         # need LD_LIBRARY_PATH by default since that breaks USE=multitarget
128         # #564272
129         INSTALL="${EPREFIX}/usr/bin/install -c" LIBPATHENV="" econf \
130                 --program-suffix=${MY_SUFFIX} \
131                 --with-soname=ruby${MY_SUFFIX} \
132                 --enable-shared \
133                 --enable-pthread \
134                 --disable-rpath \
135                 --with-out-ext="${modules}" \
136                 $(use_with jemalloc jemalloc) \
137                 $(use_enable socks5 socks) \
138                 $(use_enable doc install-doc) \
139                 --enable-ipv6 \
140                 $(use_enable static-libs static) \
141                 $(use_enable static-libs install-static-library) \
142                 $(use_with static-libs static-linked-ext) \
143                 $(use_enable debug) \
144                 ${myconf} \
145                 --enable-option-checking=no
146 }
147
148 src_compile() {
149         emake V=1 EXTLDFLAGS="${LDFLAGS}"
150 }
151
152 src_test() {
153         emake -j1 V=1 test
154
155         elog "Ruby's make test has been run. Ruby also ships with a make check"
156         elog "that cannot be run until after ruby has been installed."
157         elog
158         if use rubytests; then
159                 elog "You have enabled rubytests, so they will be installed to"
160                 elog "/usr/share/${PN}-${SLOT}/test. To run them you must be a user other"
161                 elog "than root, and you must place them into a writeable directory."
162                 elog "Then call: "
163                 elog
164                 elog "ruby${MY_SUFFIX} -C /location/of/tests runner.rb"
165         else
166                 elog "Enable the rubytests USE flag to install the make check tests"
167         fi
168 }
169
170 src_install() {
171         # Remove the remaining bundled gems. We do this late in the process
172         # since they are used during the build to e.g. create the
173         # documentation.
174         rm -rf ext/json || die
175
176         # Ruby is involved in the install process, we don't want interference here.
177         unset RUBYOPT
178
179         local MINIRUBY=$(echo -e 'include Makefile\ngetminiruby:\n\t@echo $(MINIRUBY)'|make -f - getminiruby)
180
181         LD_LIBRARY_PATH="${S}:${ED}/usr/$(get_libdir)${LD_LIBRARY_PATH+:}${LD_LIBRARY_PATH}"
182         RUBYLIB="${S}:${ED}/usr/$(get_libdir)/ruby/${RUBYVERSION}"
183         for d in $(find "${S}/ext" -type d) ; do
184                 RUBYLIB="${RUBYLIB}:$d"
185         done
186         export LD_LIBRARY_PATH RUBYLIB
187
188         emake V=1 DESTDIR="${D}" install
189
190         # Remove installed rubygems and rdoc copy
191         rm -rf "${ED}/usr/$(get_libdir)/ruby/${RUBYVERSION}/rubygems" || die "rm rubygems failed"
192         rm -rf "${ED}/usr/bin/"gem"${MY_SUFFIX}" || die "rm rdoc bins failed"
193         rm -rf "${ED}/usr/$(get_libdir)/ruby/${RUBYVERSION}"/rdoc* || die "rm rdoc failed"
194         rm -rf "${ED}/usr/bin/"{ri,rdoc}"${MY_SUFFIX}" || die "rm rdoc bins failed"
195
196         if use doc; then
197                 make DESTDIR="${D}" install-doc || die "make install-doc failed"
198         fi
199
200         if use examples; then
201                 dodoc -r sample
202         fi
203
204         dodoc ChangeLog NEWS doc/NEWS* README*
205
206         if use rubytests; then
207                 pushd test
208                 insinto /usr/share/${PN}-${SLOT}/test
209                 doins -r .
210                 popd
211         fi
212 }
213
214 pkg_postinst() {
215         if [[ ! -n $(readlink "${EROOT}"/usr/bin/ruby) ]] ; then
216                 eselect ruby set ruby${MY_SUFFIX}
217         fi
218
219         elog
220         elog "To switch between available Ruby profiles, execute as root:"
221         elog "\teselect ruby set ruby(23|24|...)"
222         elog
223 }
224
225 pkg_postrm() {
226         eselect ruby cleanup
227 }