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

# O_CLOEXEC
legacysupport.newest_darwin_requires_legacy 10
legacysupport.redirect_bins avgui

github.setup        barracuda156 avgui 38ef71aeabd8643efab824c71ce2a4e599452150
version             0.1.0
revision            0
categories          www multimedia nsfw
license             MIT
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer

description         Dear ImGui front-end for avcui
long_description    ${name} puts a windowed Dear ImGui interface on avcui’s \
                    content providers, sharing its config, library and \
                    thumbnail cache with the terminal client. Playback is \
                    either mpv in its own window or GStreamer in-window.

github.tarball_from archive

# avgui builds avcui's provider core from source as a static library.
# The avcui port installs a binary only (installs_libs no), so avcui's tree is
# fetched here as a second distfile rather than depended on. Both trees vendor
# nlohmann/json.hpp and avgui's CMakeLists prefers the vendored copy, so unlike
# the avcui and imtube ports this one needs no nlohmann-json build dependency.

set avcui_commit    ec6cbc9eb369693692e053e491fd217f73328699
set avcui_distfile  avcui-${avcui_commit}.tar.gz
set avcui_worksrc   ${workpath}/avcui-${avcui_commit}

master_sites-append https://github.com/barracuda156/avcui/archive/${avcui_commit}/:avcui
distfiles-append    ${avcui_distfile}:avcui

checksums           ${distname}${extract.suffix} \
                    rmd160  d9d4952256a9b0dd95500f697730ef2a5273c1e6 \
                    sha256  82d63d16a775644b63ca6d22549a5bd804f76361c914905fab3a50d437f36824 \
                    size    1341614 \
                    ${avcui_distfile} \
                    rmd160  101b2817e9403485769c1fbd2083dfbb628a3bdb \
                    sha256  493e16eec9ed4548833d8e9e5832456bc0896ff5453a2a6f71fc399ec5a74f25 \
                    size    274081

installs_libs       no

compiler.c_standard     2011
compiler.cxx_standard   2020

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:curl-impersonate \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:gstreamer1 \
                    port:gstreamer1-gst-plugins-base \
                    port:imgui

# Must match yt-dlp python, as in the avcui port.
set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]

# mpv is the default playback backend and ffmpeg is the byte source for
# the in-window one (seeks, and MissAV's HLS manifest). Codec/container support:
# nothing links against the GStreamer plugins, but without them a pipeline
# opens and produces no video.
depends_run-append  path:bin/ffmpeg:ffmpeg \
                    port:gstreamer1-gst-libav \
                    port:gstreamer1-gst-plugin-dav1ddec \
                    port:gstreamer1-gst-plugins-bad \
                    port:gstreamer1-gst-plugins-good \
                    path:bin/mpv:mpv-devel \
                    port:py${py_ver_nodot}-curl-cffi \
                    port:yt-dlp

configure.args-append \
                    -DAVCUI_DIR=${avcui_worksrc} \
                    -DIMTUBE_ALLOW_FETCH=NO \
                    -DIMTUBE_IMGUI=system \
                    -DIMTUBE_RENDERER=gl2

# 1080p is the upstream first-launch default; these machines want less.
if {${os.arch} eq "powerpc"} {
    configure.args-append \
                    -DIMTUBE_DEFAULT_RESOLUTION=480
}

variant glfw conflicts sdl2 sdl3 description "Use GLFW windowing" {
    depends_lib-append \
                    path:lib/pkgconfig/glfw3.pc:glfw
    configure.args-append \
                    -DIMTUBE_PLATFORM=glfw
}

variant sdl2 conflicts glfw sdl3 description "Use SDL2 windowing" {
    depends_lib-append \
                    port:libsdl2
    configure.args-append \
                    -DIMTUBE_PLATFORM=sdl2
}

variant sdl3 conflicts glfw sdl2 description "Use SDL3 windowing" {
    depends_lib-append \
                    port:SDL3
    configure.args-append \
                    -DIMTUBE_PLATFORM=sdl3
}

if {![variant_isset glfw] && ![variant_isset sdl3]} {
    default_variants +glfw
}

notes "
avgui shares its settings, library and thumbnail cache with avcui:
~/.config/avcui, ~/.local/share/avcui and ~/.cache/avcui.

PornHub needs yt-dlp with impersonation support (py${py_ver_nodot}-curl-cffi,
pulled in above), otherwise the extractor gets HTTP 410.
"
