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

PortSystem          1.0
PortGroup           python 1.0
PortGroup           github 1.0

github.setup        pyside Shiboken 1.2.4
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
name                py-shiboken
revision            2

categories-append   devel
maintainers         nomaintainer
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.

checksums           rmd160  efcfb5820bb85360e1c8c045ae2cfdea8d6e81f3 \
                    sha256  cf634ad51e9b0538c4283dbbf5e86268db793552364a03735c51299bc36ee4e4 \
                    size    1039570

python.versions     39 310 311

if {${name} ne ${subport}} {
    PortGroup       cmake 1.1
    PortGroup       qt4 1.0

    pre-patch {
        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 \
                        patch-cmakepkgconfig.diff \
                        patch-tpprint-py3.patch

    if {${python.version} >= 311} {
        patchfiles-append \
                        patch-py311-compatibility.diff
    }

    depends_lib-append  port:python${python.version} \
                        port:libxslt \
                        port:sparsehash
    use_configure   yes
    compiler.cxx_standard 2011
    configure.cxxflags-append -std=c++11
    # build.cmd must be set before configure.args is changed
    #    (see https://github.com/macports/macports-ports/commit/63c9c8e6e312c8e36603cb118d94f995aa8a6e67)
    build.cmd       make
    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 \
                    -DPYTHONBRANCH=${python.branch} \
                    -DPYTHONPREFIX=${python.prefix}
    if {${python.version} >= 30} {
        configure.args-append -DUSE_PYTHON3:BOOL=TRUE -DPYTHON3_LIBRARY=${python.lib} -DPYTHON3_INCLUDE_DIR=${python.include}
    }
    build.target    all
    destroot.cmd    make
    destroot.target  install
    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
        move ${destroot}${prefix}/lib/cmake ${destroot}${python.prefix}/lib/cmake
        move ${destroot}${prefix}/lib/pkgconfig ${destroot}${python.prefix}/lib/pkgconfig
    }
}
