File ruby33.spec of Package ruby33

%define realname ruby
%define realver  3.3.0
%define srcext   tar.gz

### %define vermajor %(VER='%{realver}'; echo ${VER%%.*})
%define vermajor 3.3
%define abiver   %{vermajor}.0

%define bin_ver  %{vermajor}
%define so_ver   %{vermajor}
%define lib_ver  %(echo '%{vermajor}' | tr . _)

%define ruby_target %{_host_cpu}-%{_host_os}%{_gnu}

# turn off the generation of debuginfo rpm  (RH9) ??
%global debug_package %{nil}

# See lib/rubygems.rb
%define rubygems_ver     3.3.7

# Common info
Name:          %{realname}%{?bin_ver}
Version:       %{realver}
Release:       %{?extraver:0.}1%{?dist}
License:       BSD-2-Clause or Ruby
Group:         Development/Languages/Ruby
URL:           https://www.ruby-lang.org/
Summary:       An Interpreted Object-Oriented Scripting Language

# Install-time parameters
Requires:      %{realname}%{?bin_ver}-stdlib = %{version}-%{release}
Provides:      ruby(abi) = %{abiver}
Provides:      ruby(release) = %{version}

# Build-time parameters
### BuildRequires: ruby
BuildRequires: pkg-config
BuildRequires: gcc-c++
BuildRequires: libgmp-devel
# ext/dbm
BuildRequires: %{!?suse_version:lib}db-devel
# ext/fiddle
BuildRequires: pkgconfig(libffi)
# ext/gdbm
BuildRequires: gdbm-devel
# ext/openssl
BuildRequires: pkgconfig(openssl) >= 1.0.1
# ext/psych
BuildRequires: libyaml-devel
# ext/readline
BuildRequires: ncurses-devel readline-devel
# ext/ripper
BuildRequires: bison
# ext/zlib
BuildRequires: zlib-devel
%if 0%{?suse_version}
BuildRequires: fdupes
%endif
BuildRoot:     %{_tmppath}/%{name}-root
Source:        http://cache.ruby-lang.org/pub/ruby/%{vermajor}/%{realname}-%{realver}%{?extraver}.%{srcext}
Source1000:    get_gems.rb
# ruby ../get_gems.rb > ../gems_list.inc
Source1001:    gems_list.inc

%description
Ruby is an interpreted object-oriented programming language often
used for web development. It also offers many scripting features
to process plain text and serialized files, or manage system tasks.
It is simple, straightforward, and extensible.

== Features of Ruby

*   Simple Syntax
*   **Normal** Object-oriented Features (e.g. class, method calls)
*   **Advanced** Object-oriented Features (e.g. mix-in, singleton-method)
*   Operator Overloading
*   Exception Handling
*   Iterators and Closures
*   Garbage Collection
*   Dynamic Loading of Object Files (on some architectures)
*   Highly Portable (works on many Unix-like/POSIX compatible platforms as
    well as Windows, macOS, Haiku, etc.) cf.
    https://github.com/ruby/ruby/blob/master/doc/contributing.rdoc#platform-maintainers

%package -n libruby%{lib_ver}-%{lib_ver}
Group:         System/Libraries
Summary:       Dynamic runtime library for Ruby

%description -n libruby%{lib_ver}-%{lib_ver}
Dynamic runtime library for Ruby

%package stdlib
Group:         Development/Languages/Ruby
Summary:       The Ruby standard library

Provides:      rubygems = %{rubygems_ver}
Provides:      rubygem-rubygems = %{rubygems_ver}
Provides:      ruby(rubygems) = %{rubygems_ver}
Provides:      rubygem(ruby:%{abiver}:rubygems) = %{rubygems_ver}
Obsoletes:     rubygems < %{rubygems_ver}
Obsoletes:     rubygem-rubygems < %{rubygems_ver}
%include       %{S:1001}

%description stdlib
The Ruby standard library

%package devel
Group:         Development/Languages/C and C++
Summary:       Development files for %{name}
Requires:      libruby%{lib_ver}-%{lib_ver} = %{version}
Requires:      gmp-devel

