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

github.setup        anholt libepoxy 1.5.10
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            3
license             MIT permissive
categories          graphics
maintainers         nomaintainer

description         Epoxy is a library for handling OpenGL function \
                    pointer management for you

long_description    {*}${description}

checksums           rmd160  0c12937f3ab3645d4b1b96f29ffd2fb5ffc92712 \
                    sha256  b3e076c5bea209ffa7789cb460d76718be206ccad65a8c915757957c76318376 \
                    size    332119

depends_build       port:pkgconfig

patchfiles          patch-meson.diff \
                    patch-paths.diff \
                    patch-egl.diff \
                    patch-src-gen_dispatch.py.diff

# https://trac.macports.org/ticket/64468
platform darwin 8 {
    configure.cflags-append -DCGLReleasePixelFormat=CGLDestroyPixelFormat
    configure.cflags-append -DCGLReleaseContext=CGLDestroyContext
}

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

depends_build-append \
                    port:python${py_ver_nodot}

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/src/dispatch_common.c
    reinplace "s|@PYTHON3@|${prefix}/bin/python${py_ver}|g" \
        ${worksrcpath}/src/gen_dispatch.py
}

variant quartz conflicts x11 {
    configure.args-append   -Dx11=false
}

variant x11 conflicts quartz {
    depends_run-append      port:mesa
    # enable GLX support
    # without this any gtk3 +x11 app will fail on load as follows
    # dyld: Symbol not found: _epoxy_glXBindTexImageEXT
    #   Referenced from: /opt/local/lib/libgdk-3.0.dylib
    #   Expected in: /opt/local/lib/libepoxy.0.dylib
    #   in /opt/local/lib/libgdk-3.0.dylib
    configure.args-append   -Dglx=yes
}

variant egl description "Enable EGL" {
    depends_run-append      port:angle
    configure.args-append   -Degl=yes
}

if {![variant_isset quartz]} {
    default_variants +x11
}
if {![variant_isset x11]} {
    default_variants +quartz
}
if {![variant_isset quartz] && ![variant_isset x11]} {
    pre-configure {
        return -code error "Either +x11 or +quartz is required"
    }
}
