# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           select 1.0

name                ruby25
version             2.5.5
revision            0

categories          lang ruby
maintainers         {kimuraw @kimuraw} openmaintainer
platforms           darwin

description         Powerful and clean object-oriented scripting language
long_description    Ruby is the interpreted scripting language for quick \
                    and easy object-oriented programming. It has many \
                    features to process text files and to do system \
                    management tasks (as in Perl). It is simple, \
                    straight-forward, extensible, and portable.

homepage            http://www.ruby-lang.org/
license             {Ruby BSD}

master_sites        ruby:2.5
use_bzip2           yes
distname            ruby-${version}
dist_subdir         ruby25

checksums           md5 8f41b5cb683d48b5cb6cdfe03d135d6b \
                    rmd160 a4f9a7c962f2364401b11b2b5917fe4d558aa37a \
                    sha1 1932db85ace80ecdbc5cfc7aada5b5123f7ad739 \
                    sha256 1f2567a55dad6e50911ce42fcc705cf686924b897f597cabf803d88192024dcb

use_parallel_build  no

depends_lib         port:readline \
                    path:lib/libssl.dylib:openssl \
                    port:zlib \
                    port:libyaml \
                    port:libffi \
                    port:gdbm
depends_run         port:ruby_select
depends_build       port:pkgconfig
depends_skip_archcheck pkgconfig

# requires gmake 3.81 or later
if {${os.major} < 10} {
    depends_build-append    port:gmake
    build.cmd               ${prefix}/bin/gmake
}

select.group        ruby
select.file         ${filespath}/ruby25

configure.args      --enable-shared \
                    --enable-install-static-library \
                    --disable-install-doc \
                    --mandir="${prefix}/share/man" \
                    --enable-pthread \
                    --without-gmp \
                    --with-opt-dir="${prefix}" \
                    --program-suffix=2.5 \
                    --with-rubylibprefix="${prefix}/lib/ruby2.5"

platform darwin {
    if {${os.major} < 10} {
        configure.args-append --disable-dtrace
    }
}

# Add the architecture flag as required
if {[info exists build_arch] && ${build_arch} != ""} {
    configure.args-append "--with-arch=${build_arch}"
}

post-destroot {
    foreach type {site vendor} {
            set libdir ${destroot}${prefix}/lib/ruby2.5/${type}_ruby/2.5.0
            xinstall -m 0755 -d ${libdir}
    }

    foreach subdir [exec find ${libdir} -type d -empty] {
            destroot.keepdirs-append ${subdir}
    }

    # install destination of commands from port:rb25-*
    xinstall -m 0755 -d ${destroot}${prefix}/libexec/ruby2.5
    destroot.keepdirs-append ${destroot}${prefix}/libexec/ruby2.5
}

variant doc description "Install rdoc indexes and C API documents" {
        configure.args-delete   --disable-install-doc
}

variant gmp description "use gmp" {
        configure.args-delete   --without-gmp
        depends_lib-append      port:gmp
}

variant jemalloc description "use jemalloc" {
        configure.args-delete   --without-jemalloc
        configure.args-append   --with-jemalloc
        depends_lib-append      port:jemalloc
}

variant universal {
        # use ruby built-in universal mechanism.
        configure.args-append   --with-arch=[join ${universal_archs} ,]
        # clear macports' universal flags
        configure.universal_cflags
        configure.universal_cppflags
        configure.universal_cxxflags
        configure.universal_ldflags
}

variant relative description "Enable relative loading of libraries to allow for relocation of binaries." {
        #enable relative loading
        configure.args-append  --enable-load-relative
}

livecheck.type  regex
livecheck.url   https://cache.ruby-lang.org/pub/ruby/2.5/
livecheck.regex ruby-(2.5.\\d+)${extract.suffix}