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

name                gimp3-devel
set my_name         gimp3
conflicts           gimp2 gimp2-devel
version             2.99.rc1
revision            1
license             GPL-3+
categories          graphics
maintainers         {devans @dbevans} {mascguy @mascguy}

description         The GNU Image Manipulation Program
long_description    The GNU Image Manipulation Program (GIMP) is a powerful \
                    tool for the preparation and manipulation of digital images. \
                    The GIMP provides the user with a wide variety of image \
                    manipulation, painting, processing, and rendering tools. \
                    This is the GTK3 based development version leading \
                    to a future 3.0 release based on a recent snapshot of \
                    git master.
homepage            https://gimp.org/

# TODO: Once 3.0 officially released, eliminate these versions hacks
set branch          3.0
#set branch          [join [lrange [split ${version} .] 0 1] .]
master_sites        gimp:gimp/v${branch}/
dist_subdir         ${my_name}
distname            gimp-3.0.0-RC1
use_xz              yes

checksums           rmd160  18f197f32e38304dba69b2d5af62534174892852 \
                    sha256  b3d0b264c5e38e789faaf3417003397f3240014c59c7f417f9ca3bd39c5ffb66 \
                    size    28863948

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

depends_build-append \
                    port:appstream-glib \
                    port:gettext \
                    port:gtk-doc \
                    port:perl${perl5.major} \
                    path:bin/pkg-config:pkgconfig \
                    port:realpath

depends_lib-append \
                    port:aalib \
                    port:atk \
                    path:lib/pkgconfig/babl-0.1.pc:babl \
                    port:bzip2 \
                    port:cfitsio \
                    port:curl \
                    port:dbus-glib \
                    port:desktop-file-utils \
                    port:fontconfig \
                    port:freetype \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    path:lib/pkgconfig/gegl-0.4.pc:gegl \
                    port:gexiv2 \
                    port:ghostscript \
                    port:glib-networking \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:iso-codes \
                    port:lcms2 \
                    port:libheif \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libjxl \
                    port:libmng \
                    port:libmypaint \
                    port:libpng \
                    path:lib/pkgconfig/librsvg-2.0.pc:librsvg \
                    port:libwmf \
                    port:libxml2 \
                    port:libxslt \
                    port:mypaint-brushes1 \
                    port:openexr \
                    port:openjpeg \
                    path:lib/pkgconfig/poppler.pc:poppler \
                    port:tiff \
                    port:webp \
                    port:xdg-utils \
                    port:zlib

depends_run-append \
                    port:adwaita-icon-theme

# gcc-4.2 5493 and 5666.3_13: gimpcpuaccel.c:180: error: can't find a register in class 'BREG' while reloading 'asm'
# redefinition of typedef is invalid in C [-Wtypedef-redefinition] (#50329)
# as of version 2.10.0 requires a C++14 compatible compiler to configure

compiler.cxx_standard 2014
compiler.blacklist-append \
                    *gcc-3.* *gcc-4.* {clang < 700}

patchfiles-append   patch-etc-gimprc.in.diff
patchfiles-append   patch-quartz-32bit.diff
patchfiles-append   MYPAINT_BRUSHES_DIR.patch

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # avoid Cursor type conflict between X11 and Quickdraw
    # error: typedef redefinition with different types ('struct Cursor' vs 'XID' (aka 'unsigned long'))
    # not an issue on 10.7 and later
    patchfiles-append \
                    patch-x11-widgets-fix.diff
}

post-patch {
    # Fix python shebangs
    fs-traverse f ${worksrcpath} {
        if {[string match *.py ${f}]} {
            ui_info "patching python script: ${f}"
            reinplace -q "s|/usr/bin/python3$|${configure.python}|" ${f}
            reinplace -q "s|/usr/bin/env python2$|${configure.python}|" ${f}
            reinplace -q "s|/usr/bin/env python3$|${configure.python}|" ${f}
        }
    }
}

configure.perl      ${perl5.bin}

configure.env-append \
                    CC_FOR_BUILD=${configure.cc}

if {[vercmp $xcodeversion 4.3] < 0 && [string match "*macports*" ${configure.compiler}]} {
    # Xcode 4.2 fails with load commands in the newer toolchain
    depends_build-append \
                    port:cctools

    configure.env-append \
                    AR=${prefix}/bin/ar \
                    RANLIB=${prefix}/bin/ranlib
}

configure.args-append \
                    -Dalsa=disabled \
                    -Denable-console-bin=true \
                    -Dbug-report-url=https://guide.macports.org/#project.tickets \
                    -Dgi-docgen=disabled \
                    -Dg-ir-doc=false \
                    -Dgudev=disabled \
                    -Dilbm=disabled \
                    -Djavascript=disabled \
                    -Dlibbacktrace=false \
                    -Dlibunwind=false \
                    -Dlua=false \
                    -Dopenmp=disabled \
                    -Dwebkit-unmaintained=false

# keep empty GIMP font directory
# silences warning message on startup:
# GIMP-Message: Some fonts failed to load:
# - /opt/local/share/gimp/3.0/fonts/
destroot.keepdirs-append \
                    ${destroot}${prefix}/share/gimp/3.0/fonts

# requires python >= 3.6.0

proc py_setup {py_ver} {
    global env prefix frameworks_dir
    set py_ver_nodot [string map {. {}} ${py_ver}]

    set python_frameworks_dir \
                    ${frameworks_dir}/Python.framework/Versions/${py_ver}

    configure.python \
                    ${prefix}/bin/python${py_ver}

    configure.pkg_config_path-append \
                    ${python_frameworks_dir}/lib/pkgconfig

    configure.env-append \
                    PATH=${python_frameworks_dir}/bin:$env(PATH)
    build.env-append \
                    PATH=${python_frameworks_dir}/bin:$env(PATH)
    destroot.env-append \
                    PATH=${python_frameworks_dir}/bin:$env(PATH)

    depends_lib-append \
                    port:py${py_ver_nodot}-cairo \
                    port:py${py_ver_nodot}-gobject3
}

variant python39 description {Build with python plugin support using python 3.9} {
    py_setup 3.9
}

variant python310 description {Build with python plugin support using python 3.10} {
    py_setup 3.10
}

variant python311 description {Build with python plugin support using python 3.11} {
    py_setup 3.11
}

variant python312 description {Build with python plugin support using python 3.12} {
    py_setup 3.12
}

if {![variant_isset python39] && \
    ![variant_isset python310] && \
    ![variant_isset python311] && \
    ![variant_isset python312]} {
    default_variants-append +python312
}

# meson.build uses the GTK+ 3 backend to determine whether to enable X11.
variant x11 conflicts quartz {
    require_active_variants gtk3 x11

    depends_lib-append \
                    port:xorg-libXcursor \
                    port:xorg-libXmu \
                    port:xorg-libXext \
                    port:xorg-libXfixes \
                    port:xpm
}

variant quartz conflicts x11 {
    require_active_variants gtk3 quartz

    depends_lib-append \
                    port:gtk-osx-application-gtk3
}

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

post-activate {
    system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}

livecheck.type      none