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

name                py-pyobjc
github.setup        ronaldoussoren pyobjc 12.1 v
github.tarball_from archive
revision            3

checksums           rmd160  cbdc2f1196550902a9b5baf722d9ce637627e973 \
                    sha256  a2fccda7d919be66df07b3150a1510bf6d0091be920f2c81715ab4a6431265a4 \
                    size    13709554

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

use_parallel_build  no

if {${name} ne ${subport}} {
    depends_patch-append \
                    port:python${python.version}

    patchfiles-append \
                    patch-pybojc_setup.py.diff \
                    patch-pyobjc-core_setup.py.diff \
                    patch-skip-unsupported-frameworks.diff

    # get rid of the "-fdisable-block-signature-string" flag
    patchfiles-append \
                    patch-pyobjc-core_Modules_objc_test_block2.m.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.platform} eq "darwin" && ${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 {
        # after patching pyobjc-core/Tools/pyobjc_setup.py run the script
        # "development-support/update-shared-files"
        system -W ${worksrcpath} "${python.bin} development-support/update-shared-files"

        # see comment above
        if {${os.platform} eq "darwin" && ${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}

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

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

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