# -*- 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           cmake 1.1
PortGroup           active_variants 1.1

github.setup        mltframework mlt 7.24.0 v
github.tarball_from releases

epoch               4
categories          multimedia
maintainers         {dennedy.org:dan @ddennedy} {gmail.com:rjvbertin @RJVB} openmaintainer
license             GPL-2+
conflicts           mlt-legacy
description         Open source multimedia framework - core libraries
long_description    MLT is an open source multimedia framework, designed and developed for \
                    television broadcasting. It provides a toolkit for broadcasters, video \
                    editors, media players, transcoders, web streamers and many more types of \
                    applications. The functionality of the system is provided via an assortment \
                    of ready to use tools, xml authoring components, and an extendible plug-in \
                    based API. \
                    \
                    This package contains the files necessary for running applications that use \
                    the MLT multimedia framework.
homepage            https://www.mltframework.org/

checksums           rmd160  6efa1a3daf2ae3c2aa3a3714c43df49901f23895 \
                    sha256  8cde7c22a1a5395abe913976c2edafb498f81ed81a5f49dd0e6e2d86d68bcec0 \
                    size    1662552

variant qt6 conflicts qt5 description "build Qt6 version of ${name}" {
    PortGroup       qt6   1.0
    configure.args-replace  -DMOD_QT6=OFF -DMOD_QT6=ON
    qt6.depends_lib \
                    qtsvg \
                    qt5compat
}

variant qt5 conflicts qt6 description "build Qt5 version of ${name}" {
    PortGroup       qt5   1.0

    qt5.min_version 5.6

    qt5.depends_component \
                    qtsvg
    configure.args-replace  -DMOD_QT=OFF -DMOD_QT=ON
}

if {![variant_isset qt5] && ![variant_isset qt6]} {
    # https://doc-snapshots.qt.io/qt6-dev/macos.html#supported-versions
    if {${os.major} >= 21 || ${os.platform} ne "darwin"} {
        default_variants-append +qt6
    } else {
        default_variants-append +qt5
    }
}

compiler.cxx_standard      2011
# fatal error: 'stdatomic.h' file not found
compiler.blacklist-append  {clang < 700}

depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    path:bin/doxygen:doxygen

set ffmpeg_ver      6

depends_lib-append  port:frei0r-plugins \
                    port:ffmpeg${ffmpeg_ver} \
                    port:libsamplerate \
                    port:libsdl2 \
                    port:libvorbis \
                    port:sox \
                    port:libxml2 \
                    port:libexif \
                    port:fftw-3 \
                    port:libebur128 \
                    port:rubberband \
                    port:rtaudio \
                    port:libmovit \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    path:lib/pkgconfig/pango.pc:pango

configure.pkg_config_path-append \
                    ${prefix}/libexec/ffmpeg${ffmpeg_ver}/lib/pkgconfig

configure.args-append \
                    -DGPL=ON \
                    -DGPL3=OFF \
                    -DMOD_JACKRACK=OFF \
                    -DMOD_OPENCV=OFF \
                    -DMOD_SDL1=OFF \
                    -DMOD_QT=OFF \
                    -DMOD_QT6=OFF

if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
    configure.ldflags-append -stdlib=${configure.cxx_stdlib}
}

variant gpl3 description {enable GPLv3 components} {
    configure.args-replace  -DGPL3=OFF -DGPL3=ON
    license                 GPL-3+
}

# use an opencv variant to avoid opportunistic dependencies on this library
# the opencv dependency must match our choice of Qt version, which is
# another reason why opencv support is provided through a variant.
variant opencv conflicts qt6 description {enable OpenCV support} {
    set opencv_ver          4
    depends_lib-append      path:lib/opencv${opencv_ver}/libopencv_core.dylib:opencv${opencv_ver}
    configure.pkg_config_path-append \
                            ${prefix}/lib/opencv${opencv_ver}/pkgconfig
    configure.args-replace  -DMOD_OPENCV=OFF \
                            -DMOD_OPENCV=ON

    if {[variant_isset qt5]} {
        require_active_variants opencv qt5
    } elseif {[variant_isset qt6]} {
        # not supported yet
        require_active_variants opencv qt6
    }
}

# Allow building without SDL support, useful when used in dependents that themselves
# depend on SDL 1.2, to avoid (warnings about) runtime conflicts.
variant disable_sdl description {disable SDL support to avoid SDL vs. SDL2 conflicts} {
    configure.args-append   -DMOD_SDL2=OFF
    configure.cppflags-append \
                            -DMELT_NOSDL
    depends_lib-delete      port:libsdl2
}
