# -*- 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-bad
set my_name         gst-plugins-bad
# please only commit stable updates (even numbered releases)
version             1.24.5
revision            0
description         A set of plug-ins for GStreamer that need more quality.
long_description    GStreamer Bad Plug-ins is a set of plug-ins that aren't up to par compared \
                    to the rest. They might be close to being good quality, but they're missing \
                    something - be it a good code review, some documentation, a set of tests, \
                    a real live maintainer, or some actual wide use.
license             GPL LGPL
maintainers         nomaintainer
categories          gnome
homepage            https://gstreamer.freedesktop.org/modules/${my_name}.html
master_sites        https://gstreamer.freedesktop.org/src/${my_name}/
distname            ${my_name}-${version}
use_xz              yes

checksums           rmd160  bd447ac7145ebd3e75f9e8a1c8e0ca5efd3d9a64 \
                    sha256  3029bfd7265314d609dc8eab503675a344ea46e8274fd73ab34566c8442dc847 \
                    size    7061664

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:gtk-doc \
                    path:bin/pkg-config:pkgconfig \
                    port:python${py_ver_nodot}

depends_lib-append  port:aom \
                    port:curl \
                    port:faad2 \
                    port:fluidsynth \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    port:gstreamer1-gst-plugins-base \
                    port:json-glib \
                    port:lcms2 \
                    path:lib/pkgconfig/libass.pc:libass \
                    port:libdca \
                    port:libde265 \
                    port:libdvdnav \
                    port:libdvdread \
                    port:libexif \
                    port:libGLU \
                    port:libgsm \
                    port:libmms \
                    port:libmodplug \
                    port:libmpcdec \
                    port:libnice \
                    path:lib/pkgconfig/librsvg-2.0.pc:librsvg \
                    port:libssh2 \
                    port:mesa \
                    port:neon \
                    port:nettle \
                    port:openal-soft \
                    port:openexr \
                    port:openjpeg \
                    port:orc \
                    port:rtmpdump \
                    port:soundtouch \
                    port:spandsp-devel \
                    port:tiff \
                    port:webp \
                    port:x265

patchfiles          modplug.patch \
                    libressl.patch \
                    no_pqueue_size.patch

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/check/media/download-media \
        ${worksrcpath}/gst-libs/gst/vulkan/vulkan_mkenum.py \
        ${worksrcpath}/ext/vulkan/shaders/bin2array.py
}

# could depend on tons for multimedia stuff +variants
# the following ports are available but don't configure
# and/or build correctly
#
# port:mjpegtools (mpeg2enc mplex build fails) need to disable mpeg2enc mplex explicitly in case mjpegtools is installed
# port:faac has a restrictive license, disable faac plugin by default
# port:libfdk-aac has a restrictive license, disable fdkaac plugin by default
# path:lib/opencv3/libopencv_core.dylib:opencv3 (opencv plugin fails to configure with opencv 3.0.0+, can't find opencv2/bgsegm.hpp, now opencv2/video/background_segm.hpp)
# plugin opus is now contained in gstreamer1-gst-plugins-base, disable this version
# plugin ipcpipeline fails to build

# fatal error: 'stdatomic.h' file not found
compiler.blacklist-append {clang < 700}
# requires support for C11 (redefinition of typedef ‘GstTestHTTPSrc’ at elements/test_http_src.c:101)
compiler.c_standard         2011
# OpenExr requires C++11
compiler.cxx_standard       2011

configure.args-append \
                    -Dapplemedia=disabled \
                    -Dexamples=disabled \
                    -Dfaac=disabled \
                    -Dfdkaac=disabled \
                    -Dopencv=disabled \
                    -Dsctp=disabled \
                    -Dsrtp=disabled \
                    -Dvulkan=disabled

configure.cppflags-append   -L${prefix}/lib
configure.cflags-append     -std=c11 -funroll-loops -fstrict-aliasing
configure.cxxflags-append   -std=gnu++11
configure.env-append        "HAVE_CXX=yes"

variant faac description {Enable faac AAC plugin} {
    depends_lib-append      port:faac
    configure.args-replace  -Dfaac=disabled \
                            -Dfaac=enabled
    notes-append "Use of the +faac variant may affect licensing due to the restrictive license of port faac itself."
}

variant fdkaac description {Enable fdkaac AAC plugin} {
    depends_lib-append      port:libfdk-aac
    configure.args-replace  -Dfdkaac=disabled \
                            -Dfdkaac=enabled
    notes-append "Use of the +fdkaac variant may affect licensing due to the restrictive license of port libfdk-aac itself."
}

variant gpl description {Enable glp-licenced plugins} {
    configure.args-append   -Dgpl=enabled
}

# Window system is provided by gstreamer1-gst-plugins-base, so sync up.
variant x11 {
    require_active_variants port:gstreamer1-gst-plugins-base x11
    configure.args-append   -Dx11=enabled
}

default_variants    +x11

# plugin applemedia (Apple video) now only builds on darwin 18 and later
platform macosx {
    if {![variant_isset x11] && ${os.major} >= 18} {
        # Apple_Media requires CGL, which can only be provided on newer platforms and without X11 enabled.
        require_active_variants port:gstreamer1-gst-plugins-base {} x11
        configure.args-replace  -Dapplemedia=disabled \
                                -Dapplemedia=enabled
    }
}

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