# -*- 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           github 1.0
PortGroup           cmake 1.1
PortGroup           legacysupport 1.1

# arc4random, strndup
legacysupport.newest_darwin_requires_legacy 10

github.setup        microsoft mimalloc 3.5.1 v
github.tarball_from archive

revision            0
categories          devel
license             MIT
maintainers         {makr @mohd-akram} openmaintainer

description         mimalloc is a compact general purpose allocator with \
                    excellent performance

long_description    mimalloc is a general purpose allocator with excellent \
                    performance characteristics.

checksums           rmd160  dcd5343fa1068d1fc92c7cf430fc02524de28af6 \
                    sha256  2602daad9b64b213a8835dee6fadda96d2081c0171bfcd3fb2db39bdc669d6b3 \
                    size    1443332

patchfiles          patch-cmake.diff

compiler.c_standard     2011
compiler.cxx_standard   2017
compiler.thread_local_storage   yes

configure.args-append \
                    -DMI_BUILD_TESTS=ON

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # Reduce stress for older systems
    configure.cppflags-append   -DNTHREADS=8
    # Turning on MI_OSX_INTERPOSE breaks the build with undefined symbols:
    # https://trac.macports.org/ticket/67220
    # https://github.com/microsoft/mimalloc/issues/779
    # Turning on MI_OSX_ZONE breaks test-stress with Bus error.
    configure.args-append \
                    -DMI_OSX_INTERPOSE=OFF \
                    -DMI_OSX_ZONE=OFF
    if {[string match *gcc* ${configure.compiler}]} {
        configure.args-append \
                    -DMI_USE_LIBATOMIC=ON
    }
}

# If built with MI_OSX_INTERPOSE=OFF MI_OSX_ZONE=OFF, realpath test case in test-api fails.
# https://github.com/microsoft/mimalloc/issues/778
test.run            yes
