app=ruby
version=2.5.0
build=1sml
homepage="http://www.ruby-lang.org/"
download="https://cache.ruby-lang.org/pub/ruby/2.5/ruby-$version.tar.gz"
desc="Interpreted object-oriented scripting language"
requires="gmp"

build() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version
  fixbuilddirpermissions

  # Thanks sabotage
  applypatch $srcdir/ruby-test_insns-lower-recursion-depth.patch
  applypatch $srcdir/ruby-rubygems-avoid-platform-specific-gems.patch

  unset CFLAGS CXXFLAGS CPPFLAGS
  
  # Put ruby on a diet
  export CPPFLAGS="-D_GNU_SOURCE -fno-omit-frame-pointer -fno-strict-aliasing" 
  export CFLAGS="-Os -fno-omit-frame-pointer -fno-strict-aliasing" 

  export ac_cv_func_isnan=yes 
  export ac_cv_func_isinf=yes 

  stack_protector=no \
  rb_cv_binary_elf=yes \
  ./configure \
    --prefix="" \
    --enable-shared \
    --enable-pthread \
    --without-jemalloc \
    --disable-rpath \
    --with-mantype=man \
    --disable-install-doc

  make
  make install DESTDIR=$pkg

  cp BSDL COPYING GPL LEGAL $pkgdocs/

  mkfinalpkg
}

sha512sums="
fc27f44b2a495db0ade5812f649182b9f7570873d27b9ccfd6e6fc9564b4e32086cc4b09879e6ceda7f604347c7da7c5a337d258a82b13427da1e2894a9fa6db  ruby-2.5.0.tar.lz
cfdc5ea3b2e2ea69c51f38e8e2180cb1dc27008ca55cc6301f142ebafdbab31c3379b3b6bba9ff543153876dd98ed2ad194df3255b7ea77a62e931c935f80538  ruby-rubygems-avoid-platform-specific-gems.patch
814fe6359505b70d8ff680adf22f20a74b4dbd3fecc9a63a6c2456ee9824257815929917b6df5394ed069a6869511b8c6dce5b95b4acbbb7867c1f3a975a0150  ruby-test_insns-lower-recursion-depth.patch
"
