# -*- 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        ronaldoussoren pyobjc 10.3.2 v
github.tarball_from archive
revision            0

checksums           rmd160  4f132cbe41bbd24de26111ad671f990807deea48 \
                    sha256  024d7205a5d2ee43fe7b230d325d7ea176db50033a7532d618f844f9571ac7bd \
                    size    20423020

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     39 310 311 312 313 314

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
    }

    compiler.blacklist-append  {clang < 900}

    # Quartz module uses CGWindowListCreateImageFromArray which is no longer available on macOS 15
    # See https://trac.macports.org/ticket/71103
    if {${os.platform} eq "darwin" && [vercmp ${macosx_deployment_target} >= 15.0]} {
        macosx_deployment_target 14.0
    }

    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+)*)
