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

PortSystem          1.0
PortGroup           java 1.0

name                jruby
version             10.0.2.0
revision            0

java.version        1.8+

if {${os.platform} eq "darwin" && ${os.arch} eq "powerpc"} {
    # If minimum required Java version is raised above 1.8,
    # macOS powerpc should be pegged to the latest supported version.
    java.fallback   openjdk8
} else {
    java.fallback   openjdk21
}

categories          lang ruby java
license             {EPL-2 GPL-2 LGPL-2.1}
supported_archs     noarch
platforms           {darwin any}
maintainers         {judaew @judaew} \
                    openmaintainer

description         JRuby is an implementation of the Ruby language using the JVM.
long_description    \
    ${description} It aims to be a complete, correct and fast implementation \
    of Ruby, at the same time as providing powerful new features such as \
    concurrency without a global-interpreter-lock, true parallelism, and tight \
    integration to the Java language to allow you to use Java classes in your \
    Ruby program and to allow JRuby to be embedded into a Java application.
homepage            https://www.jruby.org

master_sites        https://repo1.maven.org/maven2/org/jruby/jruby-dist/${version}/
distname            ${name}-dist-${version}-bin
worksrcdir          ${name}-${version}

checksums           rmd160  be423a7606e1f58219d2ce72bbb496f0c4cdb005 \
                    sha256  b8a026f38aa98461a04ed0aa0b20891ce257ecbe53e124719ce9ee5b804525f1 \
                    size    33781310

use_configure       no
build {}

variant default_ruby description {Install without j prefix} {}

variant nailgun description {include Nailgun support} {
    use_configure   yes
    configure.cmd   ./configure
    configure.dir   ${worksrcpath}/tool/nailgun

    build {
        system -W ${worksrcpath}/tool/nailgun ${build.cmd}
    }

    post-destroot {
        xinstall -m 755 -d ${destroot}${prefix}/share/java/${name}/tool/nailgun
        move ${worksrcpath}/tool/nailgun/ng \
            ${destroot}/${prefix}/share/java/${name}/tool/nailgun
    }
}

destroot {
    # Remove extraneous files from other platforms
    delete {*}[glob -directory ${worksrcpath}/bin *.bat *.dll *.exe]
    delete {*}[glob -directory ${worksrcpath}/lib/jni \
        *AIX *BSD *Linux *SunOS *Windows]

    xinstall -m 755 -d ${destroot}${prefix}/share/java/${name}

    move \
        ${worksrcpath}/bin \
        ${worksrcpath}/lib \
        ${destroot}${prefix}/share/java/${name}

    move ${worksrcpath}/samples ${destroot}${prefix}/share/java/${name}

    set jruby_prefix ""

    if { ![variant_isset default_ruby] } {
        set jruby_prefix "j"
    }

    foreach f { jruby jirb jrubyc jirb_swing } {
        regsub {^j} $f $jruby_prefix dest
        if { ${dest} != ${f} } {
            ln -s ${prefix}/share/java/${name}/bin/${f} \
                ${destroot}${prefix}/bin/${dest}
        }
        ln -s ${prefix}/share/java/${name}/bin/${f} ${destroot}${prefix}/bin/
    }

    foreach f { ast gem rdoc ri testrb } {
        ln -s ${prefix}/share/java/${name}/bin/${f} \
            ${destroot}${prefix}/bin/${jruby_prefix}${f}
    }
}

test.run            yes
test.cmd            bin/jruby
test.target         samples/java2.rb

livecheck.type      regex
livecheck.url       https://repo1.maven.org/maven2/org/jruby/jruby-dist/
livecheck.regex     (\\d+(?:\\.\\d+)*)/
