# -*- 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           conflicts_build 1.0
PortGroup           github 1.0
PortGroup           muniversal 1.0
PortGroup           qt4 1.0

name                mlt-legacy
github.setup        mltframework mlt 6.26.1 v
revision            0
categories          multimedia
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             GPL-2+
conflicts           mlt
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  e1181cd38733c89bf7e8be386e15b61fa9700deb \
                    sha256  8a484bbbf51f33e25312757531f3ad2ce20607149d20fcfcb40a3c1e60b20b4e \
                    size    1366022
github.tarball_from releases

patchfiles          patch-enforce-cxx14.diff \
                    patch-filter_rbpitch.cpp.diff \
                    patch-numeric_limits.diff \
                    patch-RtAudio.cpp.diff

if {[string match *gcc* ${configure.compiler}]} {
    # cc1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
    patchfiles-append \
                    patch-sdl2-x11.diff
}

# eigen3-devel needs C++14
compiler.cxx_standard      2014
configure.cxxflags-append  -std=c++14
# fatal error: 'stdatomic.h' file not found
compiler.blacklist-append  {clang < 700}

depends_build-append \
                    path:bin/doxygen:doxygen \
                    port:git

depends_lib-append  port:atk \
                    path:share/pkgconfig/eigen3.pc:eigen3 \
                    path:lib/libavcodec.dylib:ffmpeg \
                    port:fftw-3 \
                    port:frei0r-plugins \
                    port:libebur128 \
                    port:libexif \
                    port:libsamplerate \
                    port:libsdl2 \
                    port:libvorbis \
                    port:libxml2 \
                    port:rubberband \
                    port:sox

configure.args-append \
                    --disable-gtk2 \
                    --disable-jackrack \
                    --disable-mmx \
                    --disable-opencv \
                    --disable-sdl \
                    --disable-swfdec \
                    --enable-gpl \
                    --without-kde

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

pre-configure {
    configure.env-append \
                    QTDIR=${qt_dir}
    # NB: qt-includedir can and should be set to ${qt_includes_dir},
    # not ${qt_includes_dir}/Qt !!
    configure.args-append \
                    --qt-libdir=${qt_frameworks_dir} \
                    --qt-includedir=${qt_includes_dir}

    configure.cflags-append  "-I${qt_includes_dir}"
}

platform darwin 10 {
    if {${configure.build_arch} eq "x86_64"} {
        configure.args-delete --disable-mmx
    }
}

configure.cflags-append     "-I${prefix}/include"
configure.ldflags-delete    "-L${prefix}/lib"

# make sure the build system actually sees our settings by amending the toplevel config.mak.
post-configure {
    set config.mak [open ${worksrcpath}/config.mak "a"]
    puts ${config.mak} "CC=${configure.cc}"
    puts ${config.mak} "CXX=${configure.cxx}"
    puts ${config.mak} "CFLAGS+=${configure.cflags} ${configure.cppflags}"
    puts ${config.mak} "CXXFLAGS+=${configure.cxxflags} ${configure.cppflags}"
    puts ${config.mak} "LDLAGS+=${configure.ldflags}"
    close ${config.mak}
}

build.args-append           CC="${configure.cc}" CXX="${configure.cxx}" CPP="${configure.cpp}"

if {${universal_possible} && [variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_env(${arch})   "CFLAGS=${configure.cflags} -arch ${arch}"
        lappend merger_build_env(${arch})   "CXXFLAGS=${configure.cxxflags} -arch ${arch}"
        lappend merger_build_env(${arch})   "LDFLAGS=${configure.ldflags} -L${worksrcpath}-${arch}/src/framework -L${prefix}/lib -arch ${arch}"
    }
} else {
    build.env-append                        "CFLAGS=${configure.cflags} [get_canonical_archflags cc]"
    build.env-append                        "CXXFLAGS=${configure.cxxflags} [get_canonical_archflags cxx]"
    build.env-append                        "LDFLAGS=${configure.ldflags} -L${worksrcpath}/src/framework -L${prefix}/lib [get_canonical_archflags ld]"
}

variant gtk2 description {include the gtk2 module (for additional image and text producers)} {
    configure.args-delete   --disable-gtk2
    depends_lib-append      path:lib/pkgconfig/gtk+-2.0.pc:gtk2
    require_active_variants gtk2 x11
}

variant gpl3 description {enable GPLv3 components} {
    configure.args-append   --enable-gpl3
    license                 GPL-3+
}

# Notice that rtaudio module requires rtaudio 5.x and fails to build with 6.x:
# consumer_rtaudio.cpp:150:43: error: 'struct RtAudio::DeviceInfo' has no member named 'probed'
# consumer_rtaudio.cpp:195:25: error: 'RtAudioError' does not name a type; did you mean 'RtAudioErrorType'?
# If rtaudio port gets updated, this will break. So rather use the internal one.
conflicts_build             rtaudio

# 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   --disable-sdl2
    configure.cppflags-append \
                            -DMELT_NOSDL
    depends_lib-delete      port:libsdl2
}
