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

github.setup        hexchat hexchat 2.16.2 v
revision            0
set branch          [join [lrange [split ${version} .] 0 1] .]
set perl_minor      34
set python_minor    12
categories          irc
maintainers         nomaintainer
description         IRC client based on XChat
homepage            https://hexchat.github.io/
license             GPL-2+

long_description \
    HexChat is a graphical IRC client using GTK that has \
    many features and can be scripted with Lua, Perl, or Python.

use_xz yes

checksums           rmd160  5d50f4fc19bc876647400087b6c867a68d40a0bf \
                    sha256  2e88340a8da274b87373ec0740746da78120cc6fbfdd201a4dd6999cac790e4a \
                    size    1352304
github.tarball_from releases

patchfiles          patch-meson-post-install.diff \
                    patch-build-scripts-python3.diff
patch.pre_args-replace  -p0 -p1

post-patch {
    reinplace "s:@PYTHON3@:${prefix}/bin/python3.${python_minor}:" \
        ${worksrcpath}/plugins/perl/generate_header.py \
        ${worksrcpath}/plugins/python/generate_plugin.py \
        ${worksrcpath}/src/common/make-te.py
    reinplace "s:@PERL@:${prefix}/bin/perl5.${perl_minor}:" \
        ${worksrcpath}/plugins/perl/generate_header
}

depends_build-append \
                    port:pkgconfig \
                    port:python3${python_minor} \
                    port:py3${python_minor}-cffi

depends_lib         path:lib/pkgconfig/gtk+-2.0.pc:gtk2 \
                    port:dbus-glib \
                    port:libproxy \
                    port:libnotify \
                    port:libcanberra \
                    port:gettext

depends_run         port:desktop-file-utils

configure.args \
    -Dtls=disabled \
    -Dwith-fishlim=false \
    -Dtheme-manager=false \
    -Dwith-lua=false \
    -Dwith-perl=false \
    -Dwith-python=false

platform darwin 8 {
    # sysinfo backend.m contains ObjC incompatible with Tiger
    configure.args-append       -Dwith-sysinfo=false
}

default_variants    +ssl +lua +perl +python

variant ssl description "Enable SSL using openssl" {
    depends_lib-append          path:lib/libssl.dylib:openssl
    configure.args-replace      -Dtls=disabled -Dtls=enabled
    configure.args-append       -Dwith-fishlim=true
}

variant lua description "Enable Lua scripting, using luajit" {
    depends_lib-append          port:lua
    configure.args-replace      -Dwith-lua=false -Dwith-lua=lua
}

variant perl description "Enable Perl scripting, using perl5.${perl_minor}" {
    depends_lib-append          port:perl5.${perl_minor}
    configure.args-replace      -Dwith-perl=false -Dwith-perl=${prefix}/bin/perl5.${perl_minor}
}

variant python description "Enable Python scripting, using python3${python_minor}" {
    depends_lib-append          port:python3${python_minor}
    configure.args-replace      -Dwith-python=false -Dwith-python=python-3.${python_minor}
    configure.pkg_config_path   ${frameworks_dir}/Python.framework/Versions/3.${python_minor}/lib/pkgconfig/
}

post-activate {
    system "${prefix}/bin/gtk-update-icon-cache-2.0 -f -t ${prefix}/share/icons/hicolor"
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}

livecheck.type  regex
livecheck.url   https://hexchat.github.io/downloads.html
livecheck.regex ${name}-(\\d+(\\.\\d+)+)\\.tar
