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

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

name                gstreamer1-gst-plugins-base
set my_name         gst-plugins-base
# please only commit stable updates (even numbered releases)
version             1.24.9
revision            0
description         This is gst-plugins, a set of plug-ins for GStreamer.
long_description    {*}${description}
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}/
distname            ${my_name}-${version}
use_xz              yes

checksums           rmd160  bc10b3e3741980bf0ff8bc837fc6dd502c13fef6 \
                    sha256  5bb3b946907d3ce04dd842b610c8111c2b0611351b25a1fa22af5efa897857cb \
                    size    2446392

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  path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    port:graphene \
                    port:gstreamer1 \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libopus \
                    port:libpng \
                    port:orc \
                    path:lib/pkgconfig/pango.pc:pango \
                    port:zlib

# Embedded systems are not our primary target, so disable OpenGL|ES support.
configure.args-append \
                    -Dalsa=disabled \
                    -Dcdparanoia=disabled \
                    -Dexamples=disabled \
                    -Dgl=disabled \
                    -Dgl-graphene=enabled \
                    -Dintrospection=enabled \
                    -Dlibvisual=disabled \
                    -Dnls=disabled \
                    -Dogg=disabled \
                    -Dqt5=disabled \
                    -Dtheora=disabled \
                    -Dvorbis=disabled \
                    -Dx11=disabled \
                    -Dxshm=disabled \
                    -Dxvideo=disabled

# as of orc 0.4.34 compilation with c11 standard is required to prevent slugish behavior
# see https://gitlab.freedesktop.org/gstreamer/orc/-/issues/47
compiler.c_standard 2011
configure.cflags-append \
                    -std=c11
# orc requires stdatomic.h
compiler.blacklist-append {clang < 700}

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/meson-pkg-config-file-fixup.py \
        ${worksrcpath}/scripts/update-orc-dist-files.py \
        ${worksrcpath}/gst-libs/gst/gl/gl_mkenum.py
}

variant x11 {
    depends_lib-append \
                    port:mesa \
                    port:xorg-libX11 \
                    port:xorg-libXext \
                    port:xorg-libXv
    configure.args-replace \
                    -Dx11=disabled \
                    -Dx11=enabled \
                    -Dxshm=disabled \
                    -Dxshm=enabled \
                    -Dxvideo=disabled \
                    -Dxvideo=enabled
    configure.args-append \
                    -Dgl_winsys=x11
}

variant ogg description {Build with support for libogg, libvorbis, libtheora} {
    depends_lib-append \
                    port:libogg \
                    port:libtheora \
                    port:libvorbis
    configure.args-replace \
                    -Dogg=disabled \
                    -Dogg=enabled \
                    -Dtheora=disabled \
                    -Dtheora=enabled \
                    -Dvorbis=disabled \
                    -Dvorbis=enabled
}

variant cdparanoia description {Enable (currently broken) cdparanoia plugin} {
    depends_lib-append \
                    port:cdparanoia
    configure.args-replace \
                    -Dcdparanoia=disabled \
                    -Dcdparanoia=enabled
}

# Prefer X11 implementation.
default_variants    +ogg +x11

# Cocoa-GL
# Only enable on OS X 10.9 or later, if the x11 variant is not enabled.
# Requires ARC (automatic reference counting, a clang feature enabled
# by -fobjc-arc), which was not supported when targeting the legacy fragile
# Objective-C runtime used on 32-bit x86 until Xcode 7.3 / clang 3.9
# (https://llvm.org/viewvc/llvm-project?view=revision&revision=250955).
# If building universal or for i386 then ensure that a sufficiently recent
# version of clang is used, since the Xcode clang may be too old.
platform macosx {
    if {![variant_isset x11] && ${os.major} >= 13} {
        if {(${universal_possible} && [variant_isset universal]) || ${build_arch} eq "i386"} {
            compiler.blacklist-append *gcc* {macports-clang-3.[0-8]} {clang < 703}
        }
        # Use mesa headers if found else use gl-headers to ensure we don't conflict with gl-headers & mesa later
        depends_build-append \
                    path:include/GL/glext.h:gl-headers

        configure.args-replace \
                    -Dgl=disabled \
                    -Dgl=enabled
        configure.args-append \
                    -Dgl_winsys=cocoa
    }

    # graphene does not support +universal for arm64 & x86_64
    # https://trac.macports.org/ticket/66888
    if {${universal_possible} && [variant_isset universal] && "arm64" in ${configure.universal_archs}} {
        depends_lib-delete \
                    port:graphene
        configure.args-replace \
                    -Dgl-graphene=enabled \
                    -Dgl-graphene=disabled
    }
}

test.run            yes
test.target         check

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