# -*- 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.1.5 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  ade266c7c93bb56500b7a8aebb65edda00ded85d \
                    sha256  1c6949032069d5ebea438ec5cedd602d06f40a92ddf0f0d9dcff0993e5f6635c \
                    size    1306337

patchfiles          patch-cmake.diff

compiler.cxx_standard   2017
compiler.c_standard     2011

configure.args-append \
                    -DMI_BUILD_TESTS=ON
# Ensure test binaries can find dylibs
configure.pre_args-replace \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

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
