# -*- 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
PortGroup               legacysupport 1.1

github.setup            haasn libplacebo 7.360.1 v
github.tarball_from     archive
revision                0
categories              devel multimedia
license                 LGPL-2
maintainers             {i0ntempest @i0ntempest} openmaintainer

description             core rendering algorithms and ideas of mpv rewritten as an independent library
long_description        ${name} is, in a nutshell, the core rendering algorithms and ideas of mpv rewritten as an \
                        independent library. As of today, libplacebo contains a large assortment of video processing \
                        shaders, focusing on both quality and performance.
homepage                https://libplacebo.org

checksums               rmd160  ad8aa03905ee17a09cc157a7d6a742fc41f4af15 \
                        sha256  d05fdf90bea2f629eaa2d115e909fd356388ac639e54f77b87a018a6d76224bd \
                        size    862269

set python_ver          3.14
set python_branch       [string map {. {}} ${python_ver}]

# Vulkan headers required regardless of vulkan feature
depends_build-append    port:fast-float \
                        port:pkgconfig \
                        port:vulkan-headers \
                        port:py${python_branch}-jinja2

depends_lib-append      port:lcms2 \
                        port:xxhashlib

post-patch {
    reinplace "s|import\(\'python\'\).find_installation\(\)|import\(\'python\'\).find_installation\(\'${frameworks_dir}/Python.framework/Versions/${python_ver}/bin/python${python_ver}\'\)|" \
        ${worksrcpath}/meson.build
}

configure.args-append   -Dvulkan=disabled \
                        -Dvk-proc-addr=disabled \
                        -Dopengl=disabled \
                        -Dgl-proc-addr=disabled \
                        -Dd3d11=disabled \
                        -Ddovi=enabled \
                        -Dlibdovi=disabled \
                        -Ddemos=false \
                        -Dtests=false \
                        -Dglslang=disabled \
                        -Dshaderc=disabled \
                        -Dxxhash=enabled \
                        -Dlcms=enabled \
                        -Dunwind=disabled
# consider adding libdovi later: https://github.com/quietvoid/dovi_tool

# https://trac.macports.org/ticket/73919, https://cgit.freebsd.org/ports/commit/?id=3e04376300805a264a0533d3557e6c7bb2855600
post-patch {
    reinplace "/find.*glslang.*static/s|)|, dirs: vulkan_lib_dirs)|" ${worksrcpath}/src/glsl/meson.build
}
configure.args-append   -Dvulkan-sdk=${prefix}

compiler.c_standard     2011
compiler.cxx_standard   2020
# Undefined symbols:
# "std::__1::to_chars(char*, char*, double)"
# "std::__1::__from_chars_result<double> std::__1::__from_chars_floating_point<double>(char const*, char const*, std::__1::chars_format)"
legacysupport.newest_darwin_requires_legacy \
                        22
legacysupport.use_mp_libcxx \
                        yes

variant opengl description {enable OpenGL support} {
    depends_build-append \
                        port:py${python_branch}-glad2
    configure.args-replace \
                        -Dopengl=disabled \
                        -Dopengl=enabled
    configure.args-replace \
                        -Dgl-proc-addr=disabled \
                        -Dgl-proc-addr=enabled
}

variant vulkan description {enable Vulkan support} {
    depends_lib-append  port:vulkan-loader
    configure.args-replace \
                        -Dvulkan=disabled \
                        -Dvulkan=enabled
    configure.args-replace \
                        -Dvk-proc-addr=disabled \
                        -Dvk-proc-addr=enabled
}

variant demo description {build demo programs} {
    configure.args-replace \
                        -Ddemos=false \
                        -Ddemos=true
}

variant glslang description {enable glslang SPIR-V compiler support} {
    depends_lib-append  port:glslang
    configure.args-replace \
                        -Dglslang=disabled \
                        -Dglslang=enabled
}

default_variants-append +opengl
