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

set my_name         babl
name                ${my_name}
conflicts           ${my_name}-devel
version             0.1.128
revision            0
license             LGPL-3+
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          graphics
maintainers         {mascguy @mascguy} openmaintainer

description         Babl is a library for dynamically handling pixel formats and managing \
                    conversions between them.
long_description    ${description}

homepage            https://gegl.org/babl
master_sites        gimp:${my_name}/${branch}/
dist_subdir         ${my_name}
distname            ${my_name}-${version}
use_xz              yes

checksums           rmd160  f1bbd3b94924a318be5aad44e01e16463fed1a70 \
                    sha256  e676507b421d414d49db8627415dc1eadbd787536baa7d6fe94a1f1971cbe73e \
                    size    332976

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

# Backport:
patchfiles-append   b12c5e85a69f05637dcda84acfbd43bc832801e3.patch
# The script is still broken, however, so disable for now:
patchfiles-append   patch-meson.build.diff

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]
configure.python    ${prefix}/bin/python${py_ver}
meson.native.binaries \
                    python3=${configure.python}

depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    port:python${py_ver_nodot}

depends_lib-append  port:lcms2 \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    path:bin/vala:vala

# require C11 (typedef redefinition)
# babl-icc.c:1031:25: error: redefinition of typedef 'UTF8' is invalid in C
compiler.c_standard 2011

# babl-0.1.72 default compiler on macOS 10.10 (clang-700.1.81) has trouble with extension sse-half
# babl-0.1.72/extensions/sse-half.c:49:24: error: invalid conversion between vector type '__v4sf' (vector of 4 'float' values) and integer type 'int' of different size
#       __v4sf out_val = (__v4sf)_mm_cvtph_ps(in_val);
#                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compiler.blacklist-append {clang < 900}

configure.args-append \
                    -Dwith-docs=false

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

variant docs description "Generate optional docs" {
    depends_build-append   port:w3m \
                           path:lib/pkgconfig/librsvg-2.0.pc:librsvg

    configure.args-delete  -Dwith-docs=false
    configure.args-append  -Dwith-docs=true

    post-destroot {
        xinstall -m 0755 -d ${destroot}${prefix}/share/doc/${name}
        xinstall -m 0644 -W ${build.dir} README \
            ${destroot}${prefix}/share/doc/${name}
    }
}

livecheck.type      regex
livecheck.url       http://download.gimp.org/pub/${my_name}/${branch}/
livecheck.regex     "${my_name}-(\\d+(?:\\.\\d+)+)"
