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

name                babl
conflicts           babl-devel
set my_name         babl
version             0.1.110
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            http://gegl.org/babl
master_sites        gimp:${my_name}/${branch}/
dist_subdir         ${my_name}
distname            ${my_name}-${version}
use_xz              yes

checksums           rmd160  3f5bf199d2969c266c36d0b7fbf1493d075c9965 \
                    sha256  bf47be7540d6275389f66431ef03064df5376315e243d0bab448c6aa713f5743 \
                    size    319256

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

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

depends_build-append \
                    path:bin/pkg-config:pkgconfig

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

patchfiles-append   patch-babl-linker-fix-darwin.diff

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

# In 0.1.12, i386 fails to compile with SL's gcc-4.2:
#    babl-cpuaccel.c:169: error: ‘asm’ operand has impossible constraints
compiler.blacklist-append *gcc-3.* *gcc-4.*

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

# 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+)+)"
