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

name                mlterm
version             3.9.4
revision            2
checksums           rmd160  8c11694b8f5faeb03d7e5efffef3ea38867fad06 \
                    sha256  171de4c4f3443bc1211cc51df5caa0e082ffcdd33ab3ce261bc0a4cfe85d9b5e \
                    size    4227568

categories          x11
maintainers         nomaintainer
license             BSD

description         Multi-lingual X11 terminal emulator

long_description    ${name} is a multi-lingual terminal emulator written \
                    from scratch, which supports various character sets \
                    and encodings in the world and complex characters, \
                    such as double width for East Asian, combining for Thai, \
                    Vietnamese, and so on, and bi-direction for Arabic \
                    and Hebrew. Indic scripts in ISCII encoding are \
                    experimentally supported using libind library. It also \
                    supports various unique feature such as anti-alias using \
                    FreeType, multiple XIM, multiple windows, scrollbar API, \
                    scroll by mouse wheel, automatic selection of encoding, \
                    daemon mode, and so on.

homepage            https://mlterm.sourceforge.net
master_sites        sourceforge:project/mlterm/01release/mlterm-${version}

depends_build-append \
                    port:gettext \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:fontconfig \
                    port:freetype \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    port:gettext-runtime \
                    path:lib/pkgconfig/harfbuzz.pc:harfbuzz \
                    port:libsixel \
                    port:libssh2 \
                    port:fribidi \
                    port:libsdl2

# https://github.com/arakiken/mlterm/issues/139
patchfiles-append   patch-fix-undefined-behavior.diff

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    file copy {*}[glob ${worksrcpath}/doc/*] \
        ${destroot}${prefix}/share/doc/${name}
}

variant gtk2 conflicts gtk3 description {Build with GTK2} {
    depends_lib-append      path:lib/pkgconfig/gtk+-2.0.pc:gtk2
    configure.args-append   --with-gtk=2.0
}

variant gtk3 conflicts gtk2 description {Build with GTK3} {
    depends_lib-append      path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                            port:vte
    configure.args-append   --with-gtk=3.0
}

variant x11 conflicts sdl2 quartz {
    depends_lib-append      port:Xft2 \
                            port:xorg-libX11
    configure.args-append   --with-gui=xlib
}

variant quartz conflicts sdl2 x11 {
    configure.args-append   --with-gui=quartz
    post-destroot {
        set app_dir ${applications_dir}/mlterm.app
        set bin_dir ${app_dir}/Contents/MacOS
        copy ${worksrcpath}/cocoa/mlterm.app ${destroot}${app_dir}
        ln -s ${prefix}/etc/mlterm ${destroot}${app_dir}
        xinstall -d ${destroot}${bin_dir}
        move ${destroot}${prefix}/bin/mlterm ${destroot}${bin_dir}
        ln -s ${prefix}/libexec/mlterm/mlconfig ${destroot}${bin_dir}
        # Using a symlink doesn't work because the app can't find its data files.
        set fp [open ${destroot}${prefix}/bin/mlterm w 0755]
        puts ${fp} "#!/bin/sh"
        puts ${fp} "exec '${bin_dir}/mlterm' \"$@\""
        close ${fp}
    }
}

# This may not work well with older systems.
variant sdl2 conflicts quartz x11 description {Use SDL2 GUI} {
    configure.args-append   --with-gui=sdl2
}

# Upstream default is gtk3
if {![variant_isset gtk2] && ![variant_isset gtk3]} {
    default_variants        +gtk3
}

if {![variant_isset sdl2]} {
    if {![variant_isset quartz]} {
        default_variants +x11
    }
    if {![variant_isset x11]} {
        default_variants +quartz
    }
}

if {![variant_isset sdl2] && ![variant_isset quartz] && ![variant_isset x11]} {
    pre-configure {
        return -code error "Either +sdl2, +x11 or +quartz is required"
    }
}

livecheck.regex     /${name}-(\[0-9.\]+)${extract.suffix}
