# -*- 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.44.0
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  22ce3248a454c3e925efb903fd47562d47ed2872 \
                    sha256  07667d66a5d150abed9157ab6c0b9393c9356f229784a4385c02f99e94fc94d4 \
                    size    171880

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

    legacysupport.newest_darwin_requires_legacy \
                        17

    patchfiles-append   patch-ffi_Makefile.osx.diff

    set llvmver "15"

    if {${python.version} == 38} {
        version             0.41.1
        checksums           md5 4f58a46856bf2a82d8b661f1aa7b26ec \
                            rmd160 7e1e0cdfd9489f9385ec3d50c3e41d3114db47a4 \
                            sha256 f19f767a018e6ec89608e1f6b13348fa2fcde657151137cb64e56d48598a92db \
                            size   146564
        set llvmver "14"
    }

    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
    }

    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"
    }

    depends_lib-append  port:llvm-${llvmver} \
                        port:clang-${llvmver} \
                        port:zlib \
                        port:ncurses \
                        port:libxml2

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

    livecheck.type      none
}
