# -*- 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 79197 2011-06-05 02:20:06Z vinc17@macports.org $

PortSystem      1.0

name            zsh-devel
set my_name     [strsed ${name} {s/-.*//}]
version         4.3.12
categories      shells
platforms       darwin
maintainers     nomaintainer
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
dist_subdir     ${my_name}
distname        ${my_name}-${version}
master_sites    ${homepage}pub/ \
                ftp://ftp.zsh.org/${my_name} \
                ftp://ftp.sterling.com/${my_name}/ \
                ftp://ftp.rge.com/pub/shells/${my_name}/ \
                ftp://ftp.fu-berlin.de/pub/unix/shells/${my_name}/ \
                ftp://ftp.ips.oz.au/pub/packages/${my_name}/ \
                ftp://ftp.uit.no/pub/unix/shells/${my_name}/ \
                ftp://ftp.iij.ad.jp/pub/misc/${my_name}/ \
                ftp://ftp.icm.edu.pl/vol/wojsyl/${my_name}/ \
                ftp://ftp.sunsite.auc.dk/disk1/${my_name}/ \
                sourceforge:${my_name} \
                http://deb.grml.org/pool/main/z/${my_name}-lovers/:love

# Some love for zsh: http://grml.org/zsh/zsh-lovers.html
set love_distname   zsh-lovers_0.8.3
set love_distfile   ${love_distname}.tar.gz
set worklovedir     zsh-lovers
set worklovepath    ${workpath}/${worklovedir}

checksums       zsh-${version}.tar.bz2 \
                    md5     7a82c0bf0635e046ca4e9ec1bdef3811 \
                    sha1    8fd7a6d841770c8b12cf3ae8229dd857ecdbad93 \
                    rmd160  83f2a0f3e590722262e5725df97d924b1fd4ee84 \
                zsh-${version}-doc.tar.bz2 \
                    md5     d1bcb1e1716ac5726444dee2a3dca98d \
                    sha1    89d799454993e787aae75b54f6ecfde90b3fc530 \
                    rmd160  502b6c39c1d58d92d6df485f9298b184a808fc3c \
                zsh-lovers_0.8.3.tar.gz \
                    md5     6604f3bb8a971e66281e1369cc4bd033 \
                    sha1    f4905d8825c982371e72053a58cb9679329249a8 \
                    rmd160  f8482d61d700cc79530b4839de5a86aed6783e99

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

configure.args  --mandir=${prefix}/share/man \
                --infodir=${prefix}/share/info \
                --enable-multibyte \
                --enable-etcdir=${prefix}/etc \
                --with-tcsetpgrp

configure.env   DL_EXT=bundle

use_parallel_build  yes

test.run        yes
test.target     check

set docdir      ${prefix}/share/doc/${my_name}-${version}

post-patch {
    reinplace "s|/usr/share/zsh|${prefix}/share/zsh|" ${worksrcpath}/Functions/Misc/run-help
}

post-destroot {
    # This manpage only includes every zsh manpage; as manpages are gzipped in MacPorts,
    # .so groff directives will fail.
    system "cd ${destroot}${prefix}/share/man/man1 && \
        soelim -I.. zshall.1 > zshall.1.soelim"
    move -force \
        ${destroot}${prefix}/share/man/man1/zshall.1.soelim \
        ${destroot}${prefix}/share/man/man1/zshall.1

    # Install helpfiles for shell builtins (for use by run-help) by
    # extracting them from the zshbuiltins manpage
    set helpdir ${prefix}/share/${my_name}/${version}/help
    xinstall -d ${destroot}${helpdir}
    system "cd ${destroot}${helpdir} && nroff -mandoc -Tascii -c ${destroot}${prefix}/share/man/man1/zshbuiltins.1 | colcrt - | perl ${worksrcpath}/Util/helpfiles"
    
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} ChangeLog FEATURES LICENCE NEWS README ${destroot}${docdir}

    if {[variant_isset doc] || [variant_isset examples]} {
        xinstall -d ${destroot}${docdir}/pdf
    }
}

notes "
If you want MacPorts' ${my_name} as login shell, you should run:
% sudo sh -c \"echo '${prefix}/bin/${my_name}' >> /etc/shells\"
% chsh -s ${prefix}/bin/${my_name}
"

platform darwin 8 {
    post-configure {
        # poll(2) is broken on Darwin 8.
        reinplace "s|#define HAVE_POLL 1|#undef HAVE_POLL|" \
          ${worksrcpath}/config.h
    }
}

variant mp_completion description {Install port(1) completion file} {
    post-destroot {
        set sitedir ${prefix}/share/${my_name}/site-functions
        xinstall -m 0644 ${filespath}/_port \
            ${destroot}${sitedir}
    }
}

variant pcre description {Add regular expressions support in builtin functions through PCRE} {
    configure.args-append   --enable-pcre
    depends_lib-append      port:pcre
}

variant doc description {Install extra documentation} {
    distfiles-append        [suffix ${distname}-doc]

    post-build {
        system "${build.cmd} -C ${worksrcpath}/Doc html info"
    }

    destroot.target-append  install.html \
                            install.info
}

variant examples description {Install configuration examples} {
    distfiles-append    ${love_distfile}:love
    extract.only-delete ${love_distfile}

    post-extract {
        system "tar xzf ${distpath}/${love_distfile} -C ${workpath}"
    }

    post-destroot {
        proc xinstall_dir {dir destdir} {
            xinstall -d ${destdir}

            foreach {file} [glob ${dir}/*] {
                if {[file isdirectory ${file}]} {
                    xinstall_dir ${file} [file join ${destdir} [file tail ${file}]]
                } else {
                    xinstall -m 0644 ${file} ${destdir}
                }
            }
        }

        xinstall -m 0644 ${worklovepath}/refcard.pdf ${destroot}${docdir}/pdf
        xinstall_dir ${worklovepath}/zsh_people ${destroot}${docdir}/examples
    }
}

livecheck.distname  ${my_name}-dev
