# -*- 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           perl5 1.0

name                pidgin
version             2.14.13
revision            0
categories          net
platforms           darwin
license             GPL-2+
maintainers         {devans @dbevans} 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!, \
                    ICQ, Jabber, Napster, IRC, and Zephyr via included \
                    plugins.

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

checksums           rmd160  64ac549113694930bdf6148af8ea9030c47b4aa9 \
                    sha256  120049dc8e17e09a2a7d256aff2191ff8491abb840c8c7eb319a161e2df16ba8 \
                    size    8230755

use_bzip2           yes

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

perl5.major         5.34

depends_build       port:pkgconfig \
                    port:intltool \
                    port:autoconf \
                    port:automake \
                    port:libtool \
                    port:gettext \
                    port:gsed \
                    port:python311

depends_lib         path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:gettext-runtime \
                    port:libxml2 \
                    port:gconf \
                    port:libidn \
                    path:lib/pkgconfig/gnutls.pc:gnutls \
                    port:perl${perl5.major}

patchfiles          patch-configure.ac.diff \
                    patch-libpurple-internal.h.diff \
                    patch-pidgin-gtkdocklet-gtk.c.diff

# reconfigure using upstream autogen.sh for intltool 0.51 compatibility

post-patch {
    xinstall -m 755 ${filespath}/autogen.sh ${worksrcpath}
}

configure.cmd       ./autogen.sh

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

configure.args      --disable-avahi \
                    --disable-consoleui \
                    --disable-dependency-tracking \
                    --disable-farstream \
                    --disable-gevolution \
                    --disable-gstreamer \
                    --disable-gstreamer-interfaces \
                    --disable-gtkspell \
                    --disable-meanwhile \
                    --disable-nm \
                    --disable-nss \
                    --disable-schemas-install \
                    --disable-screensaver \
                    --disable-silent-rules \
                    --disable-sm \
                    --disable-startup-notification \
                    --disable-tcl \
                    --disable-tk \
                    --disable-vv \
                    --mandir=${prefix}/share/man \
                    --with-python3=${prefix}/bin/python3.11 \
                    --without-x

configure.args-append ac_cv_path_perlpath=${perl5.bin}

configure.ldflags-append    -bind_at_load

subport libpurple {
    depends_lib-append      port:tcl \
                            port:tk

    configure.args-delete   --disable-tcl \
                            --disable-tk
    configure.args-append   --disable-gtkui \
                            --disable-nls \
                            --disable-pixmaps-install \
                            --enable-tcl \
                            --enable-tk \
                            --with-tclconfig=${prefix}/lib \
                            --with-tkconfig=${prefix}/lib
}

subport finch {
    depends_lib-append      port:libpurple \
                            port:libgnt \
                            port:ncurses

    configure.args-delete   --disable-consoleui
    configure.args-append   --disable-gtkui \
                            --disable-pixmaps-install \
                            --disable-nls \
                            --disable-gestures \
                            --enable-consoleui \
                            --with-ncurses-headers=${prefix}/include
}

if {${subport} eq $name} {
    depends_lib-append      port:libpurple \
                            port:audiofile \
                            path:lib/pkgconfig/gtk+-2.0.pc:gtk2 \
                            port:libao

    variant x11 conflicts 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
    }

    if {[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
    }

    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"
    }
}
    
if {${subport} ne "libpurple"} {
    post-destroot {
        foreach file [glob -nocomplain -directory ${destroot}${prefix}/bin purple-*] {
            delete $file
        }
        foreach file [glob -nocomplain -directory ${destroot}${prefix}/lib pkgconfig/purple.pc libpurple* purple-2] {
            delete $file
        }
        delete ${destroot}${prefix}/include/libpurple \
               ${destroot}${prefix}/share/aclocal \
               ${destroot}${prefix}/share/man/man3/Purple.3pm \
               ${destroot}${prefix}/share/purple \
               ${destroot}${prefix}/share/sounds/purple \
    }
}

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

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