# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*-

PortSystem          1.0
PortGroup           github 1.0

github.setup        nilaoda N_m3u8DL-RE 0.5.1-beta v
github.tarball_from archive
name                [join [split [string tolower ${github.project}] _] -]
revision            0

categories          net multimedia dotnet
supported_archs     arm64 x86_64
license             MIT
maintainers         {i0ntempest @i0ntempest} openmaintainer

description         Cross-Platform, modern and powerful stream downloader for MPD/M3U8/ISM
long_description    ${github.project} is a cross-platform DASH/HLS/MSS download tool. \
                    Supports on-demand and live streaming (DASH/HLS).

checksums           rmd160  37b3bf70d9f0f32eb6ea729e8a60bd4a26b7c28f \
                    sha256  55559fec4deef7e40a4d45eebb699865f01d04f7e72110ce5d11b4ca3e655a93 \
                    size    2843589

universal_variant   no

set dotnet_sdk_ver_maj \
                    10
depends_build       port:dotnet-sdk-${dotnet_sdk_ver_maj} \
                    path:bin/dotnet:dotnet-cli

set dotnet_root_env DOTNET_ROOT=${prefix}/share/dotnet
set shared_env "
    ${dotnet_root_env} \
    DOTNET_CLI_TELEMETRY_OPTOUT=1 \
    DOTNET_CLI_HOME=${workpath} \
    NUGET_PACKAGES=${workpath}/.nuget/packages \
    DOTNET_CLI_USE_MSBUILD_SERVER=0 \
    DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
"

configure.env-append \
                    {*}$shared_env
build.env-append    {*}$shared_env
destroot.env-append {*}$shared_env

set dotnet_cmd      ${prefix}/bin/dotnet

post-patch {
    # src/N_m3u8DL-RE.Parser/StreamExtractor.cs(59,27): error CS0027: Keyword 'this' is not available in the current context
    reinplace "s|MemberNotNull(nameof(this.rawText), nameof(this.extractor))|MemberNotNull(nameof(rawText), nameof(extractor))|g" \
        ${worksrcpath}/src/N_m3u8DL-RE.Parser/StreamExtractor.cs
}

configure {
    ui_debug "configure - restore project"
    system -W ${worksrcpath}/src \
        "${configure.env} ${dotnet_cmd} restore ${github.project}.sln \
         --disable-build-servers \
         --use-current-runtime \
         --nologo"
}

build.cmd           ${dotnet_cmd} publish
build.target        src/${github.project}/${github.project}.csproj
build.args          --disable-build-servers \
                    --nologo \
                    -c Release \
                    --use-current-runtime \
                    -o publish \
                    -nodeReuse:false \
                    -property:UseSharedCompilation=false

destroot {
    xinstall -m 0755 ${worksrcpath}/publish/${github.project} ${destroot}${prefix}/bin/
    ln -s ${github.project} ${destroot}${prefix}/bin/${name}
}
