# -*- 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               legacysupport 1.1
PortGroup               openssl 1.0
PortGroup               waf 1.0

# strndup
legacysupport.newest_darwin_requires_legacy 10

name                    xmms2
github.setup            xmms2 xmms2-devel 0.9.5
github.tarball_from     releases
revision                3
categories              audio
# Mostly LGPL, some plugins and clients are GPL
license                 LGPL-2.1+ GPL-2+ GPL-2
maintainers             nomaintainer
use_xz                  yes

description             CrossPlatform Music Multiplexer System
long_description        Next generation audio player of XMMS

distname                ${name}-${version}

checksums               rmd160  ec8beae90b455e6af7311fb37c2382705e8843e9 \
                        sha256  695f2305e4085e9d7a07cabc6c5669a00a55745fe7d6013651dd21fa1f621333 \
                        size    1741972

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

set ffmpeg_ver          6
depends_lib-append      port:curl \
                        port:faad2 \
                        port:ffmpeg${ffmpeg_ver} \
                        port:fftw-3-single \
                        port:flac \
                        port:fluidsynth \
                        port:gettext-runtime \
                        path:lib/pkgconfig/glib-2.0.pc:glib2 \
                        port:libao \
                        port:libcdio-paranoia \
                        port:libdiscid \
                        port:libmad \
                        port:libmms \
                        port:libmodplug \
                        port:libmpcdec \
                        port:libofa \
                        port:libogg \
                        port:libsamplerate \
                        port:libshout2 \
                        port:libsndfile \
                        port:libvorbis \
                        port:libxml2 \
                        port:mpg123 \
                        port:opusfile \
                        path:lib/libspeex.dylib:speex \
                        port:wavpack

waf.python_branch       3.12

configure.pkg_config_path \
                        ${prefix}/libexec/ffmpeg${ffmpeg_ver}/lib/pkgconfig
configure.args-append   --conf-prefix=${prefix}

post-patch {
    fs-traverse f ${worksrcpath}/waftools {
        if {[string match *.py ${f}]} {
            reinplace -q "s|/usr/bin/env python$|${prefix}/bin/${waf.python_branch}|" ${f}
        }
    }
}

# error: incompatible function pointer types passing
# 'void (DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType,
# const char *, const char *, uint16_t, uint16_t, const char *, void *)'
# to parameter of type 'DNSServiceResolveReply'
if {[string match *clang* ${configure.compiler}]} {
    configure.cflags-append -Wno-error=incompatible-function-pointer-types
}

# Xcode gcc fails to build this at least due to pragmas inside functions.
# Rather use a newer compiler than carry a patch indefinitely.
# This does not hurt, since a newer gcc is strictly required
# anyway due to several dependencies, beginning from python312.
compiler.blacklist-append   *gcc-4.0 *gcc-4.2

options optionals

options disabled_plugins
default disabled_plugins {daap jack pulse samba}

# not supported
configure.post_args-delete  --nocache

variant pulse description {Pulseaudio support} {
    depends_lib-append  port:pulseaudio

    disabled_plugins-delete pulse
}

variant jack description {Jack audio support} {
    depends_lib-append  port:jack

    disabled_plugins-delete jack
}

variant cpp description {C++ development support} {
    PortGroup           boost 1.0

    configure.args-append \
                        --boost-includes [boost::include_dir] \
                        --boost-libs [boost::lib_dir]
    optionals-append    xmmsclient++ xmmsclient++-glib
}

# These two introduce a dependency on avahi.
variant avahi description {MDNS and DAAP using avahi} {
    depends_lib-append  port:avahi
    
    disabled_plugins-delete daap
    optionals-append    mdns
}

variant samba description {Enable smbclient support} {
    depends_lib-append  port:samba3

    disabled_plugins-delete samba
}

variant perl description {Perl development support} {
    depends_lib-append  port:perl5.34 port:p5.34-pod-parser
    configure.args-append   --with-perl-binary ${prefix}/bin/perl5.34
    configure.env-append    PODSELECT=${prefix}/bin/podselect-5.34
    optionals-append    perl
}

variant ruby description {Ruby development support} {
    depends_lib-append  port:ruby33
    configure.args-append   --with-ruby-binary ${prefix}/bin/ruby3.3
    optionals-append    ruby
}

variant python description {Support for Python 3.12} {
    depends_lib-append  port:py312-cython
    optionals-append    python
    configure.python    ${prefix}/bin/python3.12
    configure.env-append    CYTHON=${prefix}/bin/cython-3.12
}

pre-configure {
    configure.args-append \
                        --with-optionals=[join ${optionals} ,] \
                        --without-plugins=[join ${disabled_plugins} ,]
}

default_variants +python
