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

name                py-llvmlite
version             0.45.1
categories-append   devel science
license             BSD

python.versions     39 310 311 312 313

maintainers         {stromnov @stromnov} openmaintainer

description         A lightweight LLVM python binding for writing JIT compilers
long_description    {*}${description}

homepage            https://llvmlite.pydata.org/

checksums           rmd160  64cd3e620423504a50cba35c8fdeb56c1ef6823a \
                    sha256  09430bb9d0bb58fc45a45a57c7eae912850bedc095cd0810a57de109c69e1c32 \
                    size    185600

if {${name} ne ${subport}} {
    PortGroup           legacysupport 1.1
    PortGroup           compiler_wrapper 1.0

    legacysupport.newest_darwin_requires_legacy \
                        17

    if {${python.version} == 39} {
        version             0.43.0
        checksums           rmd160  ea30be9de2f72c27635c4858968b95d1ec3ebaec \
                            sha256  ae2b5b5c3ef67354824fb75517c8db5fbe93bc02cd9671f3c62271626bc041d5 \
                            size    157069

        set llvmver         "15"

        depends_lib-append  port:llvm-${llvmver} \
                            port:clang-${llvmver} \
                            port:ncurses \
                            port:libxml2
        patchfiles-append   patch-ffi_Makefile.osx.diff

        post-patch {
            reinplace "s|%%CXX%%|clang++-mp-${llvmver}|" ${worksrcpath}/ffi/Makefile.osx

            if {${os.major} <= 10} {
                # https://trac.macports.org/ticket/61302
                configure.ldflags-append \
                            -framework CoreFoundation
            } elseif {${os.major} >= 22} {
                configure.ldflags-append \
                            -lLLVM
            }

            reinplace "s|%%MP_EXTRA_LDFLAGS%%|${configure.ldflags}|" ${worksrcpath}/ffi/Makefile.osx
        }

        build.env-append    LLVM_CONFIG=llvm-config-mp-${llvmver}                        
        destroot.env-append LLVM_CONFIG=llvm-config-mp-${llvmver}

        post-destroot {
            system "/usr/bin/install_name_tool -change @rpath/libLLVM.dylib ${prefix}/libexec/llvm-${llvmver}/lib/libLLVM.dylib ${destroot}${python.pkgd}/llvmlite/binding/libllvmlite.dylib"
        }
    } else {
        set llvmver         "20"

        depends_build-append \
                            path:bin/cmake:cmake

        depends_lib-append  port:llvm-${llvmver} \
                            port:zstd

        build.env-append    LLVM_DIR=${prefix}/libexec/llvm-${llvmver}/lib/cmake/
    }

    depends_lib-append  port:zlib

    livecheck.type      none
}
