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

name                    py-lightblue
version                 0.4
revision                2
license                 GPL-3+
maintainers             nomaintainer
supported_archs         noarch

description             A cross-platform Python Bluetooth API
long_description        A cross-platform Python Bluetooth API for Mac OS X, \
                        GNU/Linux and Python For Series 60. Provides simple device \
                        and service discovery, RFCOMM sockets, L2CAP client \
                        sockets, OBEX file transfer, service advertising, and \
                        access to local device information.
platforms               darwin
homepage                http://lightblue.sourceforge.net/
master_sites            sourceforge:project/lightblue/lightblue/${version}
distname                lightblue-${version}
checksums               ${distname}${extract.suffix} \
                        md5     2f2bf66faa4bf1a79eb28a47584077b7 \
                        sha1    78331a3c1640f0e351f71774b576fef1d9d3951d \
                        rmd160  9eb520d354b3b95b8e324cf846a6cb5556a29056

python.versions         27

deprecated.upstream_support no

if {${name} ne ${subport}} {
    depends_lib-append  port:py${python.version}-pyobjc-cocoa

    patchfiles          patch-deviceInquiryComplete_error_aborted-signature.diff

    extract.only        lightblue-${version}.tar.gz

    if {${os.platform} eq "darwin" && ${os.major} >= 10} {

        distfiles-append LightAquaBlue-framework-MacOS10.6.zip LightAquaBlue-python-MacOS10.6.zip
        checksums-append LightAquaBlue-framework-MacOS10.6.zip \
                            md5     1a46f98ec2ff688bb6d23df02e91c052 \
                            sha1    f43accbcf4edf82553c12d3a809b03905a8777bf \
                            rmd160  0efeb78018bccc1d458bcdddd08d9ee20e439e83 \
                        LightAquaBlue-python-MacOS10.6.zip \
                            md5     a5eb3152039033ab100f4b855bd79478 \
                            sha1    220cafd2ee4f4cae46dd56454d02994c27c7eb4f \
                            rmd160  08aa939afe0be496af521e3e249732ad978e1f8c
        patchfiles-append patch-setup.py.diff

    # Extract LightAquaBlue-framework to replace existing version in tar archive
        post-extract {
            system "cd ${workpath}/${distname}/src/mac && rm -rf LightAquaBlue"
                system "cd ${workpath}/${distname}/src/mac && unzip ${distpath}/LightAquaBlue-framework-MacOS10.6.zip"
                system "cd ${workpath}/${distname}/src/mac && mv LightAquaBlue LightAquaBlue-xcode"
                system "cd ${workpath}/${distname}/src/mac && unzip ${distpath}/LightAquaBlue-python-MacOS10.6.zip"
        }

        post-patch {
            reinplace "s|/Library/Frameworks|${frameworks_dir}|g" \
                ${worksrcpath}/src/mac/LightAquaBlue/__init__.py
        }
    }

    if {${os.platform} eq "darwin" && ${os.major} >= 12} {
        # Fix #37361: use 10.7 SDK on 10.8 or later
        configure.sdkroot ${developer_dir}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
    }

    post-patch {
        reinplace "s|/Library/Frameworks|${frameworks_dir}|g" \
            ${worksrcpath}/setup.py \
            ${worksrcpath}/src/mac/_LightAquaBlue.py
        reinplace "s|DSTROOT=/|SDKROOT='${configure.sdkroot}' DSTROOT='${destroot}'|g" \
            ${worksrcpath}/setup.py
    }
} else {
    livecheck.regex /lightblue-(\[0-9.\]+)${extract.suffix}
}