# -*- 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
# $Id: Portfile 64832 2010-03-16 10:23:02Z ryandesign@macports.org $

PortSystem 1.0

name            gimp2
version         2.6.8
revision        1
categories      graphics
maintainers     devans
homepage        http://www.gimp.org/
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.

universal_variant  no

set branch      [join [lrange [split ${version} .] 0 1] .]
master_sites    gimp:gimp/v${branch}/

checksums       md5     a4d9462c9420954824a80c9b1963f9d9 \
                sha1    a550943f086abc9bf6b96d576741337b7186a4f4 \
                rmd160  da02fedcc00ebaac04bfd21c153a7130d3ff5e08

distname        gimp-${version}
use_bzip2       yes

patchfiles      patch-etc-gimprc.diff \
                patch-plug-ins-twain-tw_mac.c.diff

depends_build   port:pkgconfig \
                port:intltool \
                port:p5-xml-parser

depends_lib     port:iso-codes \
                port:gegl \
                port:gtk2 \
                port:libmng \
                port:libexif \
                port:aalib \
                port:librsvg \
                port:poppler \
                port:gnome-vfs \
                port:libgnomeui \
                port:curl \
                port:libwmf \
                port:lcms \
                port:dbus-glib \
                port:py25-gtk

platform darwin 9 {
    post-patch {
        reinplace "s|-export-symbols-regex.*||g" ${worksrcpath}/plug-ins/pygimp/Makefile.am
        reinplace "s|-export-symbols-regex.*||g" ${worksrcpath}/plug-ins/pygimp/Makefile.in
    }
}

use_parallel_build  yes
configure.python    ${prefix}/bin/python2.5
configure.args  --build=${configure.build_arch}-apple-${os.platform}${os.version} \
                --enable-mp \
                --with-pdbgen \
                --with-x \
                --without-hal \
                --without-alsa \
                --without-gvfs \
                --without-webkit

variant no_python description {Disable Python scripts and filters} {
    depends_lib-delete      port:py25-gtk
    configure.args-append   --disable-python
}

variant gvfs description {Enable gvfs support} {
    depends_lib-append      port:gvfs
    configure.args-delete   --without-gvfs
}

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

variant help_browser description {Enable Gimp help browser} {
    depends_lib-append      port:webkit-gtk
    configure.args-delete   --without-webkit
}

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

if {[variant_isset no_x11]} {
    default_variants    +quartz
}

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

pre-fetch {
    if {![variant_isset quartz] && ![variant_isset x11]} {
        error "Either +x11 or +quartz is required"
    }
}

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"
        } elseif {[variant_isset x11] && ${gtk_not_x11}} {
            error "+x11 variant selected, but gtk2+quartz is installed"
        }
    } else {
            error "Cannot find gdkconfig.h"
    }
}

variant quartz requires no_x11 conflicts x11 {
    configure.ldflags-append   -framework Carbon
}

variant x11 conflicts quartz description {Enable rendering in X11} {
}

variant no_x11 {
    configure.args-delete --with-x
    configure.args-append --without-x
}

livecheck.type  regex
livecheck.url   ftp://ftp.gimp.org/pub/gimp/v${branch}/
livecheck.regex "gimp-(${branch}(?:\\.\\d+)*)${extract.suffix}"
