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

name                abcl
version             1.9.2
revision            5
categories          lang java
license             GPL-2
supported_archs     noarch
platforms           any
maintainers         {easieste @easye} openmaintainer
description         A Common Lisp implementation that runs on the JVM
long_description    \
    Armed Bear Common Lisp is conforming, contemporary \
    implementation of ANSI Common Lisp running on the Java \
    Virtual Machine. Containing both an interpreted mode and \
    a compiler that produces JVM bytecode, it features extensions \
    that faciliate the use of Java from Lisp enabling the rapid \
    integration of arbitrary Java libraries into Common Lisp \
    code. ABCL fully supports the JSR-233 (Java scripting API), \
    so it can be a utilized as a scripting engine in any Java \
    application.
    
homepage            https://abcl.org
master_sites        ${homepage}/releases/${version}/
distname            abcl-src-${version}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     abcl-src-(\[0-9.\]+)${extract.suffix}

checksums           rmd160  63702c969e4093065ce038ad7c82c7295ae15419 \
                    sha256  4e2f4b8f85e2d95d95e5bdbcd9fa17ad6131a17e2fcf12bc19ffb97b48bc1d38 \
                    size    2477992

depends_build-append \
                    path:bin/ant:apache-ant
# It needed for implementation of FFI, not build
depends_run-append  port:maven3

# java PG may add or may not add java dependencies, it depends on what is installed on the system,
# anyway, ABCL cached used java inside produced scripts, and won't work without the same java.
# To avoid hell by undetermenistic behaviour, I simple use the latest JDK TLS.
if {${os.arch} eq "powerpc"} {
    depends_lib-append \
                    port:openjdk8
    set java_home   ${prefix}/Library/Java/JavaVirtualMachines/openjdk8/Contents/Home
} else {
    depends_lib-append \
                    port:openjdk21
    set java_home   ${prefix}/Library/Java/JavaVirtualMachines/jdk-21-macports.jdk/Contents/Home
}

use_configure       no

patchfiles-append   patch-macports-xdg-data-dir.diff \
                    patch-macports-maven.diff

post-patch {
    reinplace -W ${worksrcpath} "s|@@PREFIX@@|${prefix}|g" \
        src/org/armedbear/lisp/asdf.lisp \
        contrib/abcl-asdf/maven.lisp
}

build.cmd           ant
build.target        abcl
build.env-append    JAVA_HOME=${java_home}
build.args          -Djava.path=${java_home}/bin/java

post-build {
    reinplace "s|${worksrcpath}/dist/abcl.jar|${prefix}/share/java/abcl/abcl.jar|g" \
        ${worksrcpath}/abcl
}

destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/java/abcl
    xinstall -m 644 \
        ${worksrcpath}/dist/abcl.jar \
        ${destroot}${prefix}/share/java/abcl
    xinstall -m 644 \
        ${worksrcpath}/dist/abcl-contrib.jar \
        ${destroot}${prefix}/share/java/abcl
    xinstall -m 755 \
        ${worksrcpath}/abcl \
        ${destroot}${prefix}/share/java/abcl
    system "ln -fs ${prefix}/share/java/abcl/abcl \
        ${destroot}${prefix}/bin/abcl"
}
