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

# TODO: Improve atomics by using libkern/OSAtomics.h
#       https://bugs.freedesktop.org/show_bug.cgi?id=67795

PortSystem          1.0
PortGroup           active_variants 1.1
PortGroup           compiler_blacklist_versions 1.0

name                pulseaudio
version             12.99.3
revision            0
license             LGPL-2.1+ MIT BSD
categories          audio
maintainers         {ionic @Ionic} openmaintainer
platforms           darwin
description         A sound server for POSIX OSes

long_description    PulseAudio is a sound server for POSIX OSes, meaning that it is a proxy \
                    for your sound applications. It allows you to do advanced operations \
                    on your sound data as it passes between your application and your hardware. \
                    Things like transferring the audio to a different machine, changing the \
                    sample format or channel count and mixing several sounds into one are \
                    easily achieved using a sound server.

homepage            https://www.freedesktop.org/wiki/Software/PulseAudio/
master_sites        https://www.freedesktop.org/software/${name}/releases/

use_xz              yes

checksums           rmd160  44e6f70aab8cb514208016fc7ec90996a21837d8 \
                    sha256  5d93bccbfedc2510bd1766a0e66a5f0c3da8064d3464248c8c9b979f36a6612b \
                    size    1942500

set perl_branch     5.28

depends_build       port:pkgconfig \
                    port:intltool \
                    port:autoconf \
                    port:automake \
                    port:libtool \
                    port:gettext \
                    port:p${perl_branch}-xml-parser

depends_lib         port:libiconv \
                    port:libsndfile \
                    port:libtool \
                    port:gdbm \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:dbus \
                    port:fftw-3-single \
                    path:lib/libspeexdsp.dylib:speexDSP \
                    port:orc \
                    port:soxr

# configure falls back to libatomic_ops as last resort
# if no linux kernel support and inline asm snippet fails to build
# likely to fail on Leopard and older
# https://trac.macports.org/ticket/42052

platform darwin {
    if {${os.major} < 10} {
        depends_lib-append  port:libatomic_ops
    }
}

# DO NOT USE! Maintainer-only helper. DO NOT USE!
#configure.cflags-append -g3 -ggdb3 -gdwarf-4 -O0
#configure.cxxflags-append -g3 -ggdb3 -gdwarf-4 -O0

# Some patches make PulseAudio startup correctly.
# Will hopefully be merged upstream soon.
# All work has or will be sent upstream.
# C.f. https://bugs.freedesktop.org/show_bug.cgi?id=62987
# and posts on the mailing list.
patchfiles          patch-man-Makefile.am.diff \
                    patch-src_modules_macosx_module_coreaudio_device.c-respect-PA_NAME_MAX.diff \
                    patch-src_daemon_default.pa.in-skip-consolekit-and-systemdlogin.diff

# reconfigure using upstream autogen.sh for intltool 0.51 compatibility
post-patch {
    xinstall -m 755 ${filespath}/autogen.sh ${worksrcpath}
    reinplace "s|@@MP_PERL@@|${prefix}/bin/perl${perl_branch}|" ${worksrcpath}/man/Makefile.am
}

# Blacklist compilers that do not support C11.
compiler.blacklist  {*gcc-3*} {*gcc-4.[0-8]} {clang < 300} cc

configure.cmd       ./autogen.sh

configure.args      --with-mac-version-min=$macosx_deployment_target \
                    --with-caps \
                    --with-soxr \
                    --with-speex \
                    --disable-silent-rules \
                    --disable-tests \
                    --disable-gtk3 \
                    --disable-x11 \
                    --disable-oss-output \
                    --disable-alsa \
                    --disable-esound \
                    --disable-solaris \
                    --disable-waveout \
                    --disable-avahi \
                    --disable-gconf \
                    --disable-gsettings \
                    --disable-jack \
                    --disable-asyncns \
                    --disable-tcpwrap \
                    --disable-lirc \
                    --disable-bluez4 \
                    --disable-bluez5 \
                    --disable-udev \
                    --disable-hal-compat \
                    --disable-openssl \
                    --disable-systemd-daemon \
                    --disable-systemd-login \
                    --disable-systemd-journal \
                    --enable-neon-opt=no \
                    --enable-orc \
                    --enable-adrian-aec

if {"${configure.sdkroot}" eq ""} {
    configure.args-append --with-mac-sysroot=/
} else {
    configure.args-append --with-mac-sysroot=${configure.sdkroot}
}

test.run            no
test.target         check

add_users           pulse group=pulse realname=Pulse\ Audio

variant x11 conflicts minimal {
    configure.args-replace  --disable-x11 \
                            --enable-x11
    depends_lib-append      port:xorg-libX11 \
                            port:xorg-libxcb \
                            port:xorg-libice \
                            port:xorg-libsm \
                            port:xorg-libXtst
}

variant jack conflicts minimal description {Enable Jack support} {
    configure.args-replace  --disable-jack \
                            --enable-jack
    depends_lib-append      port:jack
}

variant _internal_valgrind description {DO NOT USE! Enable valgrind support. DO NOT USE!} {
    depends_lib-append      path:bin/valgrind:valgrind-devel
    patchfiles-append       patch-src_daemon_caps.c-enable-root.diff
}

variant esound description {Enable optional esound emulation support.} {
    configure.args-replace  --disable-esound \
                            --enable-esound
}

variant minimal conflicts jack conflicts x11 description {Builds a minimal version. Do not use if unsure. Please build this ONLY in trace mode.} {
    depends_lib-delete      port:libiconv \
                            port:gdbm \
                            path:lib/pkgconfig/glib-2.0.pc:glib2 \
                            port:dbus \
                            port:fftw-3-single \
                            port:orc \
                            port:soxr

    configure.args-replace  --with-soxr \
                            --without-soxr

    configure.args-replace  --enable-orc \
                            --disable-orc

    configure.args-append   --with-database=simple \
                            --disable-glib2 \
                            --disable-dbus \
                            --without-fftw \
                            --disable-nls

    require_active_variants libsndfile no_external_libs
}

if {![variant_isset minimal]} {
    default_variants    +x11
}

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