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

# Upstream build source (until more official): https://github.com/slp/homebrew-krunkit/blob/main/Formula/virglrenderer.rb

PortSystem          1.0
PortGroup           gitlab 1.0
PortGroup           meson 1.0
PortGroup           active_variants 1.1

gitlab.instance     https://gitlab.freedesktop.org
gitlab.setup        slp virglrenderer 0.10.4d "" -krunkit
distname            ${gitlab.project}-${gitlab.version}${gitlab.tag_suffix}

revision            1

categories          graphics
license             MIT
maintainers         {@tsujp wz.ht:jc+macports} openmaintainer

description         VirGL virtual OpenGL renderer
long_description    Library that gives emulators the necessary tools to \
                    implement a virtio-gpu device, in particular one with 3D support.

homepage            https://gitlab.freedesktop.org/virgl/virglrenderer

# XXX: Unsure if this does support x86_64. Upstream only really deals with arm64 so use only that for now.
supported_archs     arm64

checksums           rmd160  9b997626bf09a7d3a61a8459ac132efa586237c1 \
                    sha256  33f6ee8fded051e63a098796d152020f917a1413e2f404cf187a4d038f312f7a \
                    size    702195

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

depends_build       port:pkgconfig \
                    port:vulkan-headers
depends_lib         port:libepoxy \
                    port:moltenvk

configure.args \
            -Dvenus=true \
            -Drender-server=false

# This port builds different depending on whether libepoxy is installed +x11 or
# +quartz. If libepoxy is +quartz and virglrenderer is installed from a binary,
# it fails to run because it expects an X11-specific symbol in libepoxy that
# isn't there.
#
# Add empty variants that do nothing but ensure this port is built with the
# same variants as libepoxy, and that a binary isn't used when libepoxy +quartz
# is installed.
variant x11 conflicts quartz {
    require_active_variants libepoxy x11 quartz
}

variant quartz conflicts x11 {
    require_active_variants libepoxy quartz x11
}

# If libepoxy is installed with +quartz, automatically default to using +quartz
# for this port. Otherwise, default to +x11.
if {![catch {set result [active_variants libepoxy quartz x11]}] && $result} {
    default_variants +quartz
} elseif {![variant_isset quartz]} {
    default_variants +x11
}

# TODO: Any tests?
# TODO: Currently this Portfile is only for the variant required for use in libkrun. There should (maybe) be a normal variant and then a +krunkit or +libkrun variant which is the equivalent of this. Look at that later, just get krunkit working for now.
