# -*- 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           muniversal 1.1

name                jemalloc
license             BSD
categories          devel
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer

description         a general-purpose scalable concurrent malloc(3) implementation
long_description    ${name} is {*}${description}

homepage            https://jemalloc.net

if {${subport} eq ${name}} {
    github.setup        jemalloc jemalloc 5.3.0
    revision            4
    conflicts           jemalloc-devel
    checksums           rmd160  ff8f2958d88705927b7566d219763dda2eb7edda \
                        sha256  2db82d1e7119df3e71b7640219b6dfe84789bc0537983c3b7ac4f7189aecfeaa \
                        size    736023
    github.tarball_from releases
    use_bzip2           yes

    patchfiles-append   patch-quantum.diff \
                        patch-Makefile.diff

    # building as x86_64 on an arm64 Mac gives an error if rosetta is installed
    # https://trac.macports.org/ticket/65671
    patchfiles-append   patch-universal.diff
}

subport jemalloc-devel {
    github.setup        jemalloc jemalloc 3688dfb5c3b7d94a12e18b753c0fc9c405b77b1f
    version             2025.03.21
    conflicts           jemalloc
    checksums           rmd160  ca3eb3064b18c398642954a8fed4dc327ab5ce4b \
                        sha256  000f18e4463f8300c10c5de995214a0b03cd0c3560703683cc91f4aabbf260c4 \
                        size    877720
    github.tarball_from archive

    use_autoreconf      yes
    # autoheader: warning: missing template: LIMIT_USIZE_GAP
    # autoheader: warning: Use AC_DEFINE([LIMIT_USIZE_GAP], [], [Description])
    # autoreconf: error: /opt/local/bin/autoheader failed with exit status: 1
    autoreconf.cmd      ./autogen.sh
    autoreconf.args
    depends_build-append \
                        port:autoconf \
                        port:automake \
                        port:libtool
}

compiler.cxx_standard   2014

configure.args-append   --with-jemalloc-prefix=

# provide a compatibility symlink with the older name
post-destroot {
    ln -s jeprof ${destroot}${prefix}/bin/jemalloc-prof
}

test.run            yes
test.target         check
