# -*- 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
PortGroup           compiler_blacklist_versions 1.0

github.setup        ronaldoussoren pyobjc 10.1 v
revision            0

checksums           rmd160  4ed3e4de68817e52920dc72bc9d2a3e667c56b80 \
                    sha256  079c59f41c75c36fbbbc9b72f49b6afdaeedbc503f6263c9c8d7542303d93c89 \
                    size    25557538

name                py-pyobjc
categories-append   devel
license             MIT
maintainers         openmaintainer {danchr @danchr}

# https://pyobjc.readthedocs.io/en/latest/install.html
platforms           {darwin >= 13}

description         bidirectional bridge between python and Objective C
long_description    The PyObjC project aims to provide a bridge between \
                    the Python and Objective-C programming languages. The \
                    bridge is intended to be fully bidirectional, allowing \
                    the Python programmer to take full advantage of the \
                    power provided by various Objective-C based toolkits \
                    and the Objective-C programmer transparent access to \
                    Python based functionality.
homepage            https://pyobjc.readthedocs.io

python.versions     38 39 310 311 312

if {${name} ne ${subport}} {
    depends_lib-append \
                    port:py${python.version}-setuptools
    depends_build-append \
                    port:py${python.version}-sphinx \
                    port:py${python.version}-sphinxcontrib-blockdiag

    patchfiles-append \
                    patch-docs-conf.py.diff \
                    patch-pyobjc-core-setup.py.diff \
                    patch-setup-no-werror.diff \
                    patch-development-support-_install_tool.py-no-setup.diff

    # use system libffi on Catalina and Big Sur until upstream merges
    # and releases Apple's changes
    # https://trac.macports.org/ticket/62475
    if {${os.major} < 19} {
        depends_lib-append \
                    port:libffi
    }

    use_xcode                  yes
    compiler.blacklist-append  {clang < 900}

    post-patch {
        reinplace \
            "s/sphinx-build /sphinx-build-${python.branch} /g" \
            ${worksrcpath}/docs/Makefile

        # see comment above
        if {${os.major} < 19} {
            # force using both our libffi _and_ its headers
            reinplace \
                "s,/usr/include/ffi,${prefix}/include,g" \
                ${worksrcpath}/pyobjc-core/setup.py

            reinplace \
                "s,<ffi/ffi.h>,<ffi.h>,g" \
                ${worksrcpath}/pyobjc-core/Modules/objc/libffi_support.h
        } else {
            # force linking against system libffi by path, so that we
            # bypass CPython's dependency on it
            reinplace \
                "s,-lffi,${configure.sdkroot}/usr/lib/libffi.tbd,g" \
                ${worksrcpath}/pyobjc-core/setup.py
        }
    }

    if {${configure.sdkroot} eq ""} {
        if {${os.platform} eq "darwin" && ${os.major} == 13} {
            # Fix for 10.9: use SIMD headers from 10.10 SDK
            set sdkroot "${developer_dir}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk"
        } else {
            set sdkroot "/"
        }
    } else {
        set sdkroot ${configure.sdkroot}
    }

    build.env-append    SDKROOT=${sdkroot}
    destroot.env-append SDKROOT=${sdkroot}

    python.pep517       yes

    build.cmd-prepend   ${python.bin} ${filespath}/multibuild.py ${build.jobs}
    destroot.cmd-prepend \
                        ${python.bin} ${filespath}/multiinstall.py ${workpath}
    destroot.target

    # build the documentation
    post-build {
        system -W ${worksrcpath}/docs "make -j${build.jobs} html"
    }

    post-destroot {
        xinstall -m 644 -W ${worksrcpath}/pyobjc-core HISTORIC.txt Install.txt \
            License.txt README.txt \
            ${destroot}${prefix}/share/doc/${subport}
        copy ${worksrcpath}/docs/_build/html ${destroot}${prefix}/share/doc/${subport}/html
    }
}

# suppress release candidates
github.livecheck.regex  (\\d+(?:\\.\\d+)*)
