# -*- 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                dotnet-runtime-11
version             11.0.0
revision            0
categories          dotnet
license             MIT
maintainers         @BjarneDMat {@judaew judaew} openmaintainer

description         .NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.

long_description    .NET is a free, cross-platform, open source developer platform \
                    for building many different types of applications. \
                    \
                    With .NET, you can use multiple languages, editors, and libraries \
                    to build for web, mobile, desktop, games, and IoT.

homepage            https://dotnet.microsoft.com/
platforms           {darwin any} {darwin >= 21}
supported_archs     x86_64 arm64

switch ${build_arch} {
    x86_64 {
        distname            dotnet-runtime-${version}-osx-x64
        checksums           rmd160  13431dcce61d9fbc5cd62edff79aee298d235285 \
                            sha256  b45fdafb63a5aa5c1f4b8529531d0c3a84f2e2de5a0196c081c1607f27791fbc \
                            size    37222037
    }
    arm64 {
        distname            dotnet-runtime-${version}-osx-arm64
        checksums           rmd160  8e16ce91dfa9be18ad14d607a55cb4cff8c8a102 \
                            sha256  c0519f0a8df6d153c08736d93e5113acbe9ba6f11f83a978ecb7bfc0640a39d4 \
                            size    34699769
    }
    default {
        known_fail yes
        pre-fetch {
            ui_error "${subport} @ ${version} only supported for architectures ${supported_archs}"
            return -code error "Unsupported architecture: ${build_arch}"
        }
    }
}

master_sites        https://builds.dotnet.microsoft.com/dotnet/Runtime/${version}/

worksrcdir          ${name}-${version}
extract.mkdir       yes

use_configure       no

depends_run         port:dotnet-cli

build {}

destroot {
    set dotnet_home ${prefix}/share/dotnet
    set hostfxr_dir /host/fxr
    set runtime_dir /shared/Microsoft.NETCore.App
    xinstall -d ${destroot}${dotnet_home}${hostfxr_dir}
    xinstall -d ${destroot}${dotnet_home}${runtime_dir}

    move ${worksrcpath}${hostfxr_dir}/${version} ${destroot}${dotnet_home}${hostfxr_dir}
    move ${worksrcpath}${runtime_dir}/${version} ${destroot}${dotnet_home}${runtime_dir}
}

set major_ver       [join [lrange [split ${version} .] 0 1] .]
livecheck.type      regex
livecheck.url       https://dotnet.microsoft.com/download/dotnet/${major_ver}
livecheck.regex     ".NET Runtime (\\d+(?:\\.\\d+)*)"
