# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>

_gemname=rake-compiler
pkgname=ruby-${_gemname}
pkgver=1.2.7
pkgrel=1
pkgdesc='Rake-based Ruby Extension (C, Java) task generator'
url='https://github.com/rake-compiler/rake-compiler'
arch=(any)
license=('MIT')
depends=(
  ruby
  ruby-rake
)
checkdepends=(
  ruby-bundler
  ruby-cucumber
  ruby-rspec
)
options=('!emptydirs')
source=("https://github.com/rake-compiler/rake-compiler/archive/v${pkgver}/${pkgname}-v${pkgver}.tar.gz")
sha512sums=('7405037092446e245028f73494acbeeb9b67cdcbc4e90832180d3c53d36df008b05a83e88e1919b884754e39365ca5685aa22cf8caf9e7f96786c11ac7208ead')
b2sums=('457359489e5c3c2155d0b2118b146bdf0ed0249b642859d34950640f472e4ed1d166ff3491ba5f739612f4a32e537b8319ee0eca2cd85cd5bfb61aec7a7daecc')

prepare() {
  cd "${_gemname}-${pkgver}"

  # update gemspec/Gemfile to allow newer version of the dependencies
  sed --in-place --regexp-extended 's|~>|>=|g' "${_gemname}.gemspec"
}

build() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem build --verbose "${_gemname}.gemspec"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install${_gemdir}" \
    --bindir "tmp_install/usr/bin" \
    "${_gemname}-${pkgver}.gem"

  # remove unrepreducible files
  rm --force --recursive --verbose \
    "tmp_install${_gemdir}/cache/" \
    "tmp_install${_gemdir}/gems/${_gemname}-${pkgver}/vendor/" \
    "tmp_install${_gemdir}/doc/${_gemname}-${pkgver}/ri/ext/"

  find "tmp_install${_gemdir}/gems/" \
    -type f \
    \( \
      -iname "*.o" -o \
      -iname "*.c" -o \
      -iname "*.so" -o \
      -iname "*.time" -o \
      -iname "gem.build_complete" -o \
      -iname "Makefile" \
    \) \
    -delete

  find "tmp_install${_gemdir}/extensions/" \
    -type f \
    \( \
      -iname "mkmf.log" -o \
      -iname "gem_make.out" \
    \) \
    -delete
}

check() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  GEM_HOME="tmp_install${_gemdir}" rake spec
}

package() {
  cd "${_gemname}-${pkgver}"

  cp --archive --verbose tmp_install/* "${pkgdir}"

  install --verbose -D --mode=0644 LICENSE* --target-directory "${pkgdir}/usr/share/licenses/${pkgname}"
  install --verbose -D --mode=0644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}

# vim: tabstop=2 shiftwidth=2 expandtab:
