# -*- 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
# $Id: Portfile 106120 2013-05-15 18:06:01Z larryv@macports.org $

PortSystem              1.0

name                    zsh
version                 5.0.2
revision                3
categories              shells
platforms               darwin
maintainers             larryv
license                 Permissive

description             Zsh is a UNIX command interpreter (shell)
long_description        Zsh is a UNIX command interpreter (shell) which \
                        of the standard shells most resembles the Korn \
                        shell (ksh), although it is not completely \
                        compatible. It includes enhancements of many \
                        types, notably in the command-line editor, \
                        options for customising its behaviour, filename \
                        globbing, features to make C-shell (csh) users \
                        feel more at home and extra features drawn from \
                        tcsh (another 'custom' shell).

homepage                http://www.zsh.org/

use_bzip2               yes
master_sites            sourceforge:project/zsh/zsh/${version} \
                        http://www.zsh.org/pub/ \
                        ftp://ftp.zsh.org/pub/ \
                        ftp://ftp.fu-berlin.de/unix/shells/zsh/ \
                        ftp://ftp.icm.edu.pl/vol/rzm1/zsh/
distfiles-append        ${distname}-doc${extract.suffix}
checksums               ${distname}${extract.suffix} \
                            rmd160  eea2328a28e9f022ab9f49583622a9c3bd6114a7 \
                            sha256  eb220ae5a8076191ec6b4c6a5a2f18122d074a19f25b45f0320b44b8166c5a03 \
                        ${distname}-doc${extract.suffix} \
                            rmd160  a42bd1b85cae98158391d6aa120c6f9d4735ef7b \
                            sha256  99ee08cfc91935af8714bd98db652f016d6c7a8a71ba7c6d6223910cd0b7fbf1

set help ${prefix}/share/${name}/${version}/help
set doc ${prefix}/share/doc/${name}

post-patch {
    reinplace -E "s|{HELPDIR:-.+}|{HELPDIR:-${help}}|" \
        ${worksrcpath}/Functions/Misc/run-help
}

# Perl is only needed in post-destroot.
depends_build           bin:perl:perl5
depends_lib             port:libiconv \
                        port:ncurses \
                        port:gdbm \
                        port:pcre

configure.args          --htmldir=${doc}/html \
                        --enable-libs="-lncurses" \
                        --enable-pcre \
                        --with-tcsetpgrp \
                        DL_EXT=bundle

test.run                yes
test.target             check

destroot.target-append  install.html install.info

post-destroot {
    # zshall(1) just includes every other zsh manpage, but its .so groff
    # directives fail because MacPorts gzips manpages.
    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

    # Generate run-help help files; see zshcontrib(1).
    xinstall -d ${destroot}${help}
    system -W ${destroot}${help} "man ${man}/man1/zshbuiltins.1 | \
        colcrt - | \ perl ${worksrcpath}/Util/helpfiles"

    # Install any straggling documentation.
    xinstall -m 0644 -W ${worksrcpath} \
        ChangeLog FEATURES LICENCE META-FAQ NEWS README ${destroot}${doc}
    xinstall -d ${destroot}${doc}/pdf
    eval xinstall -m 0644 [glob ${worksrcpath}/Doc/*.pdf] \
        ${destroot}${doc}/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'
"
