# -*- 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 119549 2014-04-30 07:42:17Z and.damore@macports.org $

PortSystem          1.0
PortGroup           cmake 1.0

name                weechat
version             0.4.3
revision            1
checksums           rmd160  b9625a977d36757a4b8dfa560946f1604ba5f68a \
                    sha256  a8ec847d331a1201de975530a22f1813c260db420c68675b2ecaa7bf3c7c3ff8

homepage            http://weechat.org/
license             GPL-3
description         Fast, light & extensible IRC client
long_description    \
    WeeChat (Wee Enhanced Environment for Chat) is a fast and light IRC client \
    for many operating systems. Everything can be done with a keyboard. It is \
    customizable and extensible with plugins/scripts, and includes: \
    \n - nicklist \
    \n - smart hotlist \
    \n - infobar with highlight notification \
    \n - horizontal and vertical split \
    \n - double charset support (decode/encode) \
    \n - FIFO pipe for remote control \
    \n - and much more!

categories          irc
maintainers         gmail.com:starkhalo \
                    openmaintainer
platforms           darwin

master_sites        ${homepage}files/src
use_bzip2           yes

depends_lib-append  port:gettext \
                    port:libgcrypt \
                    port:libiconv \
                    port:ncurses

depends_run-append  path:etc/openssl/cert.pem:certsync

configure.args-append \
                    -DENABLE_GNUTLS=OFF \
                    -DENABLE_LUA=OFF \
                    -DENABLE_GUILE=OFF \
                    -DENABLE_PERL=OFF \
                    -DENABLE_PYTHON=OFF \
                    -DENABLE_RUBY=OFF \
                    -DENABLE_ASPELL=OFF \
                    -DCA_FILE=${prefix}/etc/openssl/cert.pem

variant aspell description {Support for aspell} {
    configure.args-delete   -DENABLE_ASPELL=OFF
    configure.args-append   -DENABLE_ASPELL=ON
    depends_lib-append      port:aspell
}

variant lua description {Bindings for lua plugins} {
    configure.args-delete   -DENABLE_LUA=OFF
    configure.args-append   -DENABLE_LUA=ON
    depends_lib-append      port:lua
}

variant scheme description {Bindings for Scheme (guile) plugins} {
    configure.args-delete   -DENABLE_GUILE=OFF
    configure.args-append   -DENABLE_GUILE=ON
    depends_lib-append      port:guile
}

variant perl description {Bindings for perl plugins} {
    configure.args-delete   -DENABLE_PERL=OFF
    configure.args-append   -DENABLE_PERL=ON
    depends_lib-append      path:bin/perl:perl5
}

variant python description {Bindings for python plugins} {
    configure.args-delete   -DENABLE_PYTHON=OFF
    configure.args-append   -DENABLE_PYTHON=ON
    depends_lib-append      path:bin/python:python27

    post-configure {
        reinplace -E "s|\(Python.framework\)|${frameworks_dir}/\\1|" ${worksrcpath}/src/plugins/python/CMakeFiles/python.dir/link.txt
    }
}

variant ruby description {Bindings for ruby plugins} {
    configure.args-delete   -DENABLE_RUBY=OFF
    configure.args-append   -DENABLE_RUBY=ON
    depends_lib-append      port:ruby
}

variant tls description {Support for secure connecting} {
    configure.args-delete   -DENABLE_GNUTLS=OFF
    configure.args-append   -DENABLE_GNUTLS=ON
    depends_lib-append      port:gnutls
}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} AUTHORS COPYING ChangeLog NEWS README \
        ${destroot}${prefix}/share/doc/${name}
    eval xinstall -m 644 -W ${worksrcpath} [glob doc/en/weechat*.txt] \
        ${destroot}${prefix}/share/doc/${name}
}

post-install {
    # if present then remove file previously installed outside destroot
    foreach file {include/weechat/weechat-plugin.h} {
        set filepath ${prefix}/${file}
        if {[file exists ${filepath}] && [registry_file_registered ${filepath}] == "0"} {
            if {[catch {delete ${filepath}}]} {
                ui_warn "Cannot delete ${filepath}; please remove it manually"
            }
        }
    }
}
