# -*- 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           github 1.0
PortGroup           qmake 1.0

set myname          qmmp
name                lib${myname}
# 2025-12-24
github.setup        Greedysky TTKMusicPlayer e14bc7ead6a8c3b78a81dbaa31aa1c7e481736c8
version             4.2.0.0
# Not used below, but for the reference:
set qmmp_v          1.7.9
revision            3
categories          audio
license             {GPL-3 LGPL-3}
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
description         Libary for TTKMusicPlayer
long_description    {*}${description}
checksums           rmd160  e4b77b4b739076b558186acb306fe8f2b98a144d \
                    sha256  07effd57c19bde2e016ef51340a84e73d05b22b1d4e5ed3755b90c4278219d41 \
                    size    608363
github.tarball_from     archive
github.livecheck.branch plugins

worksrcdir          ${github.project}-${github.version}/${myname}

patch.pre_args-replace  -p0 -p1

patchfiles-append   0001-v2m-fix-CheckV2MVersion-signature.patch \
                    0002-Fix-dependencies-headers.patch

post-patch {
    reinplace "s|CONFIG += USE_STATIC_LIBRARY||" ${worksrcpath}/${myname}.pri
    reinplace "s|Visual||" ${worksrcpath}/src/plugins/plugins.pro
}

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

depends_lib-append  port:adplug \
                    port:enca \
                    port:faad2 \
                    port:ffmpeg \
                    port:flac \
                    port:libADLMIDI \
                    port:libarchive \
                    port:libasap \
                    port:libayfly \
                    port:libbs2b \
                    port:libbuzzic \
                    port:libcddb \
                    port:libcdio \
                    port:libcdio-paranoia \
                    port:libdca \
                    port:libfc14audiodecoder \
                    port:libgme \
                    port:libhively \
                    port:libken \
                    port:libmms \
                    port:libmodplug \
                    port:libogg \
                    port:libopenmpt \
                    port:libopus \
                    port:libpsf \
                    port:libs98 \
                    port:libsamplerate \
                    port:libsc68 \
                    port:libsidplayfp \
                    port:libsndfile \
                    port:libsoundmon \
                    port:libtfmx \
                    port:libvorbis \
                    port:libxmp \
                    port:mpg123 \
                    port:musepack \
                    port:opusfile \
                    port:organya \
                    port:portaudio \
                    port:pulseaudio \
                    port:qoa \
                    port:sonic \
                    port:soxr \
                    port:speex \
                    port:stsound \
                    port:taglib \
                    port:v2m \
                    port:wavpack \
                    port:zlib

depends_run-append  path:bin/mplayer:MPlayer

configure.args-append \
                    ${worksrcpath}/${myname}.pro

compiler.cxx_standard   2011
# ffap.c:1238:1: error: function multiversioning is not supported on the current target
compiler.blacklist-append \
                    {clang}

set ttkroot         ${prefix}/libexec/TTKMusicPlayer

destroot {
    xinstall -d ${destroot}${ttkroot}
    copy ${worksrcpath}/bin/${version} ${destroot}${ttkroot}/
}

post-destroot {
    set mainlib ${ttkroot}/${version}/libTTKqmmp.dylib
    system "install_name_tool -id ${mainlib} ${destroot}${mainlib}"
    foreach dylib [ exec find ${destroot}${ttkroot}/${version} -name "\*.dylib" ] {
        regsub ":$" ${dylib} "" destroot_dylib_path
        regsub ${destroot} ${destroot_dylib_path} "" dylib_path
        system "install_name_tool -id ${dylib_path} ${destroot_dylib_path}"
        system "install_name_tool -change libTTKqmmp.dylib ${mainlib} ${destroot_dylib_path}"
    }
    system "install_name_tool -change libTTKqmmp.dylib ${mainlib} \
        ${destroot}${ttkroot}/${version}/demo.app/Contents/MacOS/demo"
}
