# -*- 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           cmake 1.1

name                supertuxkart
version             1.4
revision            0
categories          games
license             GPL-3+
maintainers         nomaintainer

description         Tux racing game
long_description    SuperTuxKart is a Free 3D kart racing game, with many tracks, characters, and items for you to try.
distname            SuperTuxKart-${version}-src

use_xz              yes

homepage            https://supertuxkart.net/

checksums           rmd160  3fd69526d79dc70392e3e4f8319a4996c23091ae \
                    sha256  9890392419baf4715313f14d5ad60746f276eed36eb580636caf44e2532c0f03 \
                    size    650010456

master_sites        sourceforge:project/${name}/SuperTuxKart/${version}

# Remove Homebrew and -arch flag cruft
patchfiles-append   patch-supertuxkart-cmake.diff

# fatal error: 'IOSurface/IOSurfaceRef.h' file not found
patchfiles-append   patch-supertuxkart-iosurfaceref.diff

# Need a C++14 compatible compiler in order to resolve:
# error: chosen constructor is explicit in copy-initialization
compiler.cxx_standard   2014
platform darwin {
    post-patch {
        reinplace "s|10\.9|${macosx_deployment_target}|g" ${worksrcpath}/data/SuperTuxKart-Info.plist
    }
}

set python.branch   3.11
set python.version  [join [split ${python.branch} "."] ""]

depends_build-append \
    port:pkgconfig

depends_lib-append \
    port:curl \
    port:freetype \
    port:fribidi \
    port:glew \
    path:lib/pkgconfig/harfbuzz.pc:harfbuzz \
    path:include/turbojpeg.h:libjpeg-turbo \
    port:libogg \
    port:libpng \
    port:libsamplerate \
    port:libsdl2 \
    port:libvorbis \
    port:mbedtls \
    port:openal-soft \
    port:python${python.version} \
    port:sqlite3 \
    port:squish \
    port:zlib

configure.args-append -DFREETYPE_INCLUDE_DIRS=${prefix}/include/freetype2 \
                      -DPYTHON_EXECUTABLE=${prefix}/bin/python${python.branch} \

# don't use OpenSSL, use mbedtls to avoid distribution issues.
configure.args-append -DUSE_CRYPTO_OPENSSL=OFF

# System Bluetooth headers don't work with modern compilers on Snow Leopard
# IOBluetoothHostController.h:42:29: error: unsafe_unretained property 'delegate' may not also be declared __weak
if { ${os.platform} eq "darwin" && ${os.major} <= 10 } {
    configure.args-append -DUSE_WIIUSE=OFF
}

if { ${os.platform} eq "darwin" && ${os.major} <= 14 } {
    # No Metal, https://trac.macports.org/ticket/67263
    patchfiles-append patch-supertuxkart-no-metal.diff
    configure.args-append -DDLOPEN_MOLTENVK=ON
}

# suppress warning gl.h and gl3.h are both included
configure.cppflags-append -DGL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED

destroot {
    move ${workpath}/build/bin/supertuxkart.app ${destroot}${applications_dir}
    file delete ${destroot}${applications_dir}/supertuxkart.app/Contents/Resources/data
    move ${worksrcpath}/data ${destroot}${applications_dir}/supertuxkart.app/Contents/Resources/
}

livecheck.type      sourceforge
livecheck.regex     "supertuxkart-((\\d+(\\.)*)+)-src\\.tar\\.xz"
