# -*- 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$

PortSystem          1.0
PortGroup           python 1.0
PortGroup           app 1.0
PortGroup           bitbucket 1.0

bitbucket.setup     tortoisehg thg 3.9.2
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 \
                    source control management system.

checksums           rmd160  223d8fb251d6bf47bdfed17e038a4d26893297c0 \
                    sha256  67d42ef865519bd6675a34aa3750e5df3a48611da907108508bdbb8fd94dfbff

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/
    reinplace -W ${worksrcpath} "s,pyrcc4,pyrcc4-2.7," setup.py
}

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
    }
}

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}
    }
}