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

# strndup
legacysupport.newest_darwin_requires_legacy 10

github.setup        DeaDBeeF-Player deadbeef 1.10.2
revision            0
name                DeaDBeeF
categories          multimedia audio

maintainers         {@barracuda156 macos-powerpc.org:barracuda}
description         ${name} is a modular cross-platform audio player
long_description    {*}${description}. It plays a variety of audio formats, \
                    converts between them, lets you customize the UI in almost \
                    any way you want, and use many additional plugins \
                    which can extend it even more.\n\nNOTE: The macOS version \
                    has not been officially released, and has many unresolved \
                    issues and unimplemented features.
homepage            https://deadbeef.sourceforge.io
license             zlib LGPL-2.1 GPL-2
checksums           rmd160  4d250ef6d99f57c9f72854e4849a5c3476266994 \
                    sha256  6130e95d2f4528fec4682d8fa28e5d40ea71db23294d6837c1a1ea34e5a4ae86 \
                    size    15825417
github.tarball_from archive

fetch.type          git
post-fetch {
    system -W ${worksrcpath} "git submodule update --init"
}

patch.pre_args-replace  -p0 -p1

# FIXME: PortAudio builds but may not always work currently.
# ||PaMacCore (AUHAL)|| Error on line 1329: err=''nope'', msg=Audio Hardware: Illegal Operation
# ||PaMacCore (AUHAL)|| OpenStream @ 96000 returned: -9999: Unanticipated host error
# PortAudio plugin is not supported by upstream outside of Windows:
# https://github.com/DeaDBeeF-Player/deadbeef/issues/3197
# Some patches below are very experimental. However, the app is confirmed to work via CoreAudio.
# FIXME: with CoreAudio output device names are blank, though they can still be chosen.
# With PortAudio device names are listed fine.
# FIXME: possibly there are endianness issues on correct-endian platforms.

patchfiles-append   0001-deadbeef.h-add-missing-header-for-macOS.patch \
                    0002-streamer.c-fix-include.patch \
                    0003-moduleconf.h-unbreak-coreaudio.patch \
                    0004-junklib.c-unbreak-iconv.patch \
                    0005-configure.ac-fix-options.patch \
                    0006-Fix-install-paths.patch \
                    0007-Revert-breaking-76b2914-fixes-lastfm.patch \
                    0008-scriptable-revert-5ef32df.patch \
                    0009-Revert-breaking-650a48d-fixes-portaudio.patch \
                    0010-Actually-enable-building-PortAudio-plug-in.patch \
                    0011-gtkui-remove-blocks.patch \
                    0012-callbacks.c-do-not-use-gcc-pragmas.patch \
                    0013-viz.c-blockless-dispatch.patch \
                    0014-bswap.h-define-G_GINT64_CONSTANT.patch \
                    0015-coreaudio.c-define-kAudioDeviceTransportTypeAirPlay.patch \
                    0016-main.c-fix-Apple-macros.patch \
                    0017-trkproperties.c-blockless-dispatch.patch \
                    0018-viz.c-fix-syntax.patch \
                    0019-main.c-quick-hack-for-undefined-_deinit-functions.patch

use_autoreconf      yes
autoreconf.args     -fiv

depends_build-append \
                    port:gettext \
                    port:intltool \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:curl \
                    port:faad2 \
                    port:ffmpeg \
                    port:flac \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:jansson \
                    port:libcddb \
                    port:libcdio \
                    port:libgme \
                    port:libiconv \
                    port:libmad \
                    port:libogg \
                    port:libopus \
                    port:libsndfile \
                    port:libvorbis \
                    port:libzip \
                    port:mpg123 \
                    port:opusfile \
                    port:portaudio \
                    port:wavpack \
                    port:zlib

depends_run-append  port:desktop-file-utils

compiler.c_standard     2011
compiler.cxx_standard   2011

# Disable broken stuff:
# SID module fails to compile:
# event.cpp:45:1: error: use of undeclared identifier 'EventScheduler'
# event.cpp:93:46: error: unknown type name 'event_clock_t'
# Disable plug-ins using non-portable extensions.
configure.args-append \
                    --disable-alsa \
                    --disable-artwork \
                    --disable-ffap \
                    --disable-gtk2 \
                    --disable-hotkeys \
                    --disable-medialib \
                    --disable-notify \
                    --disable-nullout \
                    --disable-pipewire \
                    --disable-pulse \
                    --disable-rgscanner \
                    --disable-shellexecui \
                    --disable-sid \
                    --disable-src \
                    --enable-static \
                    --enable-aac \
                    --enable-alac \
                    --enable-coreaudio \
                    --enable-gtk3 \
                    --enable-portaudio \
                    --with-libiconv-prefix=${prefix}

# https://github.com/adplug/adplug/issues/247
# FIXME: enable when the module is updated.
platform powerpc {
    configure.args-append \
                    --disable-adplug
}

# These are likely unneeded:
configure.cppflags-append \
                    -DHAVE_COREAUDIO -DHAVE_PORTAUDIO

# dspconfig.c:95:66: error: passing argument 4 of 'scandir' from incompatible pointer type [-Wincompatible-pointer-types]
configure.cppflags-append \
                    -D_MACPORTS_LEGACY_COMPATIBLE_SCANDIR=1

# callbacks.c:219:9: error: 'callback' is deprecated: since deadbeef API 1.4 [-Werror=deprecated-declarations]
# widgets.c:2356:43: error: passing argument 2 of 'deadbeef->vis_waveform_listen' from incompatible pointer type [-Wincompatible-pointer-types]
# covermanager.c:115:55: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
# scriptable_dsp.c:301:20: error: returning 'int' from a function with return type 'char *' makes pointer from integer without a cast [-Wint-conversion]
configure.cflags-append \
                    -Wno-error=deprecated-declarations \
                    -Wno-error=int-conversion \
                    -Wno-error=int-to-pointer-cast \
                    -Wno-error=incompatible-pointer-types

if {[string match *clang* ${configure.compiler}]} {
# gtkui.c:147:16: error: redefinition of typedef 'gtkui_dispatch_func_t' is a C11 feature [-Werror,-Wtypedef-redefinition]
    configure.cflags-append \
                    -Wno-error=typedef-redefinition
}

build.args-append   V=1

post-activate {
    system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}
