# -*- 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           active_variants 1.1
PortGroup           boost 1.0
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           openssl 1.0

boost.version       1.81

name                parabolic
github.setup        NickvisionApps Parabolic 2024.12.1
revision            0
categories          net gnome multimedia
license             GPL-3
maintainers         {@nlogozzo} openmaintainer
description         Download web video and audio
long_description    GTK-based app to download video and audio \
                    from the web.
checksums           rmd160  1a01b4f8d46a746cbf5799299a108d9a49ec4c46 \
                    sha256  1037ce3aafcb8e1b5e7b6f2844bfe7ac3fd08f391e5aac8af9c337d6d4e26f99 \
                    size    4512335
github.tarball_from archive

depends_build-append \
                    port:blueprint-compiler \
                    port:gettext \
                    port:itstool \
                    path:bin/pkg-config:pkgconfig \
                    port:yelp-tools

depends_lib-append  port:desktop-file-utils \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gtk+-4.0.pc:gtk4 \
                    port:libadwaita \
                    port:libepoxy \
                    port:libnick \
                    port:libxmlxx5

depends_run-append  port:aria2 \
                    port:yt-dlp

compiler.cxx_standard   2020

configure.args-append \
                    -DCMAKE_INSTALL_LIBDIR=${prefix}/libexec/${name} \
                    -DUI_PLATFORM=gnome

variant secret description "Use libsecret instead of Apple keychain" {
    require_active_variants \
                    libnick secret

    depends_lib-append \
                    port:libsecret
    configure.args-append \
                    -DUSE_LIBSECRET=ON
}

if {${os.platform} ne "darwin" || ${os.major} < 12} {
    default_variants-append \
                    +secret
}

post-destroot {
    # In a case of libstdc++ we install our wrapper to fix malloc errors.
    # Otherwise we just rename existing wrapper so that it is recognizable.
    # The real binary sits in libexec.
    if {${os.platform} eq "darwin" && ${configure.cxx_stdlib} ne "libc++"} {
        delete ${destroot}${prefix}/bin/org.nickvision.tubeconverter
        copy ${filespath}/${name} ${destroot}${prefix}/bin/
        reinplace "s|@PREFIX@|${prefix}|g" ${destroot}${prefix}/bin/${name}
        file attributes ${destroot}${prefix}/bin/${name} -permissions 0755
    } else {
        move ${destroot}${prefix}/bin/org.nickvision.tubeconverter \
            ${destroot}${prefix}/bin/${name}
    }
}

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
    system "${prefix}/bin/gtk4-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
}

# https://trac.macports.org/ticket/70137
notes "
If you get an error upon launching the app,\
try setting GSK_RENDERER=cairo in the environment.\
Legacy macOS versions may also need LIBGL_ALLOW_SOFTWARE=true.\
These can be set on a command line or via a shell config file.
"
