# -*- 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

name                qmmp

categories          audio multimedia
license             GPL-2
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer

description         Qt-based multimedia player
long_description    {*}${description}

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    PortGroup       qt4 1.0

    version         0.12.20
    revision        1
    set branch      [join [lrange [split ${version} .] 0 1] .]

    checksums       rmd160  328cf0056717542c0bd94eea3a3872a77be7fc06 \
                    sha256  b26192e7ed11df8aa6c2b86bc1a8d220e2a5a16e9f9cbc569ec97e89c6de5e4c \
                    size    1461567

    patchfiles-append \
                    patch-CMakeLists.diff

    platform powerpc {
        patchfiles-append \
                    patch-powerpc.diff
    }

    configure.args-append \
                    -DUSE_HAL=OFF \
                    -DUSE_MONOTOSTEREO=ON \
                    -DUSE_UDISKS2=OFF

    # Temporarily disabling these, since they fail to build.
    # Undefined symbols: "QX11Info::display()", referenced from:
    # Notifier::hasFullscreenWindow() const in notifier.cpp.o
    # moc_statusiconpopupwidget.cpp: error: ‘StatusIconPopupWidget’ has not been declared
    # qobject.h: error: ‘QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> > QObject::d_ptr’ is protected
    # moc_statusiconpopupwidget.cpp: error: ‘QProgressBar’ has not been declared
    configure.args-append \
                    -DUSE_NOTIFIER=OFF \
                    -DUSE_STATICON=OFF
} else {
    PortGroup       qt5 1.0

    version         1.6.9
    revision        1
    qt5.depends_component qtmultimedia qttools sqlite-plugin

    checksums       rmd160  834a06165b90bc924b7fdcfba63a8df6e5162722 \
                    sha256  87af24fe5494268aee98400096df286dbf133ccb7ee09c8e7b30e4b022863871 \
                    size    1375274

    configure.args-append \
                    -DUSE_HISTORY=ON \
                    -DUSE_PIPEWIRE=OFF

    # Enabling only for Qt5 for now, see above:
    configure.args-append \
                    -DUSE_NOTIFIER=ON \
                    -DUSE_STATICON=ON
}

set branch          [join [lrange [split ${version} .] 0 1] .]

use_bzip2           yes
homepage            https://qmmp.ylsoftware.com
master_sites        ${homepage}/files/qmmp/${branch}/

# Avoid arbitrary prefix:
patchfiles-append   patch-fix-include.diff

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

depends_lib-append  port:curl \
                    port:desktop-file-utils \
                    port:enca \
                    port:faad2 \
                    path:lib/libavcodec.dylib:ffmpeg \
                    port:flac \
                    port:libarchive \
                    port:libbs2b \
                    port:libcddb \
                    port:libcdio \
                    port:libcdio-paranoia \
                    port:libmms \
                    port:libmodplug \
                    port:libmpcdec \
                    port:libogg \
                    port:libopus \
                    port:libsndfile \
                    port:libvorbis \
                    port:soxr \
                    port:taglib \
                    port:wavpack \
                    port:xorg-libX11 \
                    port:xorg-xorgproto

configure.args-append \
                    -DUSE_AAC=ON \
                    -DUSE_ALSA=OFF \
                    -DUSE_ANALYZER=ON \
                    -DUSE_ARCHIVE=ON \
                    -DUSE_BS2B=ON \
                    -DUSE_CDA=ON \
                    -DUSE_CONVERTER=ON \
                    -DUSE_COPYPASTE=ON \
                    -DUSE_COVER=ON \
                    -DUSE_CROSSFADE=ON \
                    -DUSE_CUE=ON \
                    -DUSE_CURL=ON \
                    -DUSE_ENCA=ON \
                    -DUSE_FFMPEG=ON \
                    -DUSE_FILEOPS=ON \
                    -DUSE_FILEWRITER=ON \
                    -DUSE_FLAC=ON \
                    -DUSE_GME=OFF \
                    -DUSE_GNOMEHOTKEY=OFF \
                    -DUSE_HOTKEY=OFF \
                    -DUSE_JACK=OFF \
                    -DUSE_KDENOTIFY=OFF \
                    -DUSE_LADSPA=OFF \
                    -DUSE_LYRICS=ON \
                    -DUSE_MAD=OFF \
                    -DUSE_MPG123=OFF \
                    -DUSE_MIDI=OFF \
                    -DUSE_MODPLUG=ON \
                    -DUSE_MPC=ON \
                    -DUSE_MPLAYER=OFF \
                    -DUSE_MPRIS=OFF \
                    -DUSE_NULL=OFF \
                    -DUSE_OPUS=ON \
                    -DUSE_OSS4=OFF \
                    -DUSE_PROJECTM=OFF \
                    -DUSE_PULSE=OFF \
                    -DUSE_QSUI=ON \
                    -DUSE_QTMULTIMEDIA=ON \
                    -DUSE_RGSCAN=ON \
                    -DUSE_SB=ON \
                    -DUSE_SCROBBLER=ON \
                    -DUSE_SHOUT=OFF \
                    -DUSE_SID=OFF \
                    -DUSE_SKINNED=OFF \
                    -DUSE_SNDFILE=ON \
                    -DUSE_SOXR=ON \
                    -DUSE_STEREO=ON \
                    -DUSE_TRACKCHANGE=ON \
                    -DUSE_UDISKS=OFF \
                    -DUSE_VORBIS=ON \
                    -DUSE_WAVPACK=ON

variant mad conflicts mpg123 description "Use libmad for MPEG decoding" {
    depends_lib-append \
                    port:libmad
    configure.args-replace \
                    -DUSE_MAD=OFF -DUSE_MAD=ON
}

variant mpg123 conflicts mad description "Use libmad for MPEG decoding" {
    depends_lib-append \
                    port:mpg123
    configure.args-delete \
                    -DUSE_MPG123=OFF
}

variant pulse description "Enable PulseAudio output" {
    depends_lib-append \
                    port:pulseaudio
    configure.args-replace \
                    -DUSE_PULSE=OFF -DUSE_PULSE=ON
}

variant shout description "Enable Icecast output" {
    depends_lib-append \
                    port:libshout
    configure.args-replace \
                    -DUSE_SHOUT=OFF -DUSE_SHOUT=ON
}

if {![variant_isset mpg123]} {
    default_variants-append \
                    +mad
}

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}
