# -*- 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           gitlab 1.0
PortGroup           legacysupport 1.1
PortGroup           makefile 1.0

# posix_memalign
# https://trac.macports.org/ticket/62272
legacysupport.newest_darwin_requires_legacy 9

gitlab.setup        openldap openldap 0.9.33 LMDB_
name                lmdb
revision            0

checksums           rmd160  8a440438118d10d489fb6f3ea39e3052e9160941 \
                    sha256  bfd085edd5940925140484d757b92d10d19c09438b775c22ccc85b0cdd4b4279 \
                    size    121151

categories          databases
maintainers         {@artkiver gmail.com:artkiver} openmaintainer
license             OpenLDAP-2.8+

description         Symas Lightning Memory-Mapped Database (LMDB)

long_description    LMDB is an ultra-fast, ultra-compact key-value embedded data \
                    store developed by Symas for the OpenLDAP Project. It uses \
                    memory-mapped files, so it has the read performance of a \
                    pure in-memory database while still offering the persistence \
                    of standard disk-based databases, and is only limited to the \
                    size of the virtual address space, (it is not limited to the \
                    size of physical RAM). Note: LMDB was originally called MDB, \
                    but was renamed to avoid confusion with other software \
                    associated with the name MDB.

homepage            https://symas.com/lmdb/

build.dir           ${worksrcpath}/libraries/liblmdb

makefile.prefix_name \
                    prefix
makefile.override-append \
                    CFLAGS \
                    PREFIX

post-destroot {
    # Install pkg-config .pc file because Linux distributions have done
    # so and other software now depends on this but the developer of
    # lmdb refuses to add it to their source distribution.
    # See https://bugs.openldap.org/show_bug.cgi?id=9457
    set pc ${destroot}${prefix}/lib/pkgconfig/lmdb.pc
    xinstall -m 0644 ${filespath}/lmdb.pc.in ${pc}
    reinplace "s|@HOMEPAGE@|${homepage}|g;s|@PREFIX@|${prefix}|g;s|@VERSION@|${version}|g" ${pc}

    # Install additional documentation
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${build.dir} \
        CHANGES COPYRIGHT LICENSE \
        ${destroot}${docdir}
}

platform darwin {
    build.args-append \
                    SOEXT=.dylib

    destroot.args-append \
                    SOEXT=.dylib

    post-destroot {
        set dylib ${prefix}/lib/liblmdb.dylib
        system "install_name_tool -id ${dylib} ${destroot}${dylib}"
    }
}

livecheck.type      regex
livecheck.url       https://git.openldap.org/openldap/openldap/-/tags/
livecheck.regex     "LMDB_(\\d+(?:\\.\\d+)*)"
