# -*- 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-devel
set main_version    11.0.100
set full_version    11.0.0
# See patch version in https://dotnet.microsoft.com/download/dotnet/11.0
set patch_version   rc.1.26425.128
version             ${main_version}-${patch_version}
revision            0
categories          dotnet devel
license             MIT
maintainers         @BjarneDMat {@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 >= 21}
supported_archs     x86_64 arm64

switch ${build_arch} {
    x86_64 {
        set dotnet_rid osx-x64
        distname            dotnet-sdk-${version}-osx-x64
        checksums           rmd160  144af0ab764ee17b65b172113f294cf53263bae8 \
                            sha256  739e484e877c1fd84df13fc00cdc2ce68f5f24a3fa585a0709f29705c0b0c6a3 \
                            size    206793748
    }
    arm64 {
        set dotnet_rid osx-arm64
        distname            dotnet-sdk-${version}-osx-arm64
        checksums           rmd160  50b7708aae09d2622b87ed7b63f7440c3fc56cf6 \
                            sha256  a9fdddab915bac780fc656b095db8a83289fb65f829866722a830ed54c9b75f5 \
                            size    197522617
    }
    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/Sdk/${version}/

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

use_configure       no

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

build {}

destroot {
    set dotnet_home ${prefix}/share/dotnet
    set dotnet_runtime_version ${full_version}-${patch_version}

    # ASP.NET Core Targeting Pack
    set aspnet_target_dir /packs/Microsoft.AspNetCore.App.Ref
    set aspnet_target_version ${full_version}-${patch_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
    # check the correct versions for each update
    set dotnet_manifest_versions [list "11.0.100-rc.1"]
    xinstall -d ${destroot}${dotnet_home}/sdk-manifests
    foreach manifest ${dotnet_manifest_versions} {
        move ${worksrcpath}/sdk-manifests/${manifest} ${destroot}${dotnet_home}/sdk-manifests
    }

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

livecheck.version   [join [lrange [split ${patch_version} .] 0 0] .]
livecheck.type      regex
livecheck.url       https://dotnet.microsoft.com/download/dotnet/11.0
livecheck.regex     "SDK ${main_version}-(\\d)"
