# -*- 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.12.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            2
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  3d9f9c27371371bef3c3e9e9a3a514c7bdde268c \
                    sha256  5c04f14cc57e864b51b0ba92aca0f96f4fef72ce250c90bd91e96a1f4e490fd3 \
                    size    348740

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.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 \
                    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-delete CONFIG_AAC=n CONFIG_MP4=n
    configure.args-append CONFIG_AAC=y CONFIG_MP4=y
}

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

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

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

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

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

variant ffmpeg  description {Support ffmpeg} {
    set ffmpeg_ver        7
    depends_lib-append    path:libexec/ffmpeg${ffmpeg_ver}/lib/libavcodec.dylib:ffmpeg${ffmpeg_ver}
    configure.pkg_config_path-prepend \
                          ${prefix}/libexec/ffmpeg${ffmpeg_ver}/lib/pkgconfig
    configure.args-delete CONFIG_FFMPEG=n
    configure.args-append CONFIG_FFMPEG=y
    # Without these build process links ffmpeg v4 if present
    # With these present the build env line above is redundant, but I'm keeping it anyways
    configure.cflags-prepend \
                          -I${prefix}/libexec/ffmpeg${ffmpeg_ver}/include
    configure.ldflags-prepend \
                          -L${prefix}/libexec/ffmpeg${ffmpeg_ver}/lib
}

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

variant cue  description {Support CUE sheets} {
    depends_lib-append    port:libcue
    configure.args-delete CONFIG_CUE=n
    configure.args-append CONFIG_CUE=y
}

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

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

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