1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit autotools flag-o-matic multilib
8 MY_P="${PN}-$(ver_cut 1-3)"
12 MY_SUFFIX=$(ver_rs 1 '' ${SLOT})
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"
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"
24 berkdb? ( sys-libs/db:= )
25 gdbm? ( sys-libs/gdbm:= )
26 jemalloc? ( dev-libs/jemalloc )
27 jit? ( || ( sys-devel/gcc:* sys-devel/clang:* ) )
29 !libressl? ( dev-libs/openssl:0= )
30 libressl? ( dev-libs/libressl )
32 socks5? ( >=net-proxy/dante-1.1.13 )
34 dev-lang/tcl:0=[threads]
35 dev-lang/tk:0=[threads]
41 >=app-eselect/eselect-ruby-20171225
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]
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 )"
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
69 einfo "Unbundling gems..."
71 # Remove bundled gems that we will install via PDEPEND, bug
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
78 einfo "Removing bundled libraries..."
79 rm -fr ext/fiddle/libffi-3.2.1 || die
87 local modules= myconf=
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
95 use sh && append-flags -mieee
97 # Socks support via dante
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.
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}"
110 # ipv6 hack, bug 168939. Needs --enable-ipv6.
111 use ipv6 || myconf="${myconf} --with-lookup-order-hack=INET"
113 # Determine which modules *not* to build depending in the USE flags.
114 if ! use berkdb ; then
115 modules="${modules},dbm"
118 modules="${modules},gdbm"
121 modules="${modules},openssl"
124 modules="${modules},tk"
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
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} \
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) \
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) \
148 --enable-option-checking=no
150 # Makefile is broken because it lacks -ldl
151 rm -rf ext/-test-/popen_deadlock || die
155 emake V=1 EXTLDFLAGS="${LDFLAGS}" MJIT_CFLAGS="${CFLAGS}" MJIT_OPTFLAGS="" MJIT_DEBUGFLAGS=""
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."
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."
170 elog "ruby${MY_SUFFIX} -C /location/of/tests runner.rb"
172 elog "Enable the rubytests USE flag to install the make check tests"
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
180 rm -rf ext/json || die
181 rm -rf lib/bundler* lib/rdoc/rdoc.gemspec || die
183 # Ruby is involved in the install process, we don't want interference here.
186 local MINIRUBY=$(echo -e 'include Makefile\ngetminiruby:\n\t@echo $(MINIRUBY)'|make -f - getminiruby)
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"
193 export LD_LIBRARY_PATH RUBYLIB
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"
199 emake V=1 DESTDIR="${D}" GEM_DESTDIR=${gem_home} install
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"
208 emake DESTDIR="${D}" GEM_DESTDIR=${gem_home} install-doc
211 if use examples; then
215 dodoc ChangeLog NEWS doc/NEWS* README*
217 if use rubytests; then
219 insinto /usr/share/${PN}-${SLOT}/test
226 if [[ ! -n $(readlink "${EROOT}"/usr/bin/ruby) ]] ; then
227 eselect ruby set ruby${MY_SUFFIX}
231 elog "To switch between available Ruby profiles, execute as root:"
232 elog "\teselect ruby set ruby(23|24|...)"