# -*- 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.1
PortGroup           conflicts_build 1.0
PortGroup           legacysupport 1.1

# strndup()
legacysupport.newest_darwin_requires_legacy 10

name                weechat
version             4.9.5
revision            0
categories          irc
license             GPL-3
maintainers         {acm.org:cardi @cardi} openmaintainer

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!

homepage            https://weechat.org
master_sites        ${homepage}/files/src/
use_xz              yes
checksums           rmd160  3f341d82ca9a2aa759487ff0c13e37e2e3770956 \
                    sha256  3b3946104e64536d0602370a30e55dd5a301cc8ff420184ff0a101926dad1d16 \
                    size    2801244

depends_build-append \
                    port:asciidoctor \
                    port:docbook-xsl-nons \
                    port:libxslt \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:curl \
                    port:gettext \
                    path:lib/pkgconfig/gnutls.pc:gnutls \
                    port:libcjson \
                    port:libgcrypt \
                    port:libiconv \
                    port:ncurses \
                    port:zlib

depends_run-append  path:etc/openssl/cert.pem:curl-ca-bundle

depends_test-append port:cpputest

license_noconflict  asciidoctor

patchfiles          no-extra-gcc-warnings.patch

# src/plugins/plugin.c:1128: error: ‘WEECHAT_LIBDIR’ undeclared
compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2

configure.args-append \
                    -DENABLE_GUILE=OFF \
                    -DENABLE_JAVASCRIPT=OFF \
                    -DENABLE_LUA=OFF \
                    -DENABLE_MAN=ON \
                    -DENABLE_PERL=OFF \
                    -DENABLE_PHP=OFF \
                    -DENABLE_PYTHON=OFF \
                    -DENABLE_RUBY=OFF \
                    -DENABLE_SPELL=OFF \
                    -DENABLE_TCL=OFF \
                    -DENABLE_TESTS=OFF

set python_suffixes {310 311 312 313 314}

set python_ports {}
foreach s ${python_suffixes} {
    lappend python_ports python${s}
}

variant python requires python[lindex ${python_suffixes} end] \
    description "Compatibility variant, requires +python[lindex ${python_suffixes} end]" {}

foreach s ${python_suffixes} {
    set p python${s}
    set v [string index ${s} 0].[string range ${s} 1 end]
    set i [lsearch -exact ${python_ports} ${p}]
    set c [lreplace ${python_ports} ${i} ${i}]
    variant ${p} description "Bindings for Python ${v} plugins" conflicts {*}${c} "
        configure.args-replace  -DENABLE_PYTHON=OFF -DENABLE_PYTHON=ON
        configure.args-append   -DPython_EXECUTABLE=\${prefix}/bin/python${v}
        depends_lib-append      port:${p}
    "
}

set ruby_suffixes {33 34}

set ruby_ports {}
foreach s ${ruby_suffixes} {
    lappend ruby_ports ruby${s}
}

variant ruby requires ruby[lindex ${ruby_suffixes} end] \
    description "Compatibility variant, requires +ruby[lindex ${ruby_suffixes} end]" {}

foreach s ${ruby_suffixes} {
    set p ruby${s}
    set v [string index ${s} 0].[string range ${s} 1 end]
    set i [lsearch -exact ${ruby_ports} ${p}]
    set c [lreplace ${ruby_ports} ${i} ${i}]
    # Ruby should pick the right library: https://github.com/weechat/weechat/issues/2334
    variant ${p} description "Bindings for Ruby ${v} plugins" conflicts {*}${c} "
        configure.args-replace  -DENABLE_RUBY=OFF -DENABLE_RUBY=ON
        configure.args-append   -DRuby_EXECUTABLE=\${prefix}/bin/ruby${v} \
                                -DRuby_LIBRARY=\${prefix}/lib/libruby${v}.dylib
        depends_lib-append      port:${p}
    "
}

variant aspell description "Support for Spellcheck (aspell)" {
    configure.args-delete   -DENABLE_SPELL=OFF
    configure.args-append   -DENABLE_SPELL=ON
    depends_lib-append      port:aspell
}

variant doc description "Build HTML Documentation and Plugin API" {
    configure.args-append   -DENABLE_DOC=ON -DENABLE_DOC_INCOMPLETE=ON
    depends_build-append    port:source-highlight

    notes-append "Documentation is not built for disabled plugins."
}

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 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 scheme description "Bindings for Scheme (guile) plugins" {
    configure.args-delete   -DENABLE_GUILE=OFF
    configure.args-append   -DENABLE_GUILE=ON
    depends_lib-append      port:guile-3.0
}

variant tcl description "Bindings for Tcl plugins" {
    configure.args-delete   -DENABLE_TCL=OFF
    configure.args-append   -DENABLE_TCL=ON
    depends_lib-append      port:tcl
}

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

livecheck.type      regex
livecheck.regex     ^(\[0-9.\]*)$
livecheck.url       https://weechat.org/dev/info/stable/
