# -*- 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           github 1.0

github.setup        borkdude jet 0.7.27 v
github.tarball_from releases
revision            0

maintainers         nomaintainer
license             EPL-1
categories          textproc devel

description         CLI to transform between JSON, EDN, YAML and Transit using Clojure
long_description    {*}${description}

distfiles           ${name}-${version}-standalone.jar

checksums           rmd160  747a74d64c6148a4296a5bd53f5b933327825e01 \
                    sha256  db9d3fd4304d097954d5be238cb51439723eb926cec8f5ed04dd49251a5d9857 \
                    size    13546797

extract.only

variant jdk17 conflicts jdk11 description {Build using JDK 17} {
    depends_build-append port:openjdk17-graalvm
}

variant jdk11 conflicts jdk17 description {Build using the older JDK 11} {
    depends_build-append port:openjdk11-graalvm-native-image
}

if {![variant_isset jdk11] && ![variant_isset jdk17]} {
    default_variants    +jdk17
}

use_configure       no

pre-fetch {
    if {![variant_isset jdk11] && ![variant_isset jdk17]} {
        error "Either +jdk11 or +jdk17 is required"
    }
}

build {
    # Leaving this stub since we cannot declare global variables in the scope of pre-fetch
    set graalvm_home /Library/Java/JavaVirtualMachines

    if {[variant_isset jdk17]} {
        set graalvm_home ${graalvm_home}/openjdk17-graalvm
    } elseif {[variant_isset jdk11]} {
        set graalvm_home ${graalvm_home}/openjdk11-graalvm
    }

    set graalvm_home ${graalvm_home}/Contents/Home

    # See: https://github.com/borkdude/jet/blob/master/script/compile
    set args "-H:+ReportExceptionStackTraces"
    append args " --verbose"
    append args " --no-fallback"
    append args " --no-server"
    append args " -J-Djet.native=true"

    system -W ${workpath} \
        "${graalvm_home}/bin/native-image -jar [shellescape ${distpath}/${distfiles}] ${args}"
}

destroot {
    xinstall -m 755 ${workpath}/jet ${destroot}${prefix}/bin
}
