# -*- 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, as in the avcui port: avgui compiles avcui's core sources.
legacysupport.newest_darwin_requires_legacy 10
legacysupport.redirect_bins avgui

github.setup        barracuda156 avgui 6938c9ac6bb7403e0b724b0ee5993d87f6dacd49
version             0.1.0
revision            4
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. The shell comes \
                    from ImTube, so it runs on the same legacy-OpenGL over \
                    SDL2 path that works on G4 and G5 Power Macs. Playback is \
                    either mpv in its own window or GStreamer in-window.

github.tarball_from archive
distname            ${name}-src

# 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    8b74a9dc0453db548288c9ce796190a1cae82fed
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  af6bcdfc4bf849134e6a0d23c89542afaf26de84 \
                    sha256  810aae86800c20aef7c097c25ce873e6a5ccd98bfc51b64830a346302213a35d \
                    size    1338761 \
                    ${avcui_distfile} \
                    rmd160  6e2915aa4302f941fa3bc6c7a333edef0beb71b0 \
                    sha256  6d9a82957911d5a0faaa0e9d03656b240364bbbf47cac051217486241dd1e3a0 \
                    size    271788

worksrcdir          ${name}

installs_libs       no

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 +sdl2
}

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.
"
