# -*- 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               conflicts_build 1.0
PortGroup               muniversal 1.1
PortGroup               legacysupport 1.0
PortGroup               compiler_blacklist_versions 1.0

# timespec_get() and others
legacysupport.newest_darwin_requires_legacy 17

name                    mesa
conflicts               gl-headers
epoch                   1
version                 22.1.7
revision                2
checksums               rmd160  9c570f7e00527c662509ab6fb264caf2c780a4ea \
                        sha256  da838eb2cf11d0e08d0e9944f6bd4d96987fdc59ea2856f8c70a31a82b355d89 \
                        size    16109944

categories              x11 graphics
maintainers             {jeremyhu @jeremyhu} openmaintainer
license                 MIT
description             Mesa 3D Graphics Library
long_description        Mesa is an open-source implementation of the OpenGL specification, \
                        a system for rendering interactive 3D graphics.

homepage                https://www.mesa3d.org
master_sites            https://archive.mesa3d.org
use_xz                  yes

# Disable unexpected download of subprojects
meson.wrap_mode         nodownload

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

depends_build-append    port:pkgconfig \
                        port:flex \
                        port:bison \
                        port:py${py_ver_nodot}-mako \
                        port:python${py_ver_nodot} \
                        port:xorg-xorgproto

depends_lib-append      port:expat \
                        port:xorg-libxcb \
                        port:xorg-libX11 \
                        port:xorg-libXext \
                        port:xorg-libXdamage \
                        port:zlib \
                        port:zstd

patchfiles              patch-meson-spec-python.diff \
                        patch-driver_extensions.diff \
                        patch-pre-10.8-scandir.diff

# MP ticket 66269
# the sizes of int and GLint are different on 10.4 PPC, at least
# not sure how many systems this might affect, but all systems on buildbot were OK
# restrict to Tiger for now, therefore
platform darwin 8 {
    patchfiles-append       patch-mesa-apple-cgi-int-differences.diff
}

post-patch {
    reinplace "s|@@python3@@|${prefix}/bin/python${py_ver}|g" meson.build
}

compiler.c_standard     2011
compiler.cxx_standard   2014
# Build issues on mac OS 10.10
# ../mesa-22.1.7/src/util/compiler.h:90:7: error: builtin feature check macro requires a parenthesized identifier
# #elif HAS_CLANG_FALLTHROUGH
compiler.blacklist-append  {clang < 800}

configure.args          -Dc_std=c11 \
                        -Dosmesa=true \
                        -Dllvm=disabled \
                        -Dbuild-tests=false

platform darwin {
    if {${os.major} < 9} {
          # Xplugin.h is missing on Tiger
          configure.cppflags-append -I${filespath}/include
    }

    if {${os.major} < 10} {
          # avoid use of libunwind, which is not in the System on < darwin 10
          # see https://trac.macports.org/ticket/65934
          configure.args-append  -Dlibunwind=disabled
    }

    pre-configure {
        if {${os.major} < 11} {
            # https://trac.macports.org/ticket/25677
            if { ![file exists /usr/lib/libXplugin.dylib] } {
                ui_error "Detected a problem with your development environment.  Please work around it by executing:"
                ui_error "sudo ln -s libXplugin.1.dylib /usr/lib/libXplugin.dylib"
                return -code error "missing libXplugin.dylib"
            }
        }
    }
}

if {[string match *gcc* ${configure.compiler}]} {
    configure.ldflags-append -latomic

    # https://github.com/macports/macports-ports/pull/16260#issuecomment-1268741658
    configure.cxxflags-append -fpermissive
}

variant tests description "build tests" {
    # mesa uses it's own internal gtest version and fails with newer
    conflicts_build-append gtest
    configure.args-replace -Dbuild-tests=false -Dbuild-tests=true
}

test.run                yes
test.cmd                meson
test.target             test

livecheck.type          regex
livecheck.url           ${homepage}
livecheck.regex         {relnotes/([0-9.]+)\.html}
