# $Id: Portfile 119743 2014-05-05 13:51:35Z mmoll@macports.org $

PortSystem 1.0
PortGroup cmake 1.0
PortGroup python 1.0

set realname        shiboken
name                py-${realname}
version             1.2.2
revision            1
python.versions     26 27 32 33 34
python.default_version 27
categories-append   devel
maintainers         openmaintainer mmoll
license             LGPL
description         Plugin for generatorrunner that generates python bindings \
                    for C++ libraries
long_description    Shiboken is a plugin (front-end) for generatorrunner that \
                    generates python bindings for C++ libraries using CPython \
                    source code.
homepage            http://qt-project.org/wiki/PySide
platforms           darwin
master_sites        http://download.qt-project.org/official_releases/pyside

checksums           md5     9f5bee9d414ce51be07ff7a20054a48d \
                    rmd160  19c8ea09d552bf371668cd8359d9602f5ac13634 \
                    sha1    55731616791500750ef373f382057a43e133fa08
distname            ${realname}-${version}
use_bzip2           yes

if {${name} ne ${subport}} {
    pre-patch {
        # MacOS cannot have a file and directory with the same name, as occurs here
        system "mv -v '${worksrcpath}/generator/shiboken' '${worksrcpath}/generator/shiboken.d'"
        reinplace "s|3.2 3.1 3.0|${python.branch}|g" ${worksrcpath}/cmake/Modules/FindPython3Libs.cmake
        reinplace "s|NAMES python3.2mu python3.2m python3.2u python3.2 python3.1 python3.0 python3|NAMES python${python.branch}|g" ${worksrcpath}/cmake/Modules/FindPython3Interp.cmake
    }

    patchfiles          default_visibility.patch \
                        filename_collision.patch

    depends_lib-append  port:qt4-mac \
                        port:python${python.version} \
                        port:libxslt \
                        port:sparsehash
    use_configure   yes
    configure.args-append -DBUILD_TESTS:BOOL=FALSE \
                    -DPYTHON_EXECUTABLE=${python.bin} \
                    -DPYTHON_LIBRARIES=${python.lib} \
                    -DPYTHON_INCLUDE_DIR=${python.include} \
                    -DPYTHON_SITE_PACKAGES=${python.pkgd} \
                    -DSPARSEHASH_INCLUDE_PATH=${prefix}/include
    if {${python.version} >= 30} {
        configure.args-append -DUSE_PYTHON3:BOOL=TRUE -DPYTHON3_LIBRARY=${python.lib} -DPYTHON3_INCLUDE_DIR=${python.include}
    }
    build.cmd       make
    build.target    all
    destroot.cmd    make
    destroot.destdir DESTDIR=${destroot}
    post-destroot {
        move ${destroot}${prefix}/bin/shiboken ${destroot}${prefix}/bin/shiboken-${python.branch}
        move ${destroot}${prefix}/include/shiboken ${destroot}${prefix}/include/shiboken-${python.branch}
        move ${destroot}${prefix}/share/man/man1/shiboken.1 ${destroot}${prefix}/share/man/man1/shiboken-${python.branch}.1
        if {${python.version} < 30} {
            file delete ${destroot}${prefix}/lib/cmake/Shiboken-${version}/ShibokenConfig-python${python.branch}.cmake
        } else {
            file delete ${destroot}${prefix}/lib/cmake/Shiboken-${version}/ShibokenConfig.cpython-${python.version}m.cmake
        }
        file delete ${destroot}${prefix}/lib/cmake/Shiboken-${version}/ShibokenConfig.cmake
        file delete ${destroot}${prefix}/lib/cmake/Shiboken-${version}/ShibokenConfigVersion.cmake
        file delete ${destroot}${prefix}/lib/pkgconfig/shiboken.pc
    }
}

if {${name} eq ${subport}} {
    livecheck.type      regex
    livecheck.url       http://qt-project.org/wiki/PySideDownloads
    livecheck.regex     ${realname}-(\[0-9.\]+)\\.tar\\.bz2
} else {
    livecheck.type      none
}
