# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 80867 2011-07-19 21:49:38Z jmr@macports.org $

PortSystem          1.0
PortGroup           python26 1.0

name                mercurial
version             1.9
categories          devel python
license             GPL-2+
maintainers         deric
description         A fast, lightweight, distributed SCM system written in \
                    Python.
long_description    Mercurial is a fast, lightweight Source Control Management \
                    system designed for efficient handling of very large \
                    distributed projects. A distributed SCM tool is designed \
                    to support a model in which each Repository is loosely \
                    coupled to many others. Each Repository contains a \
                    complete set of metadata describing one or more projects. \
                    These repositories may be located almost anywhere. \
                    Individual developers only need access to their own \
                    repositories, not to a central one, in order to commit \
                    changes. Changes can be share via the builtin webserver, \
                    CGI, SSH or a stream of patch emails. Mercurial supports \
                    Apples' FileMerge for merges.

homepage            http://www.selenic.com/mercurial/
platforms           darwin
master_sites        http://mercurial.selenic.com/release/
checksums           md5     d4842129fa2732eb6ed1180467bc32e2 \
                    sha1    e7d80abf520849e1327ad5e7606a09628f646584 \
                    rmd160  f533234095f2028ef742dce96a23751ee023a7f1
depends_run         port:curl-ca-bundle

post-patch {
    if {[variant_isset universal]} {
        reinplace "s/-arch i386 -arch x86_64/${configure.universal_cflags}/" ${worksrcpath}/setup.py
    } else {
        reinplace "s/-arch i386 -arch x86_64/${configure.cc_archflags}/" ${worksrcpath}/setup.py
    }
}

post-destroot {
    # configure ssl certificates
    xinstall -d -m 755 ${destroot}${prefix}/etc/mercurial
    xinstall -m 644 ${filespath}/hgrc \
        ${destroot}${prefix}/etc/mercurial/hgrc
    reinplace "s|%%PREFIX%%|${prefix}|g" \
        ${destroot}${prefix}/etc/mercurial/hgrc

    # install html docs
    xinstall -m 644 -W ${worksrcpath}/doc hg.1.html hgrc.5.html hgignore.5.html \
            ${destroot}${prefix}/share/doc/${name}

    # install man pages
    xinstall -m 444 -W ${worksrcpath}/doc hg.1 \
        ${destroot}${prefix}/share/man/man1
    xinstall -m 444 -W ${worksrcpath}/doc hgrc.5 hgignore.5 \
        ${destroot}${prefix}/share/man/man5

    # install contrib
    xinstall -d -m 755 ${destroot}${prefix}/share/${name}
    file copy ${worksrcpath}/contrib ${destroot}${prefix}/share/${name}/contrib

    # copy hgweb.cgi hgwebdir.cgi
    file copy ${worksrcpath}/hgweb.cgi ${destroot}${prefix}/share/${name}/

    if {[variant_isset bash_completion]} {
        xinstall -d ${destroot}${prefix}/etc/bash_completion.d
        copy ${worksrcpath}/contrib/bash_completion ${destroot}${prefix}/etc/bash_completion.d/mercurial
    }

    if {[variant_isset zsh_completion]} {
        set site-functions ${destroot}${prefix}/share/zsh/site-functions
        xinstall -d ${site-functions}
        xinstall ${worksrcpath}/contrib/zsh_completion ${site-functions}/_mercurial
    }
}

variant bash_completion {
    depends_run-append port:bash-completion
}

variant zsh_completion description {Install mercurial zsh completion file} {
    depends_run-append path:${prefix}/bin/zsh:zsh
}

python.link_binaries_suffix

livecheck.url   http://mercurial.selenic.com/release/
livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
