# -*- 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           compiler_blacklist_versions 1.0
PortGroup           cxx11 1.1
PortGroup           legacysupport 1.0

name                mpd

# note - versions 0.21.x and beyond require meson, and will require considerable
# rearrangement of the Portfile to support setting options in variants
# also, the audio output system changes to requiring 10.8+

version             0.20.21
revision            2
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          audio
maintainers         nomaintainer
description         Music Player Daemon
long_description    Music Player Daemon (MPD) allows remote access for playing music \
    (MP3, Ogg Vorbis, FLAC, AAC, Mod, and wave files) and managing \
    playlists. MPD is designed for integrating a computer into a stereo \
    system that provides control for music playback over a local network. \
    It also makes a great desktop music player, especially if you are a \
    console junkie, like frontend options, or restart X often.
homepage            https://www.musicpd.org/
platforms           darwin
master_sites        https://www.musicpd.org/download/${name}/${branch}/
license             GPL-2+ LGPL-2.1
use_xz              yes

checksums           rmd160  9999090c99e7a0b55ea2b3a5bd8e3e6d8ceb1b9a \
                    sha256  8322764dc265c20f05c8c8fdfdd578b0722e74626bef56fcd8eebfb01acc58dc \
                    size    800476

depends_build \
    port:pkgconfig \
    port:boost
depends_lib \
    port:audiofile \
    port:cdparanoia \
    port:curl \
    port:faad2 \
    port:flac \
    path:lib/pkgconfig/glib-2.0.pc:glib2 \
    port:libcue \
    port:libiconv \
    port:libid3tag \
    port:libogg \
    port:libvorbis \
    port:zlib \
    port:libao

#   revise Main.cxx with patch in future version 0.19.12 to allow compilation without inotify
configure.args \
    --mandir=${prefix}/share/man \
    --disable-ffmpeg \
    --disable-jack \
    --enable-ao \
    --disable-mpc

# build fails against fluidsynth @2.0.3
configure.args-append \
    --disable-fluidsynth

configure.cflags-append -I${prefix}/include

variant mpcdec description {Support for musepack via libmpcdec} {
    depends_lib-append  port:libmpcdec
    configure.args-delete --disable-mpc
}
variant ffmpeg description {Support for myriad formats via ffmpeg} {
    depends_lib-append	path:lib/libavcodec.dylib:ffmpeg
    configure.args-delete --disable-ffmpeg
}
variant mod description {Support for several formats of tracker/sequencer files via libmikmod} {
    depends_lib-append    port:libmikmod
    configure.args-append --enable-mod
}
variant modplug description {Support for several formats of tracker/sequencer files via libmodplug} {
    depends_lib-append    port:libmodplug
    configure.args-append --enable-modplug
}
variant mpg123 conflicts mad description {Use mpg123 rather than mad as mp3 deconding library} {
    depends_lib-append    port:mpg123
    configure.args-append --enable-mpg123 --disable-mad
}
variant mad conflicts mpg123 description (Use mad rather than mpg123 as mp3 decoding library} {
    depends_lib-append      port:libmad
    configure.args-append   --enable-mad --disable-mpg123
}
if {![variant_isset mpg123]} {
    default_variants    +mad
}

# Doesn't work with old GCC. Also blacklist old Clang, since it requires
# support for C++14.
compiler.blacklist-append   gcc-3.3 {*gcc-4.[0-5]} {clang < 602}

if {${os.platform} eq "darwin" && ${os.major} > 8} {
    set mpduser       _mpd
} else {
    set mpduser       mpd
}
# Create new user for mpd:
add_users ${mpduser} group=${mpduser} realname=Music\ Player\ Daemon

startupitem.create  yes
startupitem.start   "${prefix}/bin/mpd --no-daemon ${prefix}/etc/mpd.conf"
startupitem.stop    "${prefix}/bin/mpd --kill"
destroot.keepdirs   ${destroot}${prefix}/var/lib/mpd/music \
    ${destroot}${prefix}/var/lib/mpd/playlists \
    ${destroot}${prefix}/var/log/mpd
post-destroot {
    # ensure ${prefix}/var/[lib/mpd/[music,playlists],log/mpd] exist
    xinstall -m 755 -o ${mpduser} -g ${mpduser} -d \
    ${destroot}${prefix}/var/lib/mpd \
    ${destroot}${prefix}/var/lib/mpd/music \
    ${destroot}${prefix}/var/lib/mpd/playlists \
    ${destroot}${prefix}/var/log/mpd

    xinstall -m 644 ${filespath}/mpd.conf ${destroot}${prefix}/etc/mpd.conf.default
    reinplace "s|%%PREFIX%%|${prefix}|g" \
        ${destroot}${prefix}/etc/mpd.conf.default
    reinplace "s|%%MPDUSER%%|${mpduser}|g" \
        ${destroot}${prefix}/etc/mpd.conf.default
}
post-activate {
    if {![file exists ${prefix}/etc/mpd.conf]} {
        copy ${prefix}/etc/mpd.conf.default ${prefix}/etc/mpd.conf
    }
}

notes "A basic configuration file has been created for you.
To add music to mpd's database, create symbolic links in
${prefix}/var/lib/mpd/music using 'ln -s'.  For advanced
configuration, run \"man mpd.conf\" or refer to
${prefix}/share/doc/mpd/mpdconf.example for an example configuration file.

You may get \"Problems shmget'ing\" message when launching mpd.
In this case, you can increase the values of kern.sysv.shmmax and
kern.sysv.shmall in /etc/rc."

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "MPD (\\d+(?:\\.\\d+)*) released"