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

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.4
    depends_run         port:scala${version}
}

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

    checksums           rmd160  280d45d29ca9e4f0edf4a23c9d9897040e6d1504 \
                        sha256  4063104c1998afc8dc6563ba5f33837f911d13bd99c0e5dc965ce56edcb0d777 \
                        size    38385920
}

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

    checksums           rmd160  e91e169290750d838e90d3c696ea05b95c419b6e \
                        sha256  eb594011312faa412aaf9a5b0e5b45921f90be9f849c20e295737d5faecd14d1 \
                        size    37208050
}

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.16
    revision            0

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

    checksums           sha256  937f743be315302caad15be99ab1ca425ff7e63f15ef5790db6c81bb49543256 \
                        rmd160  72e391426b07ed16bbf9d7c43163944b89bc3cb9 \
                        size    22613912
}

subport ${name}2.12 {
    version             2.12.20
    revision            0

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

    checksums           rmd160  4a444a132704d59f76be9d2198b6b446c5c7f0f0 \
                        sha256  cc29d91ad390dc8e9a68d1e2ec6892711b64116f549fecd67a928361d33a39c0 \
                        size    21055708
}

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"
}
