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

name                libmovit
version             1.7.0

categories          multimedia
platforms           darwin linux
license             GPL-2+
maintainers         {gmail.com:rjvbertin @RJVB} openmaintainer

description         Modern Video Toolkit - open-source library for GPU-accelerated video filters
long_description    Movit is the Modern Video Toolkit. It aims to be a high-quality, \
                    high-performance, open-source library for GPU-accelerated video filters.

homepage            https://movit.sesse.net

master_sites        ${homepage}

distname            movit-${version}

checksums           rmd160  b625f7199d130f460eebec1b0dcb4a8c86a66039 \
                    sha256  23597b93ea53762d44df763ecc2b702308f76fc17382099e9385220081ce6610 \
                    size    606989
installs_libs       yes

patchfiles-append   patch-make_bundled_shaders.diff

depends_lib-append  path:share/pkgconfig/eigen3.pc:eigen3 \
                    port:fftw-3 \
                    port:libepoxy \
                    port:libpng

compiler.cxx_standard 2014

platform darwin {
    use_autoreconf  yes
    autoreconf.args -fvi

    depends_build-append \
                    port:pkgconfig
    depends_lib-append \
                    port:libsdl2 \
                    port:libsdl2_image \
                    port:mesa \
                    port:xorg-libX11

    post-extract {
        file delete -force ${worksrcpath}/libtool
    }

    patchfiles-append \
                    patch-no-features_h.diff \
                    patch-nolibrt.diff \
                    patch-notests.diff \
                    patch-opengl.diff
}

platform linux {
    configure.env-append \
                    PKG_CONFIG=${prefix}/bin/pkg-config
}

post-destroot {
    xinstall -d ${destroot}${prefix}/share/movit
    foreach frag [glob ${worksrcpath}/*.frag] {
        xinstall -m 644 ${frag} ${destroot}${prefix}/share/movit
    }
    foreach vert [glob ${worksrcpath}/*.vert] {
        xinstall -m 644 ${vert} ${destroot}${prefix}/share/movit
    }
    foreach check {vs-color.130.vert vs-color.150.vert color.130.frag color.150.frag} {
        if {![file exists ${destroot}${prefix}/share/movit/${check}]} {
            ui_warn "Installing missing ${check}"
            xinstall -m 644 ${filespath}/${check} ${destroot}${prefix}/share/movit
        }
    }
}

variant installdemo description "Install Demo Application" {
    post-patch {
        reinplace "s|\"\.\"|\"${prefix}/share/movit/\"|g" ${worksrcpath}/demo.cpp
        reinplace "s|\"blg_wheels_woman_1.jpg\"|\"/Users/Shared/blg_wheels_woman_1.jpg\"|g" ${worksrcpath}/demo.cpp
    }

    post-destroot {
        xinstall -m 755 ${worksrcpath}/.libs/demo ${destroot}${prefix}/bin/movit_demo
    }

    notes {
        ***** To run the movit_demo applications, obtain the image
        ***** "http://home.samfundet.no/~sesse/blg_wheels_woman_1.jpg"
        ***** or "https://digitalfilms.files.wordpress.com/2010/03/blg_wheels_woman_1.jpg"
        ***** and place as "/Users/Shared/blg_wheels_woman_1.jpg"
        ***** The demo program generates a number of working files,
        ***** so I suggest you run it from within a folder you can delete.
    }
}

livecheck.regex     "movit-(\\d+(?:\\.\\d+)*)${extract.suffix}"
