# -*- 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           cxx11 1.1

name                gimp2-devel
conflicts           gimp2 gimp3-devel
set git_name        gimp
set git_commit      a48d9178e8a0cec6f828f70a27755e4fd0812980
set git_date        20180521
version             2.10.3-${git_date}
revision            1
license             GPL-3+
categories          graphics
maintainers         {devans @dbevans}
platforms           darwin

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 maintenance version leading to a future 2.10.4 release \
                    based on a recent snapshot of upstream branch gimp-2-10.

homepage            http://www.gimp.org/
master_sites        https://git.gnome.org/browse/${git_name}/snapshot/

distname            ${git_name}-${git_commit}

checksums           rmd160  2b01d11f09cd68899ee938a51eaaf0a2731ff826 \
                    sha256  221e7012a565bd0c26e232c776956d645caa7ccb263e7a314230db8e78c707b2 \
                    size    90783650

set perl_version    5.26

depends_build       port:pkgconfig \
                    port:appstream-glib \
                    port:autoconf \
                    port:automake \
                    port:libtool \
                    port:intltool \
                    port:gtk-doc \
                    port:perl${perl_version}

depends_lib         port:desktop-file-utils \
                    port:iso-codes \
                    port:babl-devel \
                    port:gegl-devel \
                    port:atk \
                    port:gdk-pixbuf2 \
                    port:glib-networking \
                    port:gtk2 \
                    port:gvfs \
                    port:fontconfig \
                    port:freetype \
                    port:tiff \
                    port:jpeg \
                    port:zlib \
                    port:bzip2 \
                    port:ghostscript \
                    port:libpng \
                    port:libmng \
                    port:openexr \
                    port:gexiv2 \
                    port:aalib \
                    port:xpm \
                    port:librsvg \
                    port:poppler \
                    port:curl \
                    port:libwmf \
                    port:jasper \
                    path:lib/pkgconfig/libmypaint.pc:libmypaint \
                    port:mypaint-brushes \
                    port:lcms2 \
                    port:dbus-glib \
                    port:libxml2 \
                    port:libxslt \
                    port:xdg-utils \
                    port:xorg-libXcursor \
                    port:xorg-libXmu \
                    port:xorg-libXext \
                    port:xorg-libXfixes

# libgimpwidgets/gimpwidgetsmarshal.h can be referenced by a parallel
# build before it is created
use_parallel_build  no

# 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.blacklist *gcc-3.* *gcc-4.* {clang < 700}

patchfiles          patch-configure.ac.diff \
                    patch-etc-gimprc.in.diff \
                    patch-app-widgets-gimpcriticaldialog.c.diff

pre-configure {
    if {[file exists ${prefix}/lib/gtk-2.0/include/gdkconfig.h]} {
        set gtk_not_quartz [catch {exec grep -q GDK_WINDOWING_QUARTZ ${prefix}/lib/gtk-2.0/include/gdkconfig.h}]
        set gtk_not_x11 [catch {exec grep -q GDK_WINDOWING_X11 ${prefix}/lib/gtk-2.0/include/gdkconfig.h}]
        if {[variant_isset quartz] && ${gtk_not_quartz}} {
            error "+quartz variant selected, but gtk2+x11 is installed. Install gtk2+quartz."
        } elseif {![variant_isset quartz] && ${gtk_not_x11}} {
            error "+quartz variant is not selected, but gtk2+quartz is installed. Install gtk2+x11."
        }
    } else {
            error "Cannot find gdkconfig.h"
    }
}

configure.perl      ${prefix}/bin/perl${perl_version}

configure.cmd       ./autogen.sh

configure.args      --build=${configure.build_arch}-apple-${os.platform}${os.version} \
                    --enable-mp \
                    --enable-bundled-mypaint-brushes \
                    --with-pdbgen \
                    --with-x \
                    --x-includes=${prefix}/include \
                    --x-libraries=${prefix}/lib \
                    --disable-silent-rules \
                    --disable-python \
                    --without-alsa \
                    --without-gudev \
                    --without-webkit \
                    ac_cv_path_INTLTOOL_PERL=${configure.perl}
configure.env       CC_FOR_BUILD=${configure.cc}

variant python27 description {Build with python plugin support using python 2.7} {
    configure.args-delete     --disable-python
    configure.python          ${prefix}/bin/python2.7
    depends_lib-append        port:py27-pygtk
    set python_framework      ${frameworks_dir}/Python.framework/Versions/2.7
    configure.pkg_config_path ${python_framework}/lib/pkgconfig
    configure.env-append      PATH=${python_framework}/bin:$env(PATH)
}


variant remote description {Enable building of obsolete gimp-remote helper app} {
    configure.args-append   --enable-gimp-remote
}

variant debug description {Enable debugging} {
    configure.args-append  --enable-debug
}

variant quartz {
    depends_lib-delete    port:xorg-libXcursor \
                          port:xorg-libXmu \
                          port:xorg-libXext \
                          port:xorg-libXfixes \
                          port:xpm
    depends_lib-append    port:gtk-osx-application-gtk2
    configure.args-delete --with-x \
                          --x-includes=${prefix}/include \
                          --x-libraries=${prefix}/lib
    configure.args-append --without-x
}

#
# set default variants
#

default_variants    +python27

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