dev-lang/ruby: depend on dev-libs/libffi directly
[gentoo.git] / dev-lang / ruby / ruby-2.7.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 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 ~sh ~sparc ~x86"
21 IUSE="berkdb debug doc examples gdbm ipv6 jemalloc jit 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         jit? ( || ( sys-devel/gcc:* sys-devel/clang:* ) )
28         ssl? (
29                 !libressl? ( dev-libs/openssl:0= )
30                 libressl? ( dev-libs/libressl )
31         )
32         socks5? ( >=net-proxy/dante-1.1.13 )
33         tk? (
34                 dev-lang/tcl:0=[threads]
35                 dev-lang/tk:0=[threads]
36         )
37         dev-libs/libyaml
38         dev-libs/libffi:=
39         sys-libs/readline:0=
40         sys-libs/zlib
41         >=app-eselect/eselect-ruby-20171225
42 "
43
44 DEPEND="${RDEPEND}"
45
46 BUNDLED_GEMS="
47         >=dev-ruby/minitest-5.13.0[ruby_targets_ruby27]
48         >=dev-ruby/net-telnet-0.2.0[ruby_targets_ruby27]
49         >=dev-ruby/power_assert-1.1.5[ruby_targets_ruby27]
50         >=dev-ruby/rake-13.0.1[ruby_targets_ruby27]
51         >=dev-ruby/test-unit-3.3.4[ruby_targets_ruby27]
52         >=dev-ruby/xmlrpc-0.3.0[ruby_targets_ruby27]
53 "
54
55 PDEPEND="
56         ${BUNDLED_GEMS}
57         virtual/rubygems[ruby_targets_ruby27]
58         >=dev-ruby/bundler-2.1.0[ruby_targets_ruby27]
59         >=dev-ruby/did_you_mean-1.3.1[ruby_targets_ruby27]
60         >=dev-ruby/json-2.0.2[ruby_targets_ruby27]
61         rdoc? ( >=dev-ruby/rdoc-6.1.2[ruby_targets_ruby27] )
62         xemacs? ( app-xemacs/ruby-modes )"
63
64 src_prepare() {
65         # 005 does not compile bigdecimal and is questionable because it
66         # compiles ruby in a non-standard way, may be dropped
67         eapply "${FILESDIR}"/2.7/010*.patch
68
69         einfo "Unbundling gems..."
70         cd "$S"
71         # Remove bundled gems that we will install via PDEPEND, bug
72         # 539700.
73         rm -fr gems/* || die
74         # Don't install CLI tools since they will clash with the gem
75         rm -f bin/{racc,racc2y,y2racc} || die
76         sed -i -e '/executables/ s:^:#:' lib/racc/racc.gemspec || die
77
78         einfo "Removing bundled libraries..."
79         rm -fr ext/fiddle/libffi-3.2.1 || die
80
81         eapply_user
82
83         eautoreconf
84 }
85
86 src_configure() {
87         local modules= myconf=
88
89         # -fomit-frame-pointer makes ruby segfault, see bug #150413.
90         filter-flags -fomit-frame-pointer
91         # In many places aliasing rules are broken; play it safe
92         # as it's risky with newer compilers to leave it as it is.
93         append-flags -fno-strict-aliasing
94         # SuperH needs this
95         use sh && append-flags -mieee
96
97         # Socks support via dante
98         if use socks5 ; then
99                 # Socks support can't be disabled as long as SOCKS_SERVER is
100                 # set and socks library is present, so need to unset
101                 # SOCKS_SERVER in that case.
102                 unset SOCKS_SERVER
103         fi
104
105         # Increase GC_MALLOC_LIMIT if set (default is 8000000)
106         if [ -n "${RUBY_GC_MALLOC_LIMIT}" ] ; then
107                 append-flags "-DGC_MALLOC_LIMIT=${RUBY_GC_MALLOC_LIMIT}"
108         fi
109
110         # ipv6 hack, bug 168939. Needs --enable-ipv6.
111         use ipv6 || myconf="${myconf} --with-lookup-order-hack=INET"
112
113         # Determine which modules *not* to build depending in the USE flags.
114         if ! use berkdb ; then
115                 modules="${modules},dbm"
116         fi
117         if ! use gdbm ; then
118                 modules="${modules},gdbm"
119         fi
120         if ! use ssl ; then
121                 modules="${modules},openssl"
122         fi
123         if ! use tk ; then
124                 modules="${modules},tk"
125         fi
126
127         # Provide an empty LIBPATHENV because we disable rpath but we do not
128         # need LD_LIBRARY_PATH by default since that breaks USE=multitarget
129         # #564272
130         INSTALL="${EPREFIX}/usr/bin/install -c" LIBPATHENV="" econf \
131                 --program-suffix=${MY_SUFFIX} \
132                 --with-soname=ruby${MY_SUFFIX} \
133                 --docdir=${EPREFIX}/usr/share/doc/${P} \
134                 --enable-shared \
135                 --enable-pthread \
136                 --disable-rpath \
137                 --with-out-ext="${modules}" \
138                 $(use_with jemalloc jemalloc) \
139                 $(use_enable jit jit-support ) \
140                 $(use_enable socks5 socks) \
141                 $(use_enable doc install-doc) \
142                 --enable-ipv6 \
143                 $(use_enable static-libs static) \
144                 $(use_enable static-libs install-static-library) \
145                 $(use_with static-libs static-linked-ext) \
146                 $(use_enable debug) \
147                 ${myconf} \
148                 --enable-option-checking=no
149
150         # Makefile is broken because it lacks -ldl
151         rm -rf ext/-test-/popen_deadlock || die
152 }
153
154 src_compile() {
155         emake V=1 EXTLDFLAGS="${LDFLAGS}" MJIT_CFLAGS="${CFLAGS}" MJIT_OPTFLAGS="" MJIT_DEBUGFLAGS=""
156 }
157
158 src_test() {
159         emake -j1 V=1 test
160
161         elog "Ruby's make test has been run. Ruby also ships with a make check"
162         elog "that cannot be run until after ruby has been installed."
163         elog
164         if use rubytests; then
165                 elog "You have enabled rubytests, so they will be installed to"
166                 elog "/usr/share/${PN}-${SLOT}/test. To run them you must be a user other"
167                 elog "than root, and you must place them into a writeable directory."
168                 elog "Then call: "
169                 elog
170                 elog "ruby${MY_SUFFIX} -C /location/of/tests runner.rb"
171         else
172                 elog "Enable the rubytests USE flag to install the make check tests"
173         fi
174 }
175
176 src_install() {
177         # Remove the remaining bundled gems. We do this late in the process
178         # since they are used during the build to e.g. create the
179         # documentation.
180         rm -rf ext/json || die
181         rm -rf lib/bundler* lib/rdoc/rdoc.gemspec || die
182
183         # Ruby is involved in the install process, we don't want interference here.
184         unset RUBYOPT
185
186         local MINIRUBY=$(echo -e 'include Makefile\ngetminiruby:\n\t@echo $(MINIRUBY)'|make -f - getminiruby)
187
188         LD_LIBRARY_PATH="${S}:${ED}/usr/$(get_libdir)${LD_LIBRARY_PATH+:}${LD_LIBRARY_PATH}"
189         RUBYLIB="${S}:${ED}/usr/$(get_libdir)/ruby/${RUBYVERSION}"
190         for d in $(find "${S}/ext" -type d) ; do
191                 RUBYLIB="${RUBYLIB}:$d"
192         done
193         export LD_LIBRARY_PATH RUBYLIB
194
195         # Create directory for the default gems
196         local gem_home="${EPREFIX}/usr/$(get_libdir)/ruby/gems/${RUBYVERSION}"
197         mkdir -p "${D}/${gem_home}" || die "mkdir gem home failed"
198
199         emake V=1 DESTDIR="${D}" GEM_DESTDIR=${gem_home} install
200
201         # Remove installed rubygems and rdoc copy
202         rm -rf "${ED}/usr/$(get_libdir)/ruby/${RUBYVERSION}/rubygems" || die "rm rubygems failed"
203         rm -rf "${ED}/usr/bin/"gem"${MY_SUFFIX}" || die "rm rdoc bins failed"
204         rm -rf "${ED}/usr/$(get_libdir)/ruby/${RUBYVERSION}"/rdoc* || die "rm rdoc failed"
205         rm -rf "${ED}/usr/bin/"{bundle,bundler,ri,rdoc}"${MY_SUFFIX}" || die "rm rdoc bins failed"
206
207         if use doc; then
208                 emake DESTDIR="${D}" GEM_DESTDIR=${gem_home} install-doc
209         fi
210
211         if use examples; then
212                 dodoc -r sample
213         fi
214
215         dodoc ChangeLog NEWS doc/NEWS* README*
216
217         if use rubytests; then
218                 pushd test
219                 insinto /usr/share/${PN}-${SLOT}/test
220                 doins -r .
221                 popd
222         fi
223 }
224
225 pkg_postinst() {
226         if [[ ! -n $(readlink "${EROOT}"/usr/bin/ruby) ]] ; then
227                 eselect ruby set ruby${MY_SUFFIX}
228         fi
229
230         elog
231         elog "To switch between available Ruby profiles, execute as root:"
232         elog "\teselect ruby set ruby(23|24|...)"
233         elog
234 }
235
236 pkg_postrm() {
237         eselect ruby cleanup
238 }