# -*- 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           cmake 1.0
PortGroup           conflicts_build 1.0
PortGroup           github 1.0

name                weechat

if {${name} eq ${subport}} {
    conflicts       weechat-devel
    name            weechat
    version         2.6
    revision        0
    checksums       rmd160  816c72c42e318b5b2be6d282a4fbda161065fd78 \
                    sha256  0b06e551e69018dbd4828113a56a9657a16cb787eb44bc83adf45424e65759d9 \
                    size    2993206

    master_sites    https://weechat.org/files/src/
    use_bzip2       yes
}

subport weechat-devel {
    conflicts       weechat
    name            weechat-devel
    version         2.5-dev-20190424
    revision        0
    checksums       rmd160  ef1b9219d799507e783f84aab90b163546184139 \
                    sha256  00ca8188a67175e158fafa356a528731ed6520ae8b629627791653f1b204af1b \
                    size    2952987

    master_sites    https://weechat.org/files/src/devel/
    use_bzip2       yes
    distname        ${name}-20190424
    worksrcdir      ${name}
}

homepage            https://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 @harciga} \
                    openmaintainer
platforms           darwin

depends_build-append \
                    port:asciidoctor \
                    port:libxslt \
                    port:pkgconfig \
                    port:docbook-xsl-nons

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

license_noconflict  asciidoctor

cmake.out_of_source yes

conflicts_build v8

configure.args-append \
                    -DENABLE_GNUTLS=OFF \
                    -DENABLE_LUA=OFF \
                    -DENABLE_GUILE=OFF \
                    -DENABLE_PERL=OFF \
                    -DENABLE_PYTHON=OFF \
                    -DENABLE_PYTHON2=OFF \
                    -DENABLE_RUBY=OFF \
                    -DENABLE_ASPELL=OFF \
                    -DENABLE_TCL=OFF \
                    -DENABLE_JAVASCRIPT=OFF \
                    -DENABLE_PHP=OFF \
                    -DENABLE_MAN=ON

variant python requires python27 description {Compatibility variant, requires +python27} {}

variant python27 description "Bindings for python 2.7 plugins" conflicts python36 {
    configure.args-replace  -DENABLE_PYTHON=OFF -DENABLE_PYTHON=ON
    configure.args-replace  -DENABLE_PYTHON2=OFF -DENABLE_PYTHON2=ON
    depends_lib-append      port:python27
}

variant python36 description "Bindings for python 3.6 plugins" conflicts python27 {
    configure.args-replace  -DENABLE_PYTHON=OFF -DENABLE_PYTHON=ON
    depends_lib-append      port:python36
}

post-patch {
    set patchfile ${worksrcpath}/cmake/FindPython.cmake

    if {[variant_isset python27]} {
        reinplace -E "s|PYTHON python2|PYTHON python-2.7|g" ${patchfile}
    }
    if {[variant_isset python36]} {
        reinplace -E "s|PYTHON python3|PYTHON python-3.6|g" ${patchfile}
    }
}

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

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 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} {
    depends_run-append      path:etc/openssl/cert.pem:curl-ca-bundle

    configure.args-delete   -DENABLE_GNUTLS=OFF
    configure.args-append   -DENABLE_GNUTLS=ON \
                            -DCA_FILE=${prefix}/etc/openssl/cert.pem
    depends_lib-append      port:gnutls
}

variant doc description {Build Documentation and plugin API} {
    depends_build-append    port:source-highlight

    configure.args-append   -DENABLE_DOC=ON
}

default_variants    +tls

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