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

# Tiger: add missing PTHREAD_RWLOCK_INITIALIZER definition for pthread.h
PortGroup           legacysupport 1.0

github.setup        cmus cmus 2.13.0 v
github.tarball_from archive
revision            0
categories          audio
maintainers         {@Traace hotmail.de:xxtraacexx} \
                    openmaintainer
license             GPL-2+
description         ncurses based music player
long_description    cmus is a small and fast text mode music player for Linux \
                    and many other UNIX like operating systems.
homepage            https://cmus.github.io/

checksums           rmd160  6026f7f35cb22f92ef2afb0c7fddb1aeeccde9fc \
                    sha256  7be478c476f0a9915cdefbf6aade825a40cd202a8ca6b5149399025d3c7fc09b \
                    size    352175

depends_build       path:bin/pkg-config:pkgconfig
depends_lib         port:libao \
                    port:libmad \
                    port:libogg \
                    port:libvorbis \
                    port:libiconv \
                    port:ncurses

universal_variant   no
build.args          V=2

# ccache: invalid option -- L
configure.ccache    no

# checking for C11 (with atomics support)... no
# this is a C11 feature; looking for compatible compilers, we find these references
# https://stackoverflow.com/questions/26440606/xcode-and-c11-stdatomic-h
# https://stackoverflow.com/questions/20326604/stdatomic-h-in-gcc-4-8
# indicates compatible compilers are Xcode > Xcode 7, clang > 3.7, and gcc > 4.8

compiler.c_standard 2011
compiler.blacklist-append \
                    *gcc-3.* *gcc-4.*
compiler.blacklist-append \
                    { clang < 700 } macports-clang-3.3 macports-clang-3.4

platform darwin i386 {
    # clang-5.0 tested, and also likely installed on these systems
    compiler.fallback-append \
                    macports-clang-5.0 macports-clang-6.0 macports-clang-7.0
}
platform darwin powerpc {
    compiler.fallback-append \
                    macports-gcc-6 macports-gcc-7 macports-gcc-5
}

configure.pre_args
configure.args      prefix=${prefix} CONFIG_FLAC=n CONFIG_MIKMOD=n \
                    CONFIG_MODPLUG=n CONFIG_MPC=n CONFIG_FFMPEG=n \
                    CONFIG_AAC=n CONFIG_MP4=n CONFIG_MAD=y CONFIG_VORBIS=y \
                    CONFIG_WAVPACK=n CONFIG_OPUS=n CONFIG_CUE=n \
                    CONFIG_CDIO=n CONFIG_CDDB=n CONFIG_DISCID=n \
                    CONFIG_AO=y CONFIG_PULSE=n CONFIG_OSS=n \
                    CONFIG_JACK=n CONFIG_COREAUDIO=y CONFIG_SAMPLERATE=n \
                    CONFIG_AAUDIO=n CONFIG_ALSA=n CONFIG_ARTS=n \
                    CONFIG_MPRIS=n CONFIG_ROAR=n CONFIG_SNDIO=n \
                    CONFIG_SUN=n CONFIG_VTX=n CONFIG_WAVEOUT=n \
                    HOSTCC="${configure.cc}" \
                    HOST_CFLAGS="${configure.cflags}" \
                    HOST_LDFLAGS="${configure.ldflags}" \
                    DEBUG=0

# darwin < 12 cannot build coreaudio output
if { ${os.platform} eq "darwin" && ${os.major} < 12 } {
    configure.args-replace \
                    CONFIG_COREAUDIO=y CONFIG_COREAUDIO=n
}

# Tiger: add missing non-POSIX SIGWINCH definition for Darwin signal.h
platform darwin 8 {
    patchfiles-append \
                    patch-cmus-uicurses-sigwinch-tiger.diff
}

# at present, this library seems to be needed when building with gcc on PPC only
platform darwin powerpc {
    configure.ldflags-append \
                    -latomic
}

default_variants    +aac +cue +ffmpeg +flac +mikmod +mpc +wavpack

variant aac  description {Support aac files}   {
    depends_lib-append \
                    port:faad2 port:mp4v2
    configure.args-replace \
                    CONFIG_AAC=n CONFIG_AAC=y \
                    CONFIG_MP4=n CONFIG_MP4=y
}

variant flac  description {Support flac files} {
    depends_lib-append \
                    port:flac
    configure.args-replace \
                    CONFIG_FLAC=n CONFIG_FLAC=y
}

variant mikmod  description {Support mod files} {
    depends_lib-append \
                    port:libmikmod
    configure.args-replace \
                    CONFIG_MIKMOD=n CONFIG_MIKMOD=y
}

variant mpc  description {Support musepack files} {
    depends_lib-append \
                    port:libmpcdec
    configure.args-replace \
                    CONFIG_MPC=n CONFIG_MPC=y
}

variant wavpack  description {Support WavPack files} {
    depends_lib-append \
                    port:wavpack
    configure.args-replace \
                    CONFIG_WAVPACK=n CONFIG_WAVPACK=y
}

variant opus  description {Support Opus files} {
    depends_lib-append \
                    port:opusfile
    configure.args-replace \
                    CONFIG_OPUS=n CONFIG_OPUS=y
}

variant ffmpeg  description {Support ffmpeg} {
    depends_lib-append \
                    path:lib/libavcodec.dylib:ffmpeg
    configure.args-replace \
                    CONFIG_FFMPEG=n CONFIG_FFMPEG=y
}

variant cdda  description {Support audio CD playback} {
    depends_lib-append \
                    port:libcdio \
                    port:libcdio-paranoia \
                    port:libcddb \
                    port:libdiscid
    configure.args-replace \
                    CONFIG_CDIO=n CONFIG_CDIO=y \
                    CONFIG_CDDB=n CONFIG_CDDB=y \
                    CONFIG_DISCID=n CONFIG_DISCID=y
}

variant cue  description {Support CUE sheets} {
    configure.args-replace \
                    CONFIG_CUE=n CONFIG_CUE=y
}

variant pulseaudio  description {Support native PulseAudio output} {
    depends_lib-append \
                    port:pulseaudio
    configure.args-replace \
                    CONFIG_PULSE=n CONFIG_PULSE=y
}

# at present, jack is building on 10.7+
variant jack  description {Support native JACK output} {
    depends_lib-append \
                    port:jack port:libsamplerate
    configure.args-replace \
                    CONFIG_JACK=n CONFIG_JACK=y \
                    CONFIG_SAMPLERATE=n CONFIG_SAMPLERATE=y
}

variant debug  description {Build debug binaries} {
    configure.args-replace \
                    DEBUG=0 DEBUG=2
}
