# -*- 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                d3dmetal
version             3.0
epoch               1
categories          devel
maintainers         {@Gcenx gmail.com:gcenx83}
homepage            https://developer.apple.com/games
platforms           {darwin any >= 23}
license             Restrictive
# Yes this only supports x86_64 and only works on Apple Silicon
supported_archs     x86_64
description         Direct3D to Metal translation layer
long_description    {*}${description}
master_sites        https://download.developer.apple.com/Developer_Tools/Game_Porting_Toolkit_3.0

distname            Evaluation_environment_for_Windows_games_3.0
use_dmg             yes

checksums           rmd160  e262284bef5c6a0819325386ed3f2a0aa32c0a6c \
                    sha256  d49395fb07e536804d1da0858590e53f6aa6fab12512e18fd80a74c87f9f063c \
                    size    25006010

fetch {
    if {![file isfile ${distpath}/${distfiles}]} {
        ui_error "This port cannot download the needed files automatically."
        ui_error "Please log in to your Apple Developer account at:"
        ui_error ""
        ui_error "https://developer.apple.com/download/"
        ui_error ""
        ui_error "Then paste this URL into your browser:"
        ui_error ""
        ui_error "${master_sites}/${distname}${extract.suffix}"
        ui_error ""
        ui_error "Place the downloaded file in this directory:"
        ui_error ""
        ui_error "${distpath}"
        ui_error ""
        ui_error "Then retry installing this port."
        ui_error ""
        return -code error "${distfiles} missing"
    }
}

use_configure       no
build {}

set d3dmetal        ${prefix}/libexec/d3dmetal
set docdir          ${prefix}/share/doc/${subport}

destroot {
    xinstall -d ${destroot}${d3dmetal}
    system "ditto ${worksrcpath}/redist/lib ${destroot}${d3dmetal}"

    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} Acknowledgements.rtf License.rtf "Read Me.rtf" ${destroot}${docdir}

    # Remove broken symlink
    file delete ${destroot}${d3dmetal}/external/D3DMetal.framework/Headers

    # Remove useless stubs
    file delete ${destroot}${d3dmetal}/wine/x86_64-unix/d3d10.so
    file delete ${destroot}${d3dmetal}/wine/x86_64-windows/d3d10.dll

    # Rename files to enable metalfx
    move ${destroot}${d3dmetal}/wine/x86_64-unix/nvngx-on-metalfx.so ${destroot}${d3dmetal}/wine/x86_64-unix/nvngx.so
    move ${destroot}${d3dmetal}/wine/x86_64-windows/nvngx-on-metalfx.dll ${destroot}${d3dmetal}/wine/x86_64-windows/nvngx.dll
}

notes "
    Please review the D3DMetal documentation found at ${docdir}
"

platform darwin i386 {
    pre-fetch {
        if {${os.major} >= 23} {
            set is_rosetta2 [exec sysctl -in sysctl.proc_translated]
            if { ${is_rosetta2} != 1 } {
                error "$name does not work on Intel hardware"
            }
        }
    }
}

livecheck.type      none
