# -*- 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 119752 2014-05-05 15:20:23Z mojca@macports.org $

PortSystem          1.0

name                gtk2hs
version             0.10.1
categories          devel graphics
platforms           darwin
maintainers         gwright

description         Portable and native GUI library for Haskell
long_description    gtk2hs is a Haskell binding to GTK, a comprehensive \
                    C GUI library that is portable across many platforms.

homepage            http://projects.haskell.org/gtk2hs/
master_sites        sourceforge

checksums           rmd160  c72acd0e2c5471c7757532cfb44c841be8e83f1d \
                    sha256  07cc98520ce6c9e0d2549fd8fd23fc5118148b7509843b0163340713a762d0c0

depends_build       port:pkgconfig
depends_lib         port:gconf \
                    port:ghc \
                    port:gtk2 \
                    port:gvfs \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:librsvg \
                    port:libglade2 \
                    port:gtkglext \
                    port:gtksourceview2

configure.args      --with-hc=${prefix}/bin/ghc   \
                    --disable-deprecated-packages \
                    --enable-profiling            \
                    --enable-packager-mode        \
                    --enable-gtk                  \
                    --enable-gio                  \
                    --enable-gconf                \
                    --enable-libglade             \
                    --enable-gtksourceview2       \
                    --enable-cairo                \
                    --enable-svg                  \
                    --enable-opengl               \
                    --without-pkgreg

# https://trac.macports.org/ticket/39383
variant no_x11 {
    depends_lib-delete      port:gtkglext
    configure.args-delete   --enable-opengl
}

# Use the same rules as GTK Portfile for setting the default variants
if {[variant_isset no_x11]} {
    default_variants    +quartz
}

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

use_parallel_build  no

# Fix gtk.package.conf to allow interoperating with non-MacPorts
# ghc. (MacPorts' ghc adds ${prefix}/lib to the linker path
# automatically.)

post-destroot {
    set pkgs {glib gio cairo svgcairo gtk gconf glade gtkglext gtksourceview2 soegtk}
    if {[variant_isset no_x11]} {
        set pkgs {glib gio cairo svgcairo gtk gconf glade gtksourceview2 soegtk}
    }
    foreach pkg ${pkgs} {
        reinplace "s|library-dirs: |library-dirs: \"${prefix}/lib\",|" \
                  ${destroot}${prefix}/lib/${name}/${pkg}.package.conf
    }
}

# Note that the order of package registration is important: certain
# packages must be registered before the packages that depend on them.

post-activate {
    set pkgs {glib gio cairo svgcairo gtk gconf glade gtkglext gtksourceview2 soegtk}
    if {[variant_isset no_x11]} {
        set pkgs {glib gio cairo svgcairo gtk gconf glade gtksourceview2 soegtk}
    }
    foreach pkg ${pkgs} {
        system "ghc-pkg update ${destroot}${prefix}/lib/${name}/${pkg}.package.conf"
    }
}
