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

set feature 8
name             openjdk${feature}-temurin
categories       java devel
maintainers      {breun @breun} openmaintainer

# JVMMinimumSystemVersion in Contents/Info.plist is set to macOS 10.6.0:
# /usr/libexec/PlistBuddy -c "Print :JavaVM:JVMMinimumSystemVersion" Contents/Info.plist
# Mapping to Darwin version: https://trac.macports.org/wiki/PortfileRecipes#compare-osx-darwin-version
platforms        {darwin any >= 10 }

# This port uses prebuilt binaries; 'NoMirror' makes sure MacPorts doesn't mirror/distribute these third-party binaries
license          GPL-2 NoMirror
# This port uses prebuilt binaries for a particular architecture; they are not universal binaries
universal_variant no

# https://adoptium.net/temurin/releases/
supported_archs  x86_64

version      ${feature}u462
set build    08
revision     0

description  Eclipse Temurin, based on OpenJDK ${feature} (Long Term Support until at least November 2026)
long_description Eclipse Temurin provides secure, TCK-tested and compliant, production-ready Java runtimes.

master_sites https://github.com/adoptium/temurin${feature}-binaries/releases/download/jdk${version}-b${build}/
distname     OpenJDK${feature}U-jdk_x64_mac_hotspot_${version}b${build}
worksrcdir   jdk${version}-b${build}

checksums    rmd160  194c44630e865bced271192c02b77d539e170360 \
             sha256  026001d776b9e692e9c79b7de975f7a1d819def42bd12e7d655ab16136b7dcf6 \
             size    109572785

homepage     https://adoptium.net

livecheck.type      regex
livecheck.url       https://github.com/adoptium/temurin${feature}-binaries
livecheck.regex     jdk(${feature}u\[0-9\]+)-b

use_configure    no
build {}

variant Applets \
    description { Advertise the JVM capability "Applets".} {}

variant WebStart \
    description { Advertise the JVM capability "WebStart".} {}

patch {
    foreach var { Applets WebStart } {
        if {[variant_isset ${var}]} {
            reinplace -E "s|^(\[\[:space:\]\]*<string>)CommandLine(</string>)|\\1${var}\\2\\\n\\1CommandLine\\2|" ${worksrcpath}/Contents/Info.plist
        }
    }
}

test.run    yes
test.cmd    Contents/Home/bin/java
test.target
test.args   -version

# macOS Java tools expect to find Java virtual machines under /Library/Java/JavaVirtualMachines, which is not under ${prefix}.
destroot.violate_mtree yes

set target /Library/Java/JavaVirtualMachines/${name}
set destroot_target ${destroot}${target}

destroot {
    xinstall -m 755 -d ${destroot_target}
    copy ${worksrcpath}/Contents ${destroot_target}
}

notes "
If you have more than one JDK installed you can make ${name} the default\
by adding the following line to your shell profile:

    export JAVA_HOME=${target}/Contents/Home
"
