# -*- 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        numba llvmlite 0.36.0 v
name                py-llvmlite
revision            0
categories-append   devel science
platforms           darwin
license             BSD

python.versions     27 35 36 37 38 39

maintainers         {stromnov @stromnov} openmaintainer

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

homepage            http://llvmlite.pydata.org/

checksums           rmd160  536800f1a3eb17976c75f12aa36c5e81e6c6a93b \
                    sha256  4456512490b24d2f614058d1e14fa947eba1c3ca2c30776f99cc22b34ae7feee \
                    size    232080

if {${name} ne ${subport}} {
    patchfiles-append   patch-ffi_Makefile.osx.diff

    if {${python.version} <= 35} {
        set llvmver "8.0"
    } else {
        set llvmver "10"
    }

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

        if {${python.version} > 35 && ${os.major} <= 10} {
            # https://trac.macports.org/ticket/61302
            reinplace "s|%%MP_EXTRA_LDFLAGS%%|-framework CoreFoundation|" \
                ${worksrcpath}/ffi/Makefile.osx
        } else {
            reinplace "s|%%MP_EXTRA_LDFLAGS%%||" ${worksrcpath}/ffi/Makefile.osx
        }
    }

    depends_build-append \
                        port:py${python.version}-setuptools \
                        port:clang-${llvmver}

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

    if {${python.version} <= 35} {
        github.setup        numba llvmlite 0.31.0 v
        revision            0
        checksums           rmd160  72cbabced6a93db7232a6a6d652e56993887f5d3 \
                            sha256  fe4b36661f050565e73e07d0c31ee47bd2b44602e0bf17d4a19d3d7d0d2c60f4 \
                            size    199646

        if {${python.version} < 34} {
            depends_lib-append  port:py${python.version}-enum34
        }
    }

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

    livecheck.type      none
} else {
    livecheck.name      ${python.rootname}
    livecheck.url       https://pypi.org/pypi/${livecheck.name}/json
    livecheck.type      regex
    livecheck.regex     {"version":"([^"]+)"[,\}]}
}
