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

github.setup        taisei-project taisei 1.4.2 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            0
fetch.type          git

homepage            https://taisei-project.org/

description         A free and open-source Touhou Project fangame

long_description    \
    Taisei Project is an open source fan-game set in the world of Tōhō \
    Project. It is a top-down vertical-scrolling curtain fire shooting game \
    \(STG\), also known as a \"bullet hell\" or \"danmaku.\" STGs are \
    fast-paced games focused around pattern recognition and mastery through \
    practice.

categories          games
license             BSD CC-BY-SA-4
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

set py_version      312
set py_branch       \
    [string index ${py_version} 0].[string range ${py_version} 1 end]
set python_bin      ${prefix}/bin/python${py_branch}

depends_build-append \
                    path:bin/cmake:cmake \
                    port:pkgconfig \
                    port:py${py_version}-docutils \
                    port:python${py_version}

depends_lib-append  path:lib/libcrypto.dylib:openssl \
                    port:cglm \
                    port:freetype \
                    port:libpng \
                    port:libsdl2 \
                    port:libsdl2_mixer \
                    port:libzip \
                    port:opusfile \
                    port:py${py_version}-zstd \
                    port:webp \
                    port:zlib \
                    port:zstd

patchfiles-append   patch-meson.build.diff \
                    patch-doc-meson.build.diff

use_xcode           yes

configure.args-append \
                    -Dvalidate_glsl=false

build.env-append    PATH=$env(PATH):${workpath}/bin

post-fetch {
    system -W ${worksrcpath} "git submodule update --init --recursive"
}

post-extract {
    file mkdir ${workpath}/bin
    ln -sf ${python_bin} ${workpath}/bin/python3
}

post-patch {
    reinplace -E \
        "s|@@PY_VERSION@@|${py_branch}|g" ${worksrcpath}/doc/meson.build

    reinplace -E \
        "s|@@PYTHON_BIN@@|${python_bin}|g" ${worksrcpath}/meson.build

    # Force all Python scripts to use MacPorts Python
    foreach pyfile [exec find ${worksrcpath} -iname "*.py"] {
        reinplace -E "s|/usr/bin/env python3|${python_bin}|" ${pyfile}
    }
}

post-destroot {
    move ${destroot}${prefix}/Taisei.app ${destroot}${applications_dir}

    xinstall -d ${destroot}${prefix}/share/${name}

    move    ${destroot}${prefix}/COPYING \
            {*}[glob ${destroot}${prefix}/*.txt] \
            {*}[glob ${destroot}${prefix}/*.html] \
        ${destroot}${prefix}/share/${name}/
}

notes "
    Taisei is installed to ${applications_dir}
"

github.livecheck.regex \
                    {([0-9.]+)}

use_parallel_build no
