# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           meson 1.0

name                audacious-core
set real_name       audacious

# Please keep audacious, audacious-core and audacious-plugins synchronized.
version             4.5.1
revision            0

license             BSD
categories          audio
maintainers         {ionic @Ionic} \
                    {makr @mohd-akram}
homepage            https://www.audacious-media-player.org/
description         Audacious is an advanced audio player.
long_description    ${description} It is free, lightweight, based on GTK3, \
                    runs on Linux and many other *nix platforms. The player focuses on audio quality \
                    and supports a wide range of audio codecs. \
                    Its advanced audio playback engine is considerably more powerful than GStreamer. \
                    Audacious is a fork of Beep Media Player (BMP), which itself forked from XMMS.

# Maintainer-only helper for testing changes quickly and easily.
#fetch.type          git
#git.url             https://github.com/Ionic/${real_name}
#git.branch          ${real_name}-${version}-buildfix

master_sites        https://distfiles.audacious-media-player.org
distname            ${real_name}-${version}
use_bzip2           yes
checksums           rmd160  1a408531b6120181bf4ba707b3baf4a1d25f4cc4 \
                    sha256  7194743a0a41b1d8f582c071488b77f7b917be47ca5e142dd76af5d81d36f9cd \
                    size    642359

universal_variant   no

depends_build       port:gettext

depends_lib         port:libiconv \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glib-2.0.pc:glib2

depends_run         port:dbus

compiler.c_standard     1999
compiler.cxx_standard   2017

configure.args      -Ddbus=true \
                    -Dqt=false \
                    -Dqt5=false \
                    -Dgtk=false \
                    -Dgtk2=false \
                    -Dvalgrind=false

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

# This issue was supposed to be fixed, but it did not work as intended.
# Temporarily revert upstream commit and restore our patch. This is tested.
# https://github.com/audacious-media-player/audacious-plugins/pull/166
patchfiles-append   patch-big-endian.diff

post-destroot {
    xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${real_name}
    move ${destroot}${prefix}/share/${real_name}/AUTHORS \
         ${destroot}${prefix}/share/${real_name}/COPYING \
         ${destroot}${prefix}/share/doc/${real_name}
}

variant qt5 description {Add Qt5 support} {
    PortGroup   qt5 1.0

    qt5.depends_component   qtsvg

    configure.args-replace  -Dqt=false \
                            -Dqt=true \
                            -Dqt5=false \
                            -Dqt5=true
}

variant qt6 description {Add Qt6 support} {
    PortGroup   qt6 1.0

    qt6.depends_lib         qtsvg

    configure.args-replace  -Dqt=false \
                            -Dqt=true
}

variant gtk2 conflicts gtk3 description {Add GTK2 support} {
    depends_lib-append      path:lib/pkgconfig/gtk+-2.0.pc:gtk2

    configure.args-replace  -Dgtk=false \
                            -Dgtk=true \
                            -Dgtk2=false \
                            -Dgtk2=true
}

variant gtk3 conflicts gtk2 description {Add GTK3 support} {
    depends_lib-append      path:lib/pkgconfig/gtk+-3.0.pc:gtk3

    configure.args-replace  -Dgtk=false \
                            -Dgtk=true
}

# Need either one of gtk2, gtk3, Qt5 or Qt6 to have a GUI.
# Default to qt6, which is preferred by upstream.
if {![variant_isset gtk2] && ![variant_isset gtk3] && ![variant_isset qt5]} {
    # Fails to build on macOS - https://trac.macports.org/ticket/69214
    if {${os.platform} ne "darwin"} {
        default_variants-append +qt6
    }
}

if {![variant_isset gtk2] && ![variant_isset gtk3] && ![variant_isset qt6]} {
    if {${os.platform} eq "darwin" && ${os.major} < 11} {
        default_variants-append +gtk3
    } else {
        default_variants-append +qt5
    }
}

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     "${real_name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
