# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem              1.0

name                    zsh
# TODO: Remove CFLAGS kludge below when upgrading to next release.
version                 5.9
revision                3
categories              shells
platforms               darwin
license                 Permissive
maintainers             {larryv @larryv}

description             The Z shell
long_description    {*}{Zsh is a shell designed for interactive use,
                        although it is also a powerful scripting
                        language. Many of the useful features of bash,
                        ksh, and tcsh were incorporated into zsh;
                        many original features were added.}
homepage                https://www.zsh.org

depends_lib             port:gdbm \
                        port:libiconv \
                        port:ncurses \
                        port:pcre

master_sites            sourceforge:project/zsh/zsh/${version}:src \
                        sourceforge:project/zsh/zsh-doc/${version}:doc
foreach mirror {        https://www.zsh.org/pub
                        ftp://ftp.zsh.org/pub
                        ftp://ftp.fu-berlin.de/unix/shells/zsh
                        ftp://ftp.funet.fi/pub/unix/shells/zsh
                        ftp://ftp.icm.edu.pl/vol/rzm4/zsh
                        ftp://sunsite.icm.edu.pl/pub/unix/shells/zsh
} {
    master_sites-append ${mirror}:src ${mirror}:doc
}

use_xz                  yes
distfiles               ${distname}${extract.suffix}:src \
                        ${distname}-doc${extract.suffix}:doc

checksums               ${distname}${extract.suffix} \
                            rmd160  4f49ce980f92ec119978763f65c04d9670da7d51 \
                            sha256  9b8d1ecedd5b5e81fbf1918e876752a7dd948e05c1a0dba10ab863842d45acd5 \
                            size    3332400 \
                        ${distname}-doc${extract.suffix} \
                            rmd160  8f546b5cc34ac22bff72bbe914604746bb44a49e \
                            sha256  6f7c091249575e68c177c5e8d5c3e9705660d0d3ca1647aea365fd00a0bd3e8a \
                            size    3130444

patchfiles              prevent-info-regeneration.patch
post-patch {
    # The texi2html configuration is not shipped with the pregenerated
    # HTML docs, but without it the build tries to regenerate them.
    touch -r ${worksrcpath}/Doc/zsh_toc.html ${worksrcpath}/Doc/texi2html.conf
}

set docdir ${prefix}/share/doc/${name}

configure.args          --enable-cap \
                        --enable-gdbm \
                        --enable-pcre \
                        --htmldir='${docdir}/html' \
                        --with-tcsetpgrp

# https://trac.macports.org/ticket/70293
# TODO: Remove when upgrading to next release.
configure.cflags-append -Wno-error=implicit-int

# NOTE: The zpty tests can't open pseudoterminals from "port test".
test.run                yes
test.target             check

destroot.target-append  install.html install.info

post-destroot {
    if {${os.major} < 22} {
        # zshall(1) includes every other zsh manpage, but groff cannot
        # process the .so requests because we compress manpages.  (Not
        # necessary on macOS 13 and later, which use mandoc instead of
        # groff.  See <https://trac.macports.org/ticket/65718>.)
        set man ${destroot}${prefix}/share/man
        system -W ${man} "soelim man1/zshall.1 >zshall.1.soelim"
        move -force ${man}/zshall.1.soelim ${man}/man1/zshall.1
    }

    # Install neglected documentation.
    xinstall -m 0644 -W ${worksrcpath} \
        FEATURES LICENCE META-FAQ NEWS README ${destroot}${docdir}
    xinstall -d ${destroot}${docdir}/pdf
    xinstall -m 0644 -W ${worksrcpath}/Doc \
        intro.a4.pdf intro.us.pdf zsh.pdf ${destroot}${docdir}/pdf
}

notes "
To set MacPorts' ${name} as default login shell, run:

    sudo chpass -s '${prefix}/bin/${name}' \"\$USER\"

To be able to switch default shells to or from ${name} without superuser\
privileges, add it to /etc/shells:

    sudo sh -c 'echo ${prefix}/bin/${name} >>/etc/shells'
"
