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

github.setup        ebassi graphene 1.10.8
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            1
license             Permissive
categories          graphics gnome
maintainers         {devans @dbevans} openmaintainer
homepage            https://ebassi.github.io/${name}/

description         A thin layer of graphic data types

long_description    {*}${description}

checksums           rmd160  2b9dca9f0e0926b5037961843f7874701144c6cb \
                    sha256  d3838b6d5eabc723e34bd5202f008417ef38431fde734c429c83ad8f34d49d3c \
                    size    178553

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

depends_build       port:pkgconfig \
                    port:python${python_version}

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

patchfiles-append   use-our-python3.patch

post-patch {
    reinplace -W ${worksrcpath} "s|@@PYTHON3_BIN@@|${prefix}/bin/python${python_branch}|" \
            src/meson.build
}

# 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.
# Patch is needed for Rosetta as well.
platform darwin {
    if {${os.major} < 10 || (${os.major} == 10 && ${configure.build_arch} eq "ppc")} {
        patchfiles-append patch-graphene-leopard.diff
    }
}

# graphene forces off SSE2 if not building for x86_64. This is based on a linux
# issue with memory alignment. We allow SSE2 for i386 on Darwin, and this also
# fixes universal building https://trac.macports.org/ticket/65710
patchfiles-append   patch-graphene-allow-sse2-on-32bit.diff

compiler.c_standard 1999

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

test.run            yes
test.target         test

variant tests description "support running tests" {
    depends_test-append     port:mutest
    configure.args-replace  -Dtests=false -Dtests=true \
                            -Dinstalled_tests=false -Dinstalled_tests=true
}

# the original motivation for this somewhat unusual pattern of supported_archs being set
# was here: https://github.com/macports/macports-ports/pull/2095#issuecomment-401559487

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

# 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}"
}
