# -*- 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.0
legacysupport.newest_darwin_requires_legacy 10

name                weechat
version             4.1.2
revision            0
checksums           rmd160  a9f09efe4f87789e1c394a2ecf4668a640078d86 \
                    sha256  9a9b910fbe768bb9de7c7ac944f5db8f233833f345b2e505e16ec6ef35effbb5 \
                    size    2635776

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         {isi.edu:calvin @cardi} openmaintainer
platforms           darwin

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

depends_lib-append  port:curl \
                    port:gettext \
                    path:lib/pkgconfig/gnutls.pc:gnutls \
                    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

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_PYTHON2=OFF \
                    -DENABLE_RUBY=OFF \
                    -DENABLE_SPELL=OFF \
                    -DENABLE_TCL=OFF \
                    -DENABLE_TESTS=OFF

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

variant python38 description "Bindings for Python 3.8 plugins" conflicts python39 python310 python311 python312 {
    configure.args-replace  -DENABLE_PYTHON=OFF -DENABLE_PYTHON=ON
    configure.pkg_config_path-append \
                            ${frameworks_dir}/Python.framework/Versions/3.8/lib/pkgconfig
    depends_lib-append      port:python38
}

variant python39 description "Bindings for Python 3.9 plugins" conflicts python38 python310 python311 python312 {
    configure.args-replace  -DENABLE_PYTHON=OFF -DENABLE_PYTHON=ON
    configure.pkg_config_path-append \
                            ${frameworks_dir}/Python.framework/Versions/3.9/lib/pkgconfig
    depends_lib-append      port:python39
}

variant python310 description "Bindings for Python 3.10 plugins" conflicts python38 python39 python311 python312 {
    configure.args-replace  -DENABLE_PYTHON=OFF -DENABLE_PYTHON=ON
    configure.pkg_config_path-append \
                            ${frameworks_dir}/Python.framework/Versions/3.10/lib/pkgconfig
    depends_lib-append      port:python310
}

variant python311 description "Bindings for Python 3.11 plugins" conflicts python38 python39 python310 python312 {
    configure.args-replace  -DENABLE_PYTHON=OFF -DENABLE_PYTHON=ON
    configure.pkg_config_path-append \
                            ${frameworks_dir}/Python.framework/Versions/3.11/lib/pkgconfig
    depends_lib-append      port:python311
}

variant python312 description "Bindings for Python 3.12 plugins" conflicts python38 python39 python310 python311 {
    configure.args-replace  -DENABLE_PYTHON=OFF -DENABLE_PYTHON=ON
    configure.pkg_config_path-append \
                            ${frameworks_dir}/Python.framework/Versions/3.12/lib/pkgconfig
    depends_lib-append      port:python312
}

variant ruby requires ruby32 description {Compatibility variant, requires +ruby32} {}

variant ruby30 description "Bindings for Ruby 3.0 plugins" conflicts ruby31 ruby32 {
    configure.args-replace  -DENABLE_RUBY=OFF -DENABLE_RUBY=ON
    configure.env-append    PKG_CONFIG_PATH=${prefix}/lib/pkgconfig
    depends_lib-append      port:ruby30

    patchfiles              FindRuby.cmake.diff
}

variant ruby31 description "Bindings for Ruby 3.1 plugins" conflicts ruby30 ruby32 {
    configure.args-replace  -DENABLE_RUBY=OFF -DENABLE_RUBY=ON
    configure.env-append    PKG_CONFIG_PATH=${prefix}/lib/pkgconfig
    depends_lib-append      port:ruby31

    patchfiles              FindRuby.cmake.diff
}

variant ruby32 description "Bindings for Ruby 3.2 plugins" conflicts ruby30 ruby31 {
    configure.args-replace  -DENABLE_RUBY=OFF -DENABLE_RUBY=ON
    configure.env-append    PKG_CONFIG_PATH=${prefix}/lib/pkgconfig
    depends_lib-append      port:ruby32

    patchfiles              FindRuby.cmake.diff
}


post-patch {
    # specify Ruby version for CMake to find and use
    set patchfile ${worksrcpath}/cmake/FindRuby.cmake

    if {[variant_isset ruby30]} {
        reinplace -E {s|pkg_search_module\(RUBY (.*)\)|pkg_search_module\(RUBY ruby-3.0\)|g} ${patchfile}
    } elseif {[variant_isset ruby31]} {
        reinplace -E {s|pkg_search_module\(RUBY (.*)\)|pkg_search_module\(RUBY ruby-3.1\)|g} ${patchfile}
    } elseif {[variant_isset ruby32]} {
        reinplace -E {s|pkg_search_module\(RUBY (.*)\)|pkg_search_module\(RUBY ruby-3.2\)|g} ${patchfile}
    }
}

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
}

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