# -*- 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
PortGroup           github 1.0
PortGroup           active_variants 1.1
PortGroup           app 1.1

github.setup        virt-manager virt-manager 5.1.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            2
checksums           rmd160  bba3d38e3edc34594920ea3620b52c54c8ed8b24 \
                    sha256  ccfc44b6c1c0be8398beb687c675d9ea4ca1c721dfb67bd639209a7b0dec11b1 \
                    size    1489116

categories          gnome emulators
supported_archs     noarch
platforms           {darwin any}
maintainers         {makr @mohd-akram} openmaintainer
license             GPL-2+

homepage            https://virt-manager.org

description         Virtual Machine Manager

long_description \
    virt-manager is a graphical tool for managing virtual machines via \
    libvirt. Most usage is with QEMU/KVM virtual machines, but Xen and \
    libvirt LXC containers are well supported. Common operations for \
    any libvirt driver should work. \
    \n\nExpect limited functionality as macOS is not the usual \
    platform for this application\; its primary use on macOS is for \
    remote administration of Linux boxes.

master_sites        https://releases.pagure.org/virt-manager/

use_xz              yes

patchfiles-append   patch-no-kvm-warning.diff
patchfiles-append   patch-not-in-usr.diff

set py_ver          3.13
set py_ver_nodot    [string map {. {}} ${py_ver}]

# Note: 'gettext' only needed at build time. No need for a runtime dep on
# 'gettext-runtime', as this port utilizes Python's built-in 'gettext' support.
depends_build \
    port:gettext \
    path:lib/pkgconfig/glib-2.0.pc:glib2 \
    port:python${py_ver_nodot} \
    port:py${py_ver_nodot}-docutils

depends_lib \
    port:py${py_ver_nodot}-gobject3 \
    port:py${py_ver_nodot}-libvirt \
    port:py${py_ver_nodot}-libxml2 \
    port:py${py_ver_nodot}-requests \
    port:libvirt-glib \
    port:vte \
    port:gtk-vnc \
    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
    port:gtksourceview4 \
    port:spice-gtk \
    port:libosinfo

app.name            Virtual Machine Manager
app.icon            data/icons/256x256/apps/virt-manager.png
app.use_launch_script  yes

post-patch {
    reinplace "s|'python3'|'${prefix}/bin/python${py_ver}'|" \
        ${worksrcpath}/meson.build
    reinplace "s|/usr/bin/env python3|${prefix}/bin/python${py_ver}|" \
        ${worksrcpath}/scripts/make_bin_wrapper.py
    reinplace "s|'rst2man'|'rst2man-${py_ver}'|" ${worksrcpath}/man/meson.build
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/virtManager/createconn.py
}

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

notes "
To be able to run VMs locally via QEMU, first run:

sudo port install qemu libvirt +qemu
sudo port load dbus

In ${name}, add a connection and set the hypervisor to QEMU/KVM user session.
"

# stubs for checking dependencies in trace mode
#test.run             yes
#test.cmd             ${prefix}/bin/python${py_ver} virt-manager
#test.args
