# -*- 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
PortGroup           github 1.0

name                godot
categories          games graphics multimedia
platforms           darwin
license             MIT
maintainers         @jasonliu--

homepage            https://${name}engine.org
description         cross-platform 2-D and 3-D game development \
                    environment
long_description    Godot Engine is a cross-platform game engine for \
                    creating 2-D and 3-D games. Godot aims to offer a \
                    fully integrated game development environment. It \
                    provides a comprehensive set of common tools, and \
                    games can be exported to a number of target \
                    platforms, including major desktop platforms \
                    (Linux, macOS, Windows), as well as mobile \
                    (Android, iOS) and web-based (HTML5) platforms.

github.setup        ${name}engine ${name} 4.6.2 "" -stable
github.tarball_from archive

checksums           rmd160  85eded24e42ec727f59036f49946f96900c8b6bb \
                    sha256  908b759e7517fec65d687b3d468cd639fd8967d25da1522ef8a2087af638b3fe \
                    size    66048870

# Godot 4 requires macOS 10.13 (x86_64) or macOS 11.0 (arm64)
if {${os.platform} eq "darwin" && ${os.major} < 17} {
    known_fail      yes
    pre-fetch {
        ui_error "${name} @${version} requires macOS 10.13 or later."
        return -code error "incompatible macOS version"
    }
}

depends_build-append    port:scons \
                        port:pkgconfig
depends_lib-append      port:freetype \
                        port:libpng \
                        port:zlib \
                        port:zstd \
                        port:libtheora \
                        port:libogg \
                        port:libvorbis \
                        port:miniupnpc \
                        port:pcre2 \
                        port:MoltenVK

patchfiles-append       add-external_libs-support.diff \
                        configure-macports-compiler.diff

use_configure       no
use_xcode           yes

build.cmd           ${prefix}/bin/scons
build.env-append    BUILD_NAME=macports_build
build.target        platform=macos \
                    arch=${build_arch} \
                    target=editor \
                    verbose=yes \
                    warnings=extra

build.args-append   vulkan_sdk_path=${prefix}/Library/Frameworks/MoltenVK.xcframework \
                    builtin_freetype=no \
                    builtin_libpng=no \
                    builtin_zlib=no \
                    builtin_zstd=no \
                    builtin_libtheora=no \
                    builtin_libogg=no \
                    builtin_libvorbis=no \
                    builtin_miniupnpc=no \
                    builtin_pcre2=no

compiler.cxx_standard   2017
# Configure the compiler
if {[string match macports-clang-* ${configure.compiler}]} {
    set clang_v [
        string range ${configure.compiler} [
            string length macports-clang-
        ] end
    ]
    build.args-append       macports_clang=${clang_v}
    build.env-append        MACPORTS_PREFIX=${prefix}
}

destroot {
    copy ${worksrcpath}/misc/dist/macos_tools.app \
         ${destroot}${applications_dir}/Godot.app
    xinstall -d ${destroot}${applications_dir}/Godot.app/Contents/MacOS
    move ${worksrcpath}/bin/${name}.macos.editor.${build_arch} \
         ${destroot}${applications_dir}/Godot.app/Contents/MacOS/Godot
    ln -s ${applications_dir}/Godot.app/Contents/MacOS/Godot \
       ${destroot}${prefix}/bin/${name}
}

livecheck.regex     releases/tag/(\\d+\\.\\d+(?:\\.\\d+)*)-stable
