# -*- 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
PortGroup               java 1.0
PortGroup               deprecated 1.0

name                    scala
categories              lang java
license                 Apache-2

maintainers             {@catap korins.ky:kirill} openmaintainer

description             The Scala Programming Language
long_description        Scala is a modern multi-paradigm programming language \
                        designed to express common programming patterns in a \
                        concise, elegant, and type-safe way.  It smoothly \
                        integrates features of object-oriented and functional \
                        languages.  It runs inside a Java Virtual Machine and \
                        is fully interoperable with Java.

homepage                https://www.scala-lang.org/
supported_archs         noarch
platforms               any

java.version            1.8+
java.fallback           openjdk8

if {${name} eq ${subport}} {
    PortGroup           stub 1.0

    version             3.3
    depends_run         port:scala${version}
}

subport ${name}3.3 {
    github.setup        lampepfl dotty 3.3.1
    revision            0
    github.tarball_from releases
    distname            scala3-${version}

    checksums           rmd160  1cc8849e253606bccee8ee63a182b6845782c47e \
                        sha256  11c0ea0f71c43af0fb1b355dde414bfef01a60c17293675e23a44d025269cd15 \
                        size    38427475
}

subport ${name}3.2 {
    github.setup        lampepfl dotty 3.2.2
    revision            0
    github.tarball_from releases
    distname            scala3-${version}

    checksums           rmd160  2b9baaf8acadd9f4886e3148ea04c01ce85bd8af \
                        sha256  b7c5edef42e8cde3e80d71372077a358e4d608461c399cad4432b3fd0c609998 \
                        size    37270187
}

subport ${name}3.1 {
    github.setup        lampepfl dotty 3.1.3
    revision            1
    github.tarball_from releases
    distname            scala3-${version}

    checksums           rmd160  40468943fa4d1fed3cf7279fbb79ac1cb07ba9e9 \
                        sha256  9e1eefdcab77b2d2a9057b3d6f78301591e9c27513c92413f3c353a77093f2d7 \
                        size    35463854
}

subport ${name}3.0 {
    github.setup        lampepfl dotty 3.0.2
    revision            1
    github.tarball_from releases
    distname            scala3-${version}

    checksums           rmd160  97aaaf7d417491ae52ba4a27244104305c85b251 \
                        sha256  136453bde7932c76a3c3530e0063329a4ce7c08fe5099554faa2aef17174cc60 \
                        size    32671071
}

subport ${name}2.13 {
    version             2.13.13
    revision            1

    master_sites        https://downloads.lightbend.com/scala/${version}
    distname            scala-${version}
    extract.suffix      .tgz

    checksums           sha256  944b0a06e3146989bc76b72d5f6e8edd09d0fcfd18ab0cb54a0c1f1d1fe80b2d \
                        rmd160  33a0681a2e5c336ff6a345f45c333ee7aa3e064c \
                        size    24134449
}

subport ${name}2.12 {
    version             2.12.19
    revision            1

    master_sites        https://downloads.lightbend.com/scala/${version}
    distname            scala-${version}
    extract.suffix      .tgz

    checksums           rmd160  fef7da2017876f142a1bf1c1b2accdb38fd282db \
                        sha256  d1876659c9298b6664f91aa7ef4b2c5baca6356ff47a9a598070045058968fb2 \
                        size    21053056
}

subport ${name}2.11 {
    version             2.11.12
    revision            2

    license             BSD

    master_sites        https://downloads.lightbend.com/scala/${version}
    distname            scala-${version}
    extract.suffix      .tgz

    checksums           sha256  b11d7d33699ca4f60bc3b2b6858fd953e3de2b8522c943f4cda4b674316196a8 \
                        rmd160  a8deefee97e7bb4c95efe5321ecae33de08fbb48 \
                        size    29114457
}

subport ${name}2.10 {
    version             2.10.7
    revision            2

    license             BSD

    master_sites        https://downloads.lightbend.com/scala/${version}
    distname            scala-${version}
    extract.suffix      .tgz

    checksums           sha256  9283119916f6bb7714e076a2840ccf22d58819b355228ed1591ae6f76929f111 \
                        rmd160  47969fa601f1b89f6601c65b6bfba9dd6cc29c2a \
                        size    29993772
}

subport ${name}2.9 {
    version             2.9.3
    revision            2

    license             BSD

    master_sites        ${homepage}files/archive/
    distname            scala-${version}
    extract.suffix      .tgz

    checksums           sha256  faaab229f78c945063e8fd31c045bc797c731194296d7a4f49863fd87fc4e7b9 \
                        rmd160  eee777413e2c8037b25711950072f13142af9c21 \
                        size    24699008

    deprecated.eol_version  yes
}

subport ${name}2.8 {
    version             2.8.2
    revision            2

    license             BSD

    master_sites        ${homepage}files/archive/
    distname            scala-${version}.final
    extract.suffix      .tgz

    checksums           sha256  45a7f29f423d1bfc505f5c1b150aa76dc76d30635f10ac72c1bce862aec1f394 \
                        rmd160  48e04679e627b72aef371dd62e966fc76a2598d8 \
                        size    20430705

    deprecated.eol_version  yes
}

subport ${name}2.7 {
    version             2.7.7
    revision            2

    license             BSD

    master_sites        ${homepage}files/archive/
    distname            scala-${version}.final
    extract.suffix      .tgz

    checksums           sha256  eecf77e120be09af9f7da7ea53f42199402bee16c92793439c93f021f5e4cda8 \
                        rmd160  ea590b9e25fd0ede59cc6ccd5e9d3bba99885b0f \
                        size    15619192

    deprecated.eol_version  yes
}

if {${name} ne ${subport}} {
    PortGroup           select 1.0

    use_configure       no
    build               {}

    depends_lib         port:scala_select
    select.group        scala
    select.file         ${filespath}/${subport}

    destroot {
        set branch      [join [lrange [split ${version} .] 0 1] .]

        set sharedir    ${destroot}${prefix}/share
        set scaladir    ${sharedir}/scala-${branch}

        xinstall -d -m 755 ${sharedir}
        xinstall -d -m 755 ${sharedir}/doc
        xinstall -d -m 755 ${sharedir}/man/man1

        file rename ${worksrcpath} ${scaladir}

        foreach f {fsc scala scalac scaladoc scalap} {
            if {[file exists ${scaladir}/bin/${f}]} {
                file attributes ${scaladir}/bin/${f} -permissions 0755
                ln -s ../share/scala-${branch}/bin/${f} ${destroot}${prefix}/bin/${f}-${branch}
            }

            if {[file exists ${scaladir}/man/man1/${f}.1]} {
                ln -s ../../scala-${branch}/man/man1/${f}.1 ${sharedir}/man/man1/${f}-${branch}.1
            }
        }

        if {[file isdirectory ${scaladir}/doc]} {
            ln -s ../scala-${branch}/doc ${sharedir}/doc/scala-${branch}
        }
    }
}

livecheck.type          regex
livecheck.url           https://scala-lang.org/download/all.html
if {${name} eq ${subport}} {
    livecheck.regex     {/download/(\d+\.\d+)\.\d+\.html}
} else {
    set major           [lindex [split $version .] 0]
    set minor           [lindex [split $version .] 1]
    livecheck.regex     "/download/(${major}\.${minor}\\.\\d+)\.*\\.html"
}
