# -*- 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           legacysupport 1.1
PortGroup           meson 1.0

# darwin <= 10: define O_CLOEXEC
# darwin <= 12: auto-include <sys/socket.h> in <net/if.h>
legacysupport.newest_darwin_requires_legacy 12

# Remember to update libvirt and py-libvirt at the same time.
name                libvirt
version             11.8.0
revision            1
checksums           rmd160  798d45f3a961467456e19d0c3e40789a355080d8 \
                    sha256  f7882fe65302bbcf804b573e0128c4fc6bfc52c9c3f44852a04de2391d858e34 \
                    size    10093332

categories          sysutils
license             LGPL-2.1+
maintainers         {ryandesign @ryandesign} openmaintainer

description         Libvirt - The Virtualization API

long_description    A toolkit to interact with the virtualization \
                    capabilities of modern hypervisors.

homepage            https://libvirt.org
master_sites        https://download.libvirt.org
use_xz              yes

set python_branch   3.13
set python_version  [string map {. {}} ${python_branch}]

depends_build-append \
                    port:gettext \
                    port:gmake \
                    port:gsed \
                    port:grep \
                    port:bash-completion \
                    path:bin/pkg-config:pkgconfig \
                    port:python${python_version} \
                    port:py${python_version}-docutils \
                    port:perl5

depends_lib         port:curl \
                    port:gettext-runtime \
                    port:json-c \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gnutls.pc:gnutls \
                    port:libiconv \
                    port:libxml2 \
                    port:readline \
                    port:zlib

patchfiles          uint64_t.patch

# error: 'struct stat' has no member named 'st_birthtimespec'; did you mean 'st_atimespec'?
patchfiles-append   patch-st_birthtimespec.diff

# Undefined symbols: "___gcc_personality_v0", "__Unwind_Resume"
if {${os.platform} eq "darwin" && ${os.major} < 11} {
    patchfiles-append \
                    patch-fix-linking.diff
}

# error: You need at least XCode Clang v10.0 to compile libvirt
# error: You need at least Clang v6.0 to compile libvirt
# error: You need at least GCC v7.4.0 to compile libvirt
compiler.blacklist-append \
                    apple-gcc* {clang < 1000} \
                    gcc-3.3 *gcc-4.* *gcc-5.* *gcc-6.* \
                    macports-clang-3.* macports-clang-5.0

# libvirt build scripts require python 3.x
configure.python    ${prefix}/bin/python${python_branch}
configure.perl      ${prefix}/bin/perl5

# Some build scripts run "python3"
configure.env       PATH=${frameworks_dir}/Python.framework/Versions/${python_branch}/bin:$env(PATH)
build.env           {*}${configure.env}

configure.args      -Dapparmor=disabled \
                    -Dattr=disabled \
                    -Daudit=disabled \
                    -Dbash_completion=enabled \
                    -Dbash_completion_dir=${prefix}/share/bash-completion/completions \
                    -Dblkid=disabled \
                    -Dcapng=disabled \
                    -Dcurl=enabled \
                    -Ddriver_bhyve=disabled \
                    -Ddriver_esx=enabled \
                    -Ddriver_hyperv=disabled \
                    -Ddriver_libvirtd=enabled \
                    -Ddriver_libxl=disabled \
                    -Ddriver_lxc=disabled \
                    -Ddriver_network=disabled \
                    -Ddriver_openvz=disabled \
                    -Ddriver_qemu=disabled \
                    -Ddriver_remote=enabled \
                    -Ddriver_secrets=enabled \
                    -Ddriver_test=enabled \
                    -Ddriver_vbox=enabled \
                    -Ddriver_vmware=enabled \
                    -Ddriver_vz=disabled \
                    -Ddtrace=disabled \
                    -Dfuse=disabled \
                    -Dglusterfs=disabled \
                    -Dinit_script=none \
                    -Djson_c=enabled \
                    -Dlibpcap=disabled \
                    -Dlibssh=disabled \
                    -Dlibssh2=disabled \
                    -Dnetcf=disabled \
                    -Dnumactl=disabled \
                    -Dopenwsman=disabled \
                    -Dpm_utils=disabled \
                    -Dpolkit=disabled \
                    -Dreadline=enabled \
                    -Dsanlock=disabled \
                    -Dsasl=disabled \
                    -Dselinux=disabled \
                    -Dsysctl_config=disabled \
                    -Dudev=disabled \
                    -Dwireshark_dissector=disabled

variant fuse description {FUSE support} {
    depends_lib-append      port:osxfuse
    configure.args-replace  -Dfuse=disabled -Dfuse=enabled
}

variant libssh2 description {Enable the libssh2 transport} {
    depends_lib-append      port:libssh2
    configure.args-replace  -Dlibssh2=disabled -Dlibssh2=enabled
}

variant sasl description {Use Cyrus SASL for authentication} {
    depends_lib-append      port:cyrus-sasl2
    configure.args-replace  -Dsasl=disabled -Dsasl=enabled
}

variant qemu description {Enable the QEMU virtualization driver} {
    depends_run-append      port:qemu
    configure.args-replace  -Ddriver_qemu=disabled -Ddriver_qemu=enabled
}

notes "
    The default socket path for the libvirt client is ${prefix}/var/run/libvirt/libvirt-sock,\
    which might cause problems when you want to attach to a remote libvirtd instance.\
    In this case, remember to also specify the socket path for the remote side, which is\
    usually /var/run/libvirt/libvirt-sock. For example to connect to a remote host with virsh:
      $ virsh -c qemu+ssh://user@host/system?socket=/var/run/libvirt/libvirt-sock
"

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     ${name}-(\[0-9.\]+)\\.tar
