# -*- 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-sdk-6
version             6.0.424
revision            0
categories          dotnet devel
license             MIT
maintainers         {@tsabirgaliev gmail.com:tair.sabirgaliev} \
                    {@judaew judaew} openmaintainer

description         Core functionality needed to create .NET Core projects, that is \
                    shared between Visual Studio and CLI

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 >= 19}
supported_archs     x86_64 arm64

switch ${build_arch} {
    x86_64 {
        set dotnet_rid osx-x64
        distname            dotnet-sdk-${version}-osx-x64
        checksums           rmd160  880ca6e38b2c0d9b60e1dc432c54e054c3a95956 \
                            sha256  773c039073b02d89b150d84a5f20abafb1bcd8f7a1825ea32229f2422a5f3ee1 \
                            size    184485652
    }
    arm64 {
        set dotnet_rid osx-arm64
        distname            dotnet-sdk-${version}-osx-arm64
        checksums           rmd160  6d40dc628e582c51341ebcbcd75c0e6d6e6b6e9f \
                            sha256  b7ab72530789d7b09dbd2cb5a7572ee7d3a287ae9ab0fed87d455bf269c328d2 \
                            size    178669146
    }
    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://dotnetcli.azureedge.net/dotnet/Sdk/${version}/

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

use_configure       no

depends_run         port:dotnet-cli \
                    port:dotnet-runtime-6 \
                    port:aspnetcore-runtime-6

build {}

destroot {
    set dotnet_home ${prefix}/share/dotnet
    set dotnet_runtime_version 6.0.32

    # ASP.NET Core Targeting Pack
    set aspnet_target_dir /packs/Microsoft.AspNetCore.App.Ref
    set aspnet_target_version ${dotnet_runtime_version}
    xinstall -d ${destroot}${dotnet_home}${aspnet_target_dir}
    move ${worksrcpath}${aspnet_target_dir}/${aspnet_target_version} ${destroot}${dotnet_home}${aspnet_target_dir}

    # .NET AppHost Pack
    set dotnet_apphost_dir /packs/Microsoft.NETCore.App.Host.${dotnet_rid}
    set dotnet_apphost_version ${dotnet_runtime_version}
    xinstall -d ${destroot}${dotnet_home}${dotnet_apphost_dir}
    move ${worksrcpath}${dotnet_apphost_dir}/${dotnet_apphost_version} ${destroot}${dotnet_home}${dotnet_apphost_dir}

    # .NET Targeting Pack
    set dotnet_target_dir /packs/Microsoft.NETCore.App.Ref
    set dotnet_target_version ${dotnet_runtime_version}
    xinstall -d ${destroot}${dotnet_home}${dotnet_target_dir}
    move ${worksrcpath}${dotnet_target_dir}/${dotnet_target_version} ${destroot}${dotnet_home}${dotnet_target_dir}

    # SDK
    xinstall -d ${destroot}${dotnet_home}/sdk
    move ${worksrcpath}/sdk/${version} ${destroot}${dotnet_home}/sdk

    # SDK-Manifests
    set dotnet_manifest_version 6.0.300
    xinstall -d ${destroot}${dotnet_home}/sdk-manifests
    move ${worksrcpath}/sdk-manifests/${dotnet_manifest_version} ${destroot}${dotnet_home}/sdk-manifests

    # Templates
    set dotnet_templates_version ${dotnet_runtime_version}
    xinstall -d ${destroot}${dotnet_home}/templates
    move ${worksrcpath}/templates/${dotnet_templates_version} ${destroot}${dotnet_home}/templates
}

livecheck.type      regex
livecheck.url       https://dotnet.microsoft.com/download/dotnet/6.0
livecheck.regex     "SDK (\\d+(?:\\.\\d+)*)"