# Maintainer: Alexey Pavlov <alexpux@gmail.com>

# be sure to run the updpkgprovs and rebuild.  This is to get the propper version
# of the ruby gems that were bundled.

_realname=ruby
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.4.6
pkgrel=1
pkgdesc="An object-oriented language for quick and easy programming (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.ruby-lang.org/en"
msys2_references=(
  "cpe: cpe:/a:ruby-lang:ruby"
  "cpe: cpe:/a:yukihiro_matsumoto:ruby"
)
msys2_repository_url='https://github.com/ruby/ruby'
msys2_documentation_url='https://docs.ruby-lang.org/en/master/index.html'
license=('spdx:Ruby AND BSD-2-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
depends=("${MINGW_PACKAGE_PREFIX}-gdbm"
         "${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-libffi"
         "${MINGW_PACKAGE_PREFIX}-libyaml"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-readline"
         "${MINGW_PACKAGE_PREFIX}-tk"
         "${MINGW_PACKAGE_PREFIX}-winpthreads"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=("https://cache.ruby-lang.org/pub/ruby/${pkgver%.*}/${_realname}-${pkgver}.tar.xz")
## Populated by the updpkgprovs script
provides=(
    "${MINGW_PACKAGE_PREFIX}-ruby-abbrev=0.1.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-base64=0.2.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-bigdecimal=3.1.8"
    "${MINGW_PACKAGE_PREFIX}-ruby-csv=3.3.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-debug=1.11.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-drb=2.2.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-getoptlong=0.2.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-matrix=0.4.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-minitest=5.25.4"
    "${MINGW_PACKAGE_PREFIX}-ruby-mutex_m=0.3.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-net-ftp=0.3.8"
    "${MINGW_PACKAGE_PREFIX}-ruby-net-imap=0.5.8"
    "${MINGW_PACKAGE_PREFIX}-ruby-net-pop=0.1.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-net-smtp=0.5.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-nkf=0.2.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-observer=0.1.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-power_assert=2.0.5"
    "${MINGW_PACKAGE_PREFIX}-ruby-prime=0.1.3"
    "${MINGW_PACKAGE_PREFIX}-ruby-racc=1.8.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-rake=13.2.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-rbs=3.8.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-repl_type_completor=0.1.9"
    "${MINGW_PACKAGE_PREFIX}-ruby-resolv-replace=0.1.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-rexml=3.4.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-rinda=0.2.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-rss=0.3.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-test-unit=3.6.7"
    "${MINGW_PACKAGE_PREFIX}-ruby-typeprof=0.30.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-benchmark=0.4.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-bundler=2.6.9"
    "${MINGW_PACKAGE_PREFIX}-ruby-cgi=0.4.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-date=3.4.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-delegate=0.4.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-did_you_mean=2.0.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-digest=3.2.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-english=0.8.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-erb=4.0.4"
    "${MINGW_PACKAGE_PREFIX}-ruby-error_highlight=0.7.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-etc=1.4.6"
    "${MINGW_PACKAGE_PREFIX}-ruby-fcntl=1.2.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-fiddle=1.1.6"
    "${MINGW_PACKAGE_PREFIX}-ruby-fileutils=1.7.3"
    "${MINGW_PACKAGE_PREFIX}-ruby-find=0.2.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-forwardable=1.3.3"
    "${MINGW_PACKAGE_PREFIX}-ruby-io-console=0.8.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-io-nonblock=0.3.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-io-wait=0.3.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-ipaddr=1.2.7"
    "${MINGW_PACKAGE_PREFIX}-ruby-irb=1.14.3"
    "${MINGW_PACKAGE_PREFIX}-ruby-json=2.9.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-logger=1.6.4"
    "${MINGW_PACKAGE_PREFIX}-ruby-net-http=0.6.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-net-protocol=0.2.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-open-uri=0.5.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-open3=0.2.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-openssl=3.3.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-optparse=0.6.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-ostruct=0.6.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-pathname=0.4.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-pp=0.6.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-prettyprint=0.2.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-prism=1.5.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-pstore=0.1.4"
    "${MINGW_PACKAGE_PREFIX}-ruby-psych=5.2.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-rdoc=6.14.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-readline=0.0.4"
    "${MINGW_PACKAGE_PREFIX}-ruby-reline=0.6.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-resolv=0.6.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-ruby2_keywords=0.0.5"
    "${MINGW_PACKAGE_PREFIX}-ruby-securerandom=0.4.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-set=1.1.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-shellwords=0.2.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-singleton=0.3.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-stringio=3.1.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-strscan=3.1.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-syntax_suggest=2.0.2"
    "${MINGW_PACKAGE_PREFIX}-ruby-tempfile=0.3.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-time=0.4.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-timeout=0.4.3"
    "${MINGW_PACKAGE_PREFIX}-ruby-tmpdir=0.3.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-tsort=0.2.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-un=0.3.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-uri=1.0.3"
    "${MINGW_PACKAGE_PREFIX}-ruby-weakref=0.1.3"
    "${MINGW_PACKAGE_PREFIX}-ruby-win32-registry=0.1.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-win32ole=1.9.1"
    "${MINGW_PACKAGE_PREFIX}-ruby-yaml=0.4.0"
    "${MINGW_PACKAGE_PREFIX}-ruby-zlib=3.2.1"
)
## End of pkgupdprovs modifications

sha256sums=('804995bc22938aa475127000d3103cb133409ad3955edfc0e7412be66a4859b8')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd ${_realname}-${pkgver}
  autoreconf -fi
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  if [[ ${MSYSTEM} == CLANG* ]]; then
    CFLAGS+=" -Wno-dll-attribute-on-redeclaration"
    CPPFLAGS+=" -pthread"
    LDFLAGS+=" -pthread"
  else
    CFLAGS+=" -Wno-incompatible-pointer-types"
  fi

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --disable-install-doc \
    --without-baseruby \
    --with-setjmp-type=setjmp

  make
}

check() {
  cd build-${MSYSTEM}
  make test || true
}

package() {
  cd build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install-nodoc

  for script in {gem,}; do
    install "${srcdir}"/${_realname}-${pkgver}/bin/${script} \
      "${pkgdir}"${MINGW_PREFIX}/bin/
  done

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/ruby/LICENSE"
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/BSDL "${pkgdir}${MINGW_PREFIX}/share/licenses/ruby/BSDL"
}
