# -*- 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.6a
if {${subport} eq ${name}} {
    revision        0
    conflicts       tmux-devel
}
subport tmux-devel {
    github.setup    tmux tmux 1bcd360dfe8428a3d8d27777136669efd2a9a667
    version         20251204-[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  95b1132931370d465e390c220a1a7f878aba4d9f \
                            sha256  b6d8d9c76585db8ef5fa00d4931902fa4b8cbe8166f528f44fc403961a3f3759 \
                            size    750698
}

subport tmux-devel {
    github.tarball_from     archive
    checksums               rmd160  54d467a7c4f798d7ccfb3dde2c208f765031c146 \
                            sha256  f0b43438efcfec9a784df1262eb49a12ac120b3b15b4872ebe8d186a3ec5bc69 \
                            size    1094871

    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
    }

    # https://github.com/tmux/tmux/issues/4119
    patchfiles-append       patch-devel-gcc4.diff
}

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