# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           meson 1.0
PortGroup           yelp 1.0

name                totem
version             3.38.2
revision            1
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          gnome
# also has an exception allowing use of non-GPL-compatible plugins
license             GPL-2+
maintainers         {devans @dbevans} openmaintainer
description         Official movie player of the GNOME desktop environment
long_description    Totem is based on GStreamer. It features a \
                    playlist, a full-screen mode, seek and volume controls, \
                    as well as keyboard navigation. It comes with added \
                    functionality such as: \
                    \n    * Video thumbnailer for the file manager \
                    \n    * Nautilus properties tab \
                    \n    * Webcam utility (in development)

homepage            https://wiki.gnome.org/Apps/Videos
platforms           darwin
master_sites        gnome:sources/${name}/${branch}/

use_xz              yes

checksums           rmd160  d15c029a7155358b3bfec0a0f49a41a4c827631e \
                    sha256  fce562e2b26cbcfc0c678538dcc81f9dc15ce60d5a89ee4358907bf634304c40 \
                    size    2190700

depends_build-append \
                    port:pkgconfig \
                    port:appstream-glib \
                    port:gettext \
                    port:gtk-doc \
                    port:itstool

depends_lib         path:lib/pkgconfig/cairo.pc:cairo \
                    port:clutter \
                    port:clutter-gst3 \
                    port:clutter-gtk \
                    port:dbus \
                    port:desktop-file-utils \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    port:gettext-runtime \
                    port:gnome-desktop \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    port:grilo \
                    port:grilo-plugins \
                    port:gsettings-desktop-schemas \
                    port:gstreamer1 \
                    port:gstreamer1-gst-plugins-base \
                    port:gstreamer1-gst-plugins-good \
                    port:gstreamer1-gst-plugins-bad \
                    port:gstreamer1-gst-libav \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:libpeas \
                    port:shared-mime-info \
                    port:totem-pl-parser

depends_run         port:adwaita-icon-theme

patchfiles          patch-meson-0.61.0.diff

configure.args      -Denable-easy-codec-installation=yes \
                    -Dwith-plugins=auto \
                    -Denable-python=no \
                    -Denable-gtk-doc=true

variant python38 conflicts python39 python310 description {Use python 3.8} {
    depends_build-append      port:py38-pylint
    depends_lib-append        port:py38-gobject3
    configure.python          ${prefix}/bin/python3.8
    set python_framework      ${frameworks_dir}/Python.framework/Versions/3.8
    configure.env             PATH=${python_framework}/bin:$env(PATH)
    configure.pkg_config_path ${python_framework}/lib/pkgconfig
    configure.args-replace    -Denable-python=no -Denable-python=yes
}

variant python39 conflicts python38 python310 description {Use python 3.9} {
    depends_build-append      port:py39-pylint
    depends_lib-append        port:py39-gobject3
    configure.python          ${prefix}/bin/python3.9
    set python_framework      ${frameworks_dir}/Python.framework/Versions/3.9
    configure.env             PATH=${python_framework}/bin:$env(PATH)
    configure.pkg_config_path ${python_framework}/lib/pkgconfig
    configure.args-replace    -Denable-python=no -Denable-python=yes
}

variant python310 conflicts python38 python39 description {Use python 3.10} {
    depends_build-append      port:py310-pylint
    depends_lib-append        port:py310-gobject3
    configure.python          ${prefix}/bin/python3.10
    set python_framework      ${frameworks_dir}/Python.framework/Versions/3.10
    configure.env             PATH=${python_framework}/bin:$env(PATH)
    configure.pkg_config_path ${python_framework}/lib/pkgconfig
    configure.args-replace    -Denable-python=no -Denable-python=yes
}

if {![variant_isset python38] && \
    ![variant_isset python39] && \
    ![variant_isset python310]} {
    default_variants    +python310
}

# uses g-ir-scanner, which uses $CC from env
if {${universal_possible} && [variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_env(${arch})  "CC=${configure.cc} -arch ${arch}"
        lappend merger_destroot_env(${arch})  "CC=${configure.cc} -arch ${arch}"
    }
} else {
    build.env-append       "CC=${configure.cc} ${configure.cc_archflags}"
    destroot.env-append    "CC=${configure.cc} ${configure.cc_archflags}"
}

test.run    yes

# libpeas expects plugin modules with .so extensions
# make .so symlink for each plugin module built as .dylib
post-destroot {
    set plugindir lib/totem/plugins

    lappend pluginlibs \
       im-status/libtotem-im-status \
       screenshot/libscreenshot \
       autoload-subtitles/libautoload-subtitles \
       screensaver/libscreensaver \
       vimeo/libvimeo \
       apple-trailers/libapple-trailers \
       properties/libmovie-properties \
       skipto/libskipto \
       open-directory/libopen-directory \
       rotation/librotation \
       save-file/libsave-file \
       media-player-keys/libmedia-player-keys \
       variable-rate/libvariable-rate \
       recent/librecent

    foreach pluginlib ${pluginlibs} {
        ln -s ${prefix}/${plugindir}/${pluginlib}.dylib ${destroot}${prefix}/${plugindir}/${pluginlib}.so
    }
}

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
    system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
    system "${prefix}/bin/glib-compile-schemas ${prefix}/share/glib-2.0/schemas"
}

livecheck.type      gnome