# -*- 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.3.2 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  b0f0fa75ab8aed7305deba2e328a4273cd50d4d5 \
                    sha256  ca02384e007f46950598500dfaebde5ff9948c1d231f5a81b058799afa64bbbb \
                    size    1410297

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
    patchfiles-append \
                    patch-test-stress.diff
    # 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
