# -*- 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           active_variants 1.1
PortGroup           compiler_blacklist_versions 1.0
PortGroup           meson 1.0

# https://bugzilla.gnome.org/show_bug.cgi?id=636134
PortGroup           muniversal 1.0

name                gstreamer1-gst-plugins-good
set my_name         gst-plugins-good
# please only commit stable updates (even numbered releases)
version             1.24.9
revision            2
description         A set of good-quality plug-ins for GStreamer under GStreamer's preferred \
                    license, LGPL.
long_description    GStreamer Good Plug-ins is a set of plug-ins that GStreamer's developers \
                    consider to have good quality code, correct functionality, and their \
                    preferred license (LGPL for the plug-in code, LGPL or LGPL-compatible \
                    for the supporting library).
maintainers         nomaintainer
categories          gnome
license             LGPL-2+
homepage            https://gstreamer.freedesktop.org/modules/${my_name}.html
master_sites        https://gstreamer.freedesktop.org/src/${my_name}/
use_xz              yes
distname            ${my_name}-${version}

checksums           rmd160  7af56d76f910acf27e42d230b9ccfd3e4e2b7c2c \
                    sha256  897de50bff337e3ca2f86f1eaa28e0828d83024156162a50c4ea0af86e29799f \
                    size    2929348

set py_ver          3.12
set py_ver_nodot    [string map {. {}} ${py_ver}]
set python.bin      ${prefix}/bin/python${py_ver}

depends_build-append \
                    port:gettext \
                    path:bin/pkg-config:pkgconfig \
                    port:python${py_ver_nodot}

depends_lib-append  port:aalib \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:flac \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    port:gettext-runtime \
                    port:gstreamer1-gst-plugins-base \
                    port:lame \
                    path:lib/libcaca.dylib:libcaca \
                    port:libdv \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libpng \
                    port:libshout2 \
                    path:lib/pkgconfig/libsoup-3.0.pc:libsoup \
                    path:lib/pkgconfig/vpx.pc:libvpx \
                    port:libxml2 \
                    port:mpg123 \
                    port:nettle \
                    port:orc \
                    path:lib/libspeex.dylib:speex \
                    port:taglib \
                    port:twolame \
                    port:wavpack

platform darwin {
    if {${os.major} < 11} {
        patchfiles-append \
                    snowleopard-memmem.patch
    }

    if {${os.major} < 16} {
        patchfiles-append \
                    patch-gstosxaudiodeviceprovider.c.diff
    }
}

patchfiles-append   patch-coreaudio.diff

post-patch {
    reinplace "s|/usr/bin/env python3|${python.bin}|" \
        ${worksrcpath}/scripts/extract-release-date-from-doap-file.py \
        ${worksrcpath}/scripts/dist-translations.py \
        ${worksrcpath}/scripts/update-orc-dist-files.py \
        ${worksrcpath}/tests/examples/rpicamsrc/dynamicprops.py
}

configure.args-append   -Dexamples=disabled \
                        -Dqt5=disabled \
                        -Dgtk3=disabled

configure.env-append    "HAVE_CXX=yes"

# Fix libtool errors:
# libtool: error: specify a tag with '--tag'
compiler.blacklist-append \
                        {clang < 900}
# SSE register return with SSE disabled
# <rdar://problem/9694837> - Fixed in Xcode 4.2 (clang 211.10.1)
# blacklist compilers that don't support C11 typedef redefinition
# gstflvmux.h:73: error: redefinition of typedef ‘GstFlvMuxPadClass’
compiler.c_standard 2011

platform darwin {
    if {${os.major} < 10} {
        # gstosxcoreaudio.c:419:28: error: use of undeclared identifier 'kLinearPCMFormatFlagsSampleFractionMask'
        configure.args-append \
                            -Dosxaudio=disabled
    }
    if {${os.major} < 10 || (${os.major} == 10 && ${configure.build_arch} eq "ppc")} {
        # osx_video requires darwin 10 or later, does not build for ppc
        configure.args-append \
                            -Dosxvideo=disabled
    }
}

variant gtk3 description {Enable GTK3 windowing elements} {
    depends_lib-append      path:lib/pkgconfig/gtk+-3.0.pc:gtk3
    depends_build-append    port:gtk-doc
    configure.args-replace  -Dgtk3=disabled \
                            -Dgtk3=enabled
}

variant jack description {Enable Jack plugin} {
    depends_lib-append      port:jack
    configure.args-append   -Djack=enabled
}

variant pulseaudio description {Enable PulseAudio plugin} {
    depends_lib-append      port:pulseaudio
    configure.args-append   -Dpulse=enabled
}

variant x11 {
    depends_lib-append      port:xorg-libX11 \
                            port:xorg-libXfixes \
                            port:xorg-libXdamage \
                            port:xorg-libXext
    configure.args-append   -Dximagesrc=enabled \
                            -Dximagesrc-xshm=enabled \
                            -Dximagesrc-xdamage=enabled \
                            -Dximagesrc-xfixes=enabled
}

# Requires gstreamer-gl
variant qt description {Enable Qt5 MAC windowing elements } {
    PortGroup               qt5 1.0

    qt5.depends_component   qtdeclarative \
                            qtmacextras

    configure.args-replace  -Dqt5=disabled \
                            -Dqt5=enabled

    # avoid:
    # ${prefix}/libexec/qt5/include/QtCore/qcompilerdetection.h:562:6: error: Qt requires a C++11 compiler and yours does not seem to be that.
    compiler.cxx_standard   2011
    configure.cxxflags-append -std=c++11
}

default_variants            +pulseaudio +x11 +gtk3

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