# -*- 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
# $Id: Portfile 119820 2014-05-07 18:22:50Z sean@macports.org $

PortSystem          1.0
PortGroup           python 1.0
PortGroup           app 1.0
PortGroup           bitbucket 1.0

bitbucket.setup     tortoisehg thg 3.0
name                tortoisehg
categories          devel python
platforms           darwin
license             GPL-2+
maintainers         sean openmaintainer
supported_archs     noarch

description         A set of graphical tools for Mercurial

long_description    A set of graphical tools for the Mercurial distributed \
                    revision control system.

checksums           rmd160  25e9e822edef9f55f56e6e4b0d8927a702823ebb \
                    sha256  70c5825c86f882eeb1b4b6343de60366249fc639d5dea4d95441b1db29fe3d74

python.default_version 27

# Can use either py*-pyqt4 or py*-pyqt4-devel. Also mercurial or
# mercurial-devel.
depends_lib         path:bin/hg:mercurial \
                    path:share/py${python.version}-sip/PyQt4:py${python.version}-pyqt4 \
                    port:py${python.version}-qscintilla \
                    port:py${python.version}-iniparse

depends_build       port:py${python.version}-sphinx

post-extract {
    copy ${filespath}/config.py ${worksrcpath}/tortoisehg/util/
}

patchfiles          patch-setup.py.diff

post-patch {
    reinplace "s|{prefix}|${prefix}|" ${worksrcpath}/tortoisehg/util/config.py
    reinplace "s|{python.prefix}|${python.prefix}|" ${worksrcpath}/tortoisehg/util/config.py

    foreach f [glob -type f \
                   ${worksrcpath}/thg \
                   ${worksrcpath}/contrib/hg \
                   ${worksrcpath}/contrib/*.py \
                   ${worksrcpath}/i18n/*.py] {
        reinplace "s,#! */usr/bin/env python,#!${python.bin}," $f
    }
}

python.link_binaries_suffix

post-destroot {
    system -W ${worksrcpath}/doc "make SPHINXBUILD=sphinx-build-${python.branch} html"
    copy ${worksrcpath}/doc/build/html ${destroot}${prefix}/share/doc/${name}/html

    xinstall -m 644 -W ${worksrcpath} COPYING.txt ${destroot}${prefix}/share/doc/${name}
}

app.name            TortoiseHg
app.executable      ${workpath}/${app.name}
app.icon            icons/thg_logo_92x50.png

platform macosx {
    post-extract {
        copy ${filespath}/${app.name}.in ${workpath}/${app.name}
    }
    post-patch {
        reinplace "s|@PREFIX@|${prefix}|g" ${workpath}/${app.name}
    }
}
