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

github.setup    tmux tmux 3.7b
if {${subport} eq ${name}} {
    revision        0
    conflicts       tmux-devel
}
subport tmux-devel {
    github.setup    tmux tmux 6ad86ebdf1ed9f3fa71c2adbf7cb0cf057732609
    version         20260701-[string range ${github.version} 0 6]
    revision        0
    conflicts       tmux
}
categories      sysutils
maintainers     {evermeet.cx:tessarek @tessus} openmaintainer
description     terminal multiplexer
long_description \
    tmux is a \"terminal multiplexer\", it enables a number of terminals \
    (or windows) to be accessed and controlled from a single terminal. \
    tmux is intended to be a simple, modern, BSD-licensed alternative \
    to programs such as GNU screen.
homepage        https://tmux.github.io
license         BSD

# Availability.h
legacysupport.newest_darwin_requires_legacy \
                8

depends_build   path:bin/pkg-config:pkgconfig
depends_lib     port:libutf8proc \
                port:libevent \
                port:ncurses
configure.args-append \
                --enable-utf8proc \
                --sysconfdir=${prefix}/etc

if {${subport} eq ${name}} {
    github.tarball_from     releases
    checksums               rmd160  a467fd66fdd012d7a06f24f80613932bcc639d8a \
                            sha256  87f2e99e3b685973f2ca002ffd6ed7e51a5744f7009daae5a15670b6d532db96 \
                            size    788458
}

subport tmux-devel {
    github.tarball_from     archive
    checksums               rmd160  a650dd0b87fe55834537b124c6da381831e758cc \
                            sha256  866270932f7409bbdd0f750c926f018a0554a6a7b3b930a759b03d72a35a46d9 \
                            size    1210374

    use_autoreconf          yes
    autoreconf.cmd          ./autogen.sh
    autoreconf.args
    depends_build-append    port:autoconf \
                            port:automake \
                            port:libtool
    post-extract {
        set reinplace_cmd [subst -nobackslashes -nocommands {s/AC_INIT\(\[tmux\], (next-[0-9]+\.[0-9]+)\)/AC_INIT([tmux], \1 (${version}))/g}]
        reinplace -E $reinplace_cmd ${worksrcpath}/configure.ac
    }
}

platform darwin {
    if {${os.major} < 23} {
        # Before Sonoma, macOS lacked terminal descriptions for tmux,
        # tmux-256color. Fallback on a terminal definition that is available on
        # these older versions
        configure.args-append   --with-TERM=screen-256color
    }
}

platform darwin 8 {
    # On Mac OS X 10.4 there's no libproc.h, so we use a previous version of osdep-darwin.c (c1b9948)
    post-extract {
        file copy -force ${filespath}/osdep-darwin.8.c ${worksrcpath}/osdep-darwin.c
    }
    # Normally `pkg-config ncurses --cflags` sets _XOPEN_SOURCE=600, which has a
    # side effect of setting _POSIX_C_SOURCE and hiding dozens of definitions
    # that are needed
    configure.env-append    LIBNCURSES_CFLAGS=-D_APPLE_C_SOURCE

    # "No rule to make target `compat/forkpty-darwin.c'"
    depends_build-append    port:gmake
    build.cmd               gmake
}

post-destroot {
    xinstall -m 0755 -d ${destroot}${prefix}/share/doc/tmux
    xinstall -m 0644 ${worksrcpath}/example_tmux.conf ${destroot}${prefix}/share/doc/tmux
    xinstall -m 0755 -d ${destroot}${prefix}/share/vim/vimfiles/ftdetect
    xinstall -m 0644 ${filespath}/ftdetect-tmux.vim ${destroot}${prefix}/share/vim/vimfiles/ftdetect/tmux.vim
}

variant sixel description {Support SIXEL graphics} {
    configure.args-append   --enable-sixel
}

default_variants-append +sixel

notes {
    On legacy systems, consider installing port tmux-pasteboard to\
    integrate the system pasteboard with tmux.
}

github.livecheck.regex {([0-9.]+[a-z]?)}
