# -*- 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 90012 2012-02-19 18:31:37Z phw@macports.org $

PortSystem          1.0
PortGroup           python 1.0

name                py-sip
version             4.13.2
revision            0
python.versions     24 25 26 27 31 32
python.default_version 24
categories          python devel
maintainers         phw openmaintainer
license             {GPL-2 GPL-3 PSF}
platforms           macosx

description         create Python bindings for C and C++ libraries
long_description \
    SIP is a tool that makes it very easy to create \
    Python bindings for C and C++ libraries. \
    It was originally developed to create PyQt, \
    the Python bindings for the Qt toolkit, \
    but can be used to create bindings for any \
    C or C++ library.

homepage            http://www.riverbankcomputing.co.uk/software/sip/intro

if {$subport != $name} {
    master_sites \
        http://www.riverbankcomputing.com/static/Downloads/sip4/ \
        http://gentoo.mirrors.easynews.com/linux/gentoo/distfiles/ \
        http://gentoo.osuosl.org/distfiles/ \
        http://www.gtlib.gatech.edu/pub/gentoo/distfiles/

    distname            sip-${version}

    checksums           rmd160  24a8e7c4bd36382594ea3f11317eb0f10e4e56ea \
                        sha256  4bc3f5353c75918e1c8499ec1474e7b3392c30513ea6d7a6334f88b88271eebf
    patchfiles          patch-siputils.py.diff

    use_configure       yes
    pre-configure {
        # Ensure correct compilers are used
        reinplace "s| cc\$| ${configure.cc}|" \
            ${worksrcpath}/specs/macx-g++
        reinplace "s| c++\$| ${configure.cxx}|" \
            ${worksrcpath}/specs/macx-g++
    }

    post-configure {
# fix sip bin name
       reinplace "s|bin/sip|bin/sip-${python.branch}|g" \
         ${worksrcpath}/sipconfig.py
    }

    configure.cmd       ${python.bin} configure.py
    configure.pre_args  -d ${python.bin} \
                        -e ${python.include} \
                        -v ${prefix}/share/sip \
                        -p macx-g++ \
                        --bindir=${prefix}/bin \
                        --destdir=${python.pkgd} \
                        --incdir=${python.include} \
                        --sipdir=${prefix}/share/${subport}

    configure.post_args LFLAGS="-F${prefix}/Library/Frameworks -L${prefix}/lib"

    python.add_archflags    no
    if {[variant_isset universal]} {
        foreach arch ${configure.universal_archs} {
            configure.args-append   "--arch=${arch}"
        }
        configure.universal_args
        configure.post_args LFLAGS="-F${frameworks_dir} -L${prefix}/lib \
                                    ${configure.universal_ldflags}"
        configure.post_args-append  CFLAGS="${configure.universal_cflags}"
        configure.post_args-append  CXXFLAGS="${configure.universal_cxxflags}"
    }

    switch ${os.major} {
        8   { configure.args-append   "--sdk=${developer_dir}/SDKs/MacOSX10.4u.sdk" }
        9   { configure.args-append   "--sdk=${developer_dir}/SDKs/MacOSX10.5.sdk" }
        10  { configure.args-append   "--sdk=${developer_dir}/SDKs/MacOSX10.6.sdk" }
        11  { configure.args-append   "--sdk=${developer_dir}/SDKs/MacOSX10.7.sdk" }
    }

    build.cmd           make
    build.target        all

    test.run    yes
    test.cmd    cd siplib && ${python.bin} -c 'import sip'

    destroot.cmd        make
    destroot.destdir    DESTDIR=${destroot}

    post-destroot {
        xinstall -m 755 -d ${destroot}${prefix}/share/doc
        file copy ${worksrcpath}/doc ${destroot}${prefix}/share/doc/${subport}
        xinstall -m 644 -W ${worksrcpath} LICENSE LICENSE-GPL2 LICENSE-GPL3 NEWS README \
            ${destroot}${prefix}/share/doc/${subport}
        move ${destroot}${prefix}/bin/sip ${destroot}${prefix}/bin/sip-${python.branch}
        system "${python.bin} ${python.libdir}/compileall.py ${destroot}${prefix}"
        system "${python.bin} -O ${python.libdir}/compileall.py ${destroot}${prefix}"
    }

    notes "${subport} is available under a PSF license with one addition: \n
    4. Licensee may not use SIP to generate Python bindings for any C or
       C++ library for which bindings are already provided by Riverbank. \n
GPL-2 or GPL-3 licenses are also available. For details see
${prefix}/share/doc/${subport}/LICENSE \[-GPL2 -GPL3\]\n\n"

    livecheck.type      none
} else {
    livecheck.url       http://www.riverbankcomputing.co.uk/software/sip/download
    livecheck.regex     sip-(\\d+(\\.\\d+)+)${extract.suffix}
}

