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

name                gegl
conflicts           gegl-devel
set my_name         gegl
version             0.4.46
revision            3
epoch               1

license             {GPL-3+ LGPL-3+}
categories          graphics
maintainers         {mascguy @mascguy} openmaintainer

description         GEGL is a graph based image processing framework.
long_description    GEGL is a graph based image processing framework offering image processing and \
                    compositing on large images. GEGL is suitable for projects ranging from small \
                    one-off projects to interactive applications.
homepage            http://gegl.org/

set branch          [join [lrange [split ${version} .] 0 1] .]
master_sites        gimp:${my_name}/${branch}/
dist_subdir         ${my_name}
distname            ${my_name}-${version}
use_xz              yes

checksums           rmd160  5a7ab6a581574694c5f61aeac98e15da3c6956ac \
                    sha256  d0b3b2481bc8774c5f3d0a487611910166d18eef823a859fb91e781ab7b1e892 \
                    size    5799248

set py_ver          3.11
set py_ver_nodot    [string map {. {}} ${py_ver}]
set py_framework    ${frameworks_dir}/Python.framework/Versions/${py_ver}

depends_build-append \
                    port:gettext \
                    port:pkgconfig \
                    port:python${py_ver_nodot}

depends_lib-append \
                    path:lib/pkgconfig/babl.pc:babl \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:exiv2 \
                    path:lib/libavcodec.dylib:ffmpeg \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    port:gettext-runtime \
                    port:gexiv2 \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    port:jasper \
                    port:json-glib \
                    port:lcms2 \
                    port:libraw \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    path:lib/pkgconfig/librsvg-2.0.pc:librsvg \
                    port:libspiro \
                    path:lib/libluajit-5.1.2.dylib:luajit \
                    port:openexr \
                    path:lib/pkgconfig/pango.pc:pango \
                    port:poly2tri-c \
                    path:lib/pkgconfig/poppler.pc:poppler \
                    port:py${py_ver_nodot}-gobject3 \
                    port:SuiteSparse_UMFPACK \
                    port:tiff \
                    port:webp

# libsdl2 requires minimum Xcode 10.7 SDK to build successfully, but builds on 10.6 x86.
# On earlier systems and all PPC use libsdl1 instead.
if {${os.platform} eq "darwin" && (${os.major} < 10 || ${configure.build_arch} in [list ppc ppc64])} {
    depends_lib-append  port:libsdl
    configure.args-append \
                    -Dsdl2=disabled \
                    -Dsdl1=enabled
} else {
    depends_lib-append \
                    port:libsdl2
}

# Upstream patch to eliminate need for Rust-based librsvg
# https://gitlab.gnome.org/GNOME/gegl/-/issues/333
patchfiles-append   patch-rsvg-no-rust.diff

# proposed fix for 32 bit builds
# https://trac.macports.org/ticket/58524
patchfiles-append   patch-gegl-32bit-host-statistics.diff

# https://trac.macports.org/ticket/66233
if {[string match *gcc* ${configure.compiler}]} {
    patchfiles-append patch-use-gcc.diff
}

platform darwin {
    if {${os.major} < 10 || (${os.major} == 10 && ${configure.build_arch} eq "ppc")} {
        patchfiles-append patch-gegl-opencl-fix-Leopard-and-less-only.diff
    }
}

post-patch {
    # https://trac.macports.org/ticket/35148
    if {${os.major} < 10} {
        reinplace "s|OpenGL/CGLDevice.h|OpenGL/CGLTypes.h|" \
                    ${worksrcpath}/gegl/opencl/cl_gl.h
    }
}

# needs C++14 C11
compiler.cxx_standard 2014
compiler.c_standard   2011

# version 0.4.14+ requires apple clang 700.0.72 (Xcode 7.0.0) to build new parallelization code
# ../gegl/gegl-parallel.h:134:29: error: expected expression '[] (gint     i,'
compiler.blacklist-append  {clang < 900}

if { [string match *clang* ${configure.compiler}] } {
    # Quiet warnings
    configure.cxxflags-append \
                    -Wno-deprecated-declarations \
                    -Wno-error=unknown-warning-option \
                    -Wno-unknown-warning-option
}

configure.pkg_config_path \
                    ${py_framework}/lib/pkgconfig

configure.args-append \
                    -Ddocs=false \
                    -Dgraphviz=disabled \
                    -Dgtk-doc=false \
                    -Dlensfun=disabled \
                    -Dlibv4l=disabled \
                    -Dlibv4l2=disabled \
                    -Dmaxflow=disabled \
                    -Dmrg=disabled \
                    -Dopenmp=disabled \
                    -Dvapigen=disabled

# at present, luajit does not build on PowerPC
platform darwin powerpc {
    depends_lib-delete \
                    path:lib/libluajit-5.1.2.dylib:luajit
    configure.args-append \
                    -Dlua=disabled
}

# 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 gtk_docs description {Build API docs using gtk-doc} {
    depends_build-append \
                    port:asciidoc \
                    port:gtk-doc
    configure.args-replace \
                    -Ddocs=false \
                    -Ddocs=true
    configure.args-replace \
                    -Dgtk-doc=false \
                    -Dgtk-doc=true
}

variant vala description {Enable build of vala extensions} {
    depends_lib-append \
                    path:bin/vala:vala
    configure.args-replace \
                    -Dvapigen=disabled \
                    -Dvapigen=enabled
}

variant workshop description {Enable build of workshop operations} {
    depends_lib-append \
                    port:lensfun
    configure.args-replace \
                    -Dlensfun=disabled \
                    -Dlensfun=enabled
    configure.args-append \
                    -Dworkshop=true
}

# Dummy variants used to identify this port's dependencies
variant x11 conflicts quartz {}
variant quartz conflicts x11 {}

if {![variant_isset quartz]} {
    default_variants +x11
}

# Vapigen is broken on PPC: https://gitlab.gnome.org/GNOME/vala/-/issues/1297
if {${os.arch} ne "powerpc"} {
    default_variants-append +vala
}

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