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

# Need strndup()
PortGroup           legacysupport 1.1
legacysupport.newest_darwin_requires_legacy 10

name                weechat
version             4.9.4
revision            0
checksums           rmd160  d7aeaf65315d3dc4a85bedeb4391b4bf76c873fa \
                    sha256  3fc50359f3a3b258c9f03148b02f3b9c59194535d1b465c481fb85a76c2ed005 \
                    size    2799628

master_sites        https://weechat.org/files/src/
use_xz              yes

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

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         {acm.org:cardi @cardi} openmaintainer

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

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

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}]
    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
}