%description devel
Development files for %{name}

%package -n ruby-devel
Group:         Development/Languages/C and C++
Summary:       Development files for %{name}
Requires:      %{name}-devel = %{version}

%description -n ruby-devel
Development files for %{name}

%package doc-ri
Group:         Documentation/HTML
Summary:       Documentation for %{name}
Provides:      ruby-ri = %{version}
Requires:      %{name} = %{version}

%if 0%{?suse_version} && ! 0%{?sles_version}
BuildArch:     noarch
%endif

%description doc-ri
Documentation for %{name}

%package -n ruby
Group:         Development/Languages/Ruby
Summary:       An Interpreted Object-Oriented Scripting Language
Provides:      ruby-irb = %{version} ruby-rdoc = %{version}
Requires:      %{name} = %{version}
Requires:      %{_sbindir}/update-alternatives

%description -n ruby
Ruby is an interpreted object-oriented programming language often
used for web development. It also offers many scripting features
to process plain text and serialized files, or manage system tasks.
It is simple, straightforward, and extensible.

== Features of Ruby

*   Simple Syntax
*   **Normal** Object-oriented Features (e.g. class, method calls)
*   **Advanced** Object-oriented Features (e.g. mix-in, singleton-method)
*   Operator Overloading
*   Exception Handling
*   Iterators and Closures
*   Garbage Collection
*   Dynamic Loading of Object Files (on some architectures)
*   Highly Portable (works on many Unix-like/POSIX compatible platforms as
    well as Windows, macOS, Haiku, etc.) cf.
    https://github.com/ruby/ruby/blob/master/doc/contributing.rdoc#platform-maintainers

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}
# Fix shebang
%{__sed} -ri '1 s|^.+$|#!%{_bindir}/ruby%{vermajor}|' libexec/*

%build
%configure \
 --program-suffix=%{vermajor} \
 --target=%{_host} \
 --disable-rpath \
 --disable-static \
 --enable-shared \
 --without-valgrind \
 --with-soname=ruby%{vermajor} \
 CFLAGS="%{optflags} " \
 CXXFLAGS="%{optflags} %{?cxx11abi}" \
 LDFLAGS="-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -pthread"
%{__make} %{?_smp_mflags}

%install
%{__make} install DESTDIR=%{buildroot}
%{__install} -d -m755 %{buildroot}%{_bindir}
%{__install} -d -m755 %{buildroot}%{_sysconfdir}/alternatives
%{__ln_s} ../%{ruby_target}/ruby/config.h %{buildroot}%{_includedir}/ruby-%{abiver}/ruby/config.h
# Alternatives for binaries
for bin in bundle bundler erb gem irb racc rake rbs rdbg rdoc ri ruby syntax_suggest typeprof; do
  # dummy
  touch %{buildroot}%{_sysconfdir}/alternatives/${bin}
  %{__ln_s} %{_sysconfdir}/alternatives/${bin} %{buildroot}%{_bindir}/${bin}
  %{__ln_s} ${bin}%{vermajor} %{buildroot}%{_bindir}/${bin}.%{name}
done
for man in erb irb ri ruby; do
  # dummy
  touch %{buildroot}%{_sysconfdir}/alternatives/${man}.1.gz
  %{__ln_s} %{_sysconfdir}/alternatives/${man}.1.gz %{buildroot}%{_mandir}/man1/${man}.1
done
%if 0%{?suse_version}
%fdupes %{buildroot}%{_prefix}
%endif
# Not needed
find %{buildroot}%{_libdir}/ruby/gems -name gem.build_complete -delete
# Symlinks for includes
%{__ln_s} ../../include/ruby-%{abiver} %{buildroot}%{_libdir}/ruby/include
%{__ln_s} ruby-%{abiver} %{buildroot}%{_includedir}/ruby
%{__ln_s} ruby-%{vermajor}.pc %{buildroot}%{_libdir}/pkgconfig/ruby.pc
# Fix shebangs
%{__sed} -ri \
    -e '1 s|^#!/usr/bin/env .+$|#!%{_bindir}/ruby%{vermajor}|' \
    %{buildroot}%{_libdir}/ruby/gems/%{abiver}/gems/*/exe/* \
    %{buildroot}%{_libdir}/ruby/gems/%{abiver}/gems/*/bin/*

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%files
%defattr(-,root,root)
%license COPYING BSDL GPL
%doc CONTRIBUTING.md LEGAL NEWS.md README.md README.EXT
%{_bindir}/*%{vermajor}
%{_bindir}/*.%{name}
%doc %{_mandir}/man1/erb%{vermajor}.1*
%doc %{_mandir}/man1/irb%{vermajor}.1*
%doc %{_mandir}/man1/ri%{vermajor}.1*
%doc %{_mandir}/man1/ruby%{vermajor}.1*

# Dynamic library
%files -n libruby%{lib_ver}-%{lib_ver}
%defattr(-,root,root)
%{_libdir}/*.so.%{?so_ver}*

# Standard library
%files stdlib
%defattr(-,root,root)
%dir %{_libdir}/ruby/%{abiver}
%dir %{_libdir}/ruby/gems/%{abiver}
%dir %{_libdir}/ruby/gems
%dir %{_libdir}/ruby/site_ruby/%{abiver}
%dir %{_libdir}/ruby/site_ruby
%dir %{_libdir}/ruby/vendor_ruby/%{abiver}
%dir %{_libdir}/ruby/vendor_ruby
%dir %{_libdir}/ruby
%{_libdir}/ruby/%{abiver}/*
%{_libdir}/ruby/gems/%{abiver}/*
%exclude %{_libdir}/ruby/gems/%{abiver}/gems/*/.gitignore

