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

PortSystem          1.0
PortGroup           select 1.0

name                ruby23
version             2.3.8
revision            4

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.3
use_bzip2           yes
distname            ruby-${version}

checksums           md5 78045332e298dfd859ceef9fe946950f \
                    rmd160 1e7cc76027730979123cdd02691ce5193cd9df7a \
                    sha1 91b31abdba00a346c155fd32bd32d3cec3b73bc4 \
                    sha256 4d1a3a88e8cf9aea624eb73843fbfc60a9a281582660f86d5e4e00870397407c

use_parallel_build  no

depends_lib         port:readline \
                    port:openssl10 \
                    port:zlib \
                    port:libyaml \
                    port:libffi \
                    port:gdbm
depends_run         port:ruby_select
depends_build       port:pkgconfig
depends_skip_archcheck pkgconfig

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

# ext/openssl/ossl.h: <openssl/asn1_mac.h> was deprecated (#58123)
patchfiles          patch-ext_openssl_ossl.h.diff

configure.args      --enable-shared \
                    --disable-install-doc \
                    --mandir="${prefix}/share/man" \
                    --enable-pthread \
                    --without-tk \
                    --without-gmp \
                    --with-opt-dir="${prefix}" \
                    --with-openssl-include=${prefix}/include/openssl-1.0 \
                    --with-openssl-lib=${prefix}/lib/openssl-1.0 \
                    --program-suffix=2.3 \
                    --with-rubylibprefix="${prefix}/lib/ruby2.3"

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

# Avoid compile error for regexec.c with Xcode-6.4
# https://build.macports.org/builders/buildports-yosemite-x86_64/builds/6960
if {[info exists xcodeversion] && [vercmp $xcodeversion 6.4] == 0} {
    if {${configure.cc} eq "/usr/bin/clang" && ${configure.optflags} eq "-Os"} {
        configure.optflags -O3
    }
}

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

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

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

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

# note: ruby/tk does not support tk-8.6.
#
#variant tk conflicts mactk description "Build using MacPorts Tk" {
#        configure.args-delete   --without-tk
#        configure.args-append   --with-tk --disable-tcltk-framework
#        depends_lib-append      port:tcl \
#                                port:tk
#}

variant mactk description "Build using Mac OS X Tk Framework" {
        configure.args-delete   --without-tk
        configure.args-append   --enable-tcltk-framework
}

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.3/
livecheck.regex ruby-(2.3.\\d+)${extract.suffix}