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

github.setup        wez wezterm 9ddca7bde92090792dbcdc65c1e9897c362196d7
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             20241015-000000-9ddca7bde
revision            0

homepage            https://wezfurlong.org/wezterm

description         A GPU-accelerated cross-platform terminal emulator and \
                    multiplexer written in Rust

long_description    {*}${description}

categories          aqua sysutils
installs_libs       no
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

depends_build-append \
                    port:zip \
                    port:unzip

depends_lib-append  port:zlib

fetch.type          git

build.pre_args      --release -v -j${build.jobs}

use_xcode           yes

# requires macOS10.13 (Darwin17) or newer
platforms           {darwin >= 17}

post-extract {
    system -W ${worksrcpath} "git submodule update --init"
}

destroot {
    set wz_zip_name "WezTerm-macos-${version}"

    system  -W ${worksrcpath} "export TAG_NAME=${version} && ./ci/deploy.sh"

    move    ${worksrcpath}/${wz_zip_name}.zip ${destroot}${applications_dir}

    system  -W ${destroot}${applications_dir} "unzip ${wz_zip_name}.zip"

    move    ${destroot}${applications_dir}/${wz_zip_name}/WezTerm.app \
            ${destroot}${applications_dir}/

    delete  ${destroot}${applications_dir}/${wz_zip_name}
    delete  ${destroot}${applications_dir}/${wz_zip_name}.zip

    ln -s ${applications_dir}/WezTerm.app/Contents/MacOS/wezterm \
        ${destroot}${prefix}/bin/

    ln -s ${applications_dir}/WezTerm.app/Contents/MacOS/wezterm-gui \
        ${destroot}${prefix}/bin/

    set comp_src_path \
        ${applications_dir}/WezTerm.app/Contents/Resources/shell-completion

    set bash_compl_path ${destroot}${prefix}/share/bash-completion/completions
    set fish_compl_path ${destroot}${prefix}/share/fish/vendor_completions.d
    set zsh_compl_path  ${destroot}${prefix}/share/zsh/site-functions

    xinstall -d ${bash_compl_path} ${fish_compl_path} ${zsh_compl_path}

    ln -s ${comp_src_path}/bash ${bash_compl_path}/${name}
    ln -s ${comp_src_path}/fish ${fish_compl_path}/${name}.fish
    ln -s ${comp_src_path}/zsh  ${zsh_compl_path}/_${name}
}
