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

github.setup        ebassi graphene 1.10.2
license             Permissive
categories          graphics gnome
maintainers         {devans @dbevans} openmaintainer
platforms           darwin
homepage            https://ebassi.github.io/${name}/

description         A thin layer of graphic data types

long_description    ${description}

checksums           rmd160  cd6d2ad814d126f0493ccc223ee1bdb4ad559571 \
                    sha256  a9109334a65e377150a832f298bdf098291621b6b1c377dd5e68e6cce3b544b4 \
                    size    174489

depends_build-append \
                    port:pkgconfig

depends_lib         path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:gobject-introspection

# __GNUC__ is unreliable indicator of SSE existence on macOS
# patchfiles-append   patch-meson.build.diff

# macosx_deployment_target-append 10.5

compiler.blacklist-append *clang*
compiler.whitelist macports-gcc-7

# platform darwin i386 {
#     # older compilers on Intel do not understand the new SSE compiler instructions
#     compiler.blacklist-append *gcc-3.* *gcc-4.* {clang < 212}
# }

# 10.5 or less has no special memalign but doesn't absolutely need it
# as the fallthrough to malloc returns aligned memory. Passes all tests.
if {${os.platform} eq "darwin" && ${os.major} < 11 } {
    patchfiles-append patch-graphene-leopard.diff
#     patchfiles-append patch-src-bench-matrix.diff
}

# attempt to fix build on 10.6 using gcc-4.2
# error: ‘for’ loop initial declaration used outside C99 mode
configure.cflags-append \
                    -std=c99

configure.args-append \
                    -Dtests=false \
                    -Dbenchmarks=false

if {${build_arch} eq "arm64"} {
    supported_archs     arm64
} elseif {${build_arch} eq "i386" || ${build_arch} eq "x86_64"} {
    supported_archs     i386 x86_64
} else {
    supported_archs     ppc ppc64
}

if {![info exists universal_possible]} {
    set universal_possible [expr {${os.universal_supported} && [llength ${configure.universal_archs}] >= 2}]
}
# gobject-introspection uses g-ir-scanner, which uses $CC from env
if {${universal_possible} && [variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_env(${arch})  "CC=${configure.cc} -arch ${arch}"
        lappend merger_destroot_env(${arch})  "CC=${configure.cc} -arch ${arch}"
    }
} else {
    build.env-append       "CC=${configure.cc} ${configure.cc_archflags}"
    destroot.env-append    "CC=${configure.cc} ${configure.cc_archflags}"
}
