# -*- 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 119723 2014-05-04 18:21:31Z devans@macports.org $

PortSystem          1.0

name                pidgin
version             2.10.7
revision            6
categories          net
platforms           darwin
license             GPL-2+
maintainers         devans openmaintainer
description         Multi-protocol Instant Messaging client
long_description    Pidgin is an Open Source clone of America OnLine's \
                    Instant Messenger client that uses GTK+ version 2.  It \
                    features multiple groups, group chat, user information \
                    fetching and registration, time stamping, and more.  It \
                    also supports other IM protocols, including Yahoo!, MSN, \
                    ICQ, Jabber, Napster, IRC, and Zephyr via included \
                    plugins.

homepage            http://www.pidgin.im/
master_sites        sourceforge:project/pidgin/Pidgin/${version}

checksums           rmd160  51827270c7b55ae134d4b70fc5a5845681d9c1d1 \
                    sha256  eba32994eca20d1cf24a4261b059b2de71a1ec2dd0926e904074b0db49f7f192

use_bzip2           yes

depends_build       port:pkgconfig \
                    port:intltool

depends_lib         port:audiofile \
                    port:gconf \
                    port:gtk2 \
                    port:gnutls \
                    port:libao \
                    port:libidn \
                    port:libxml2 \
                    port:nspr \
                    port:nss \
                    port:perl5

# nss is not universal
universal_variant   no

patchfiles          patch-configure.ac.diff \
                    patch-libpurple-internal.h.diff

use_autoreconf      yes

configure.args      --disable-avahi \
                    --disable-consoleui \
                    --disable-farstream \
                    --disable-gstreamer \
                    --disable-gstreamer-interfaces \
                    --disable-gtkspell \
                    --disable-meanwhile \
                    --disable-nm \
                    --disable-screensaver \
                    --disable-sm \
                    --disable-startup-notification \
                    --disable-schemas-install \
                    --disable-vv \
                    --enable-nss \
                    --mandir=${prefix}/share/man \
                    --with-nspr-includes=${prefix}/include/nspr \
                    --with-nspr-libs=${prefix}/lib/nspr \
                    --with-nss-includes=${prefix}/include/nss \
                    --with-nss-libs=${prefix}/lib/nss \
                    --disable-dependency-tracking \
                    --without-x

# --disable-dependency-tracking was added because a +universal perl will result in
# PERL_CFLAGS containing multiple -arch arguments... this is the easiest workaround

configure.ldflags-append    -bind_at_load
configure.cppflags-append   -no-cpp-precomp

variant finch_only requires finch description {Build without pidgin} {
    configure.args-append   --disable-gtkui
}

variant finch description {Build with finch} {
    configure.args-delete   --disable-consoleui
    patchfiles-append          patch-finch_libgnt_Makefile.in.diff patch-finch_libgnt_gntwm.c
}

post-destroot {
    fs-traverse file ${destroot}${prefix}/lib/perl5 {
        if {[file tail ${file}] == "perllocal.pod"} {
            delete ${file}
        }
    }
}

variant x11 conflicts no_x11 quartz {
    depends_lib-append      port:xorg-libX11 \
                            port:xorg-libXext \
                            port:xorg-libXScrnSaver \
                            port:xorg-libice \
                            port:xorg-libsm

    configure.args-delete   --without-x \
                            --disable-screensaver \
                            --disable-sm

    configure.args-append   --with-x \
                            --x-includes=${prefix}/include \
                            --x-libraries=${prefix}/lib \
                            --enable-screensaver \
                            --enable-sm
}

# Legacy no_x11 variant to be removed after May 2015.
variant no_x11 conflicts x11 description {Legacy compatibility variant} {}

if {[variant_isset no_x11] || [variant_isset quartz]} {
    default_variants -x11
} else {
    default_variants +x11
}

variant quartz conflicts x11 {
    configure.args-append   --disable-gestures
}

variant spellcheck description {Allow spell checking} {
    depends_lib-append      port:gtkspell2
    configure.args-delete   --disable-gtkspell
}

# Python is only required if --enable-dbus is used, and only for
# the build process to generate the dbus code, not for running pidgin.

variant python26 conflicts python27 description {Generate dbus code using Python 2.6} {
    depends_build-append    port:python26
    configure.args-append   --with-python=${prefix}/bin/python2.6
}
    
variant python27 conflicts python26 description {Generate dbus code using Python 2.7} {
    depends_build-append    port:python27
    configure.args-append   --with-python=${prefix}/bin/python2.7
}

if {![variant_isset python26]} {
    default_variants    +python27
}
    
post-activate {
    system "dbus-uuidgen --ensure"
    system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
    system "export GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` && \
        gconftool-2 --makefile-install-rule ${prefix}/etc/gconf/schemas/*.schemas"
}

livecheck.type      regex
livecheck.url       http://sourceforge.net/projects/pidgin/files/Pidgin/
livecheck.regex     "\/Pidgin\/(\\d+(?:\\.\\d+)*)\/"