# Development stuff
%files devel
%defattr(-,root,root)
%{_libdir}/pkgconfig/ruby-%{vermajor}.pc
%{_includedir}/ruby-%{abiver}/
%{_libdir}/*.so

# Development stuff
%files -n ruby-devel
%defattr(-,root,root)
%{_libdir}/ruby/include
%{_includedir}/ruby
%{_libdir}/pkgconfig/ruby.pc

# Documentation
%files doc-ri
%defattr(-,root,root)
%docdir %{_datadir}/ri/
%dir %{_datadir}/ri/
%doc %{_datadir}/ri/%{abiver}/

%files -n ruby
%defattr(-,root,root)
%doc BSDL COPYING GPL LEGAL NEWS.md README.md README.EXT
%{_bindir}/*
%exclude %{_bindir}/*%{vermajor}
%exclude %{_bindir}/*.%{name}
%ghost %{_sysconfdir}/alternatives/*
%doc %{_mandir}/man1/erb.1*
%doc %{_mandir}/man1/irb.1*
%doc %{_mandir}/man1/ri.1*
%doc %{_mandir}/man1/ruby.1*

%post   -n libruby%{lib_ver}-%{lib_ver} -p /sbin/ldconfig
%postun -n libruby%{lib_ver}-%{lib_ver} -p /sbin/ldconfig

%post -n ruby
for bin in erb irb ri ruby; do
  %{_sbindir}/update-alternatives --install \
    %{_bindir}/${bin} ${bin} %{_bindir}/${bin}%{vermajor} 33 \
    --slave %{_mandir}/man1/${bin}.1.gz ${bin}.1.gz %{_mandir}/man1/${bin}%{vermajor}.1.gz
done
for bin in bundle bundler gem racc rake rbs rdbg rdoc syntax_suggest typeprof; do
  %{_sbindir}/update-alternatives --install \
    %{_bindir}/${bin} ${bin} %{_bindir}/${bin}%{vermajor} 33
done

%preun -n ruby
if [ ${1} -eq 0 ]; then
  for bin in bundle bundler erb gem irb racc rake rbs rdbg rdoc ri ruby syntax_suggest typeprof; do
    %{_sbindir}/update-alternatives --remove ${bin} %{_bindir}/${bin}%{vermajor}
  done
fi

%changelog
openSUSE Build Service is sponsored by