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

name                gegl-devel
conflicts           gegl
set my_name         gegl
version             0.4.64
revision            0
epoch               0

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  b2c71c1a1d8b6fde481b6f9d10cd145b4ade2a1e \
                    sha256  0de1c9dd22c160d5e4bdfc388d292f03447cca6258541b9a12fed783d0cf7c60 \
                    size    6066976

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

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

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

depends_lib-append \
                    path:lib/pkgconfig/babl-0.1.pc:babl-devel \
                    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:libsdl2 \
                    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

# Fix define for HAVE_UNISTD_H, which otherwise fails for some older Clang versions
# See: https://trac.macports.org/ticket/71253
patchfiles-append   patch-meson-unistd.diff

# proposed fix for 32 bit builds
# https://trac.macports.org/ticket/58524
patchfiles-append   patch-gegl-32bit-host-statistics.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
    }
}

# cc1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117478
if { [string match *gcc* ${configure.compiler}] } {
    patchfiles-append patch-fix-objc-flags.diff
}

# 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 sdl1 description {Build with SDL v. 1} {
    depends_lib-replace \
                    port:libsdl2 port:libsdl
    configure.args-append \
                    -Dsdl2=disabled \
                    -Dsdl1=enabled
}

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
}

default_variants-append +vala

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