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

github.setup            google leveldb 1.23
github.tarball_from     archive
revision                1
categories              databases

license                 BSD
maintainers             nomaintainer

description             A fast and lightweight key/value database library by Google
long_description        {*}${description}

checksums               rmd160  6a8834f071cd2866a5bee707094caea0f90274c0 \
                        sha256  9a37f8a6174f09bd622bc723b55881dc541cd50747cbd08831c2a82d620f6d76 \
                        size    242925

depends_lib             port:snappy

compiler.cxx_standard   2011

# Need O_CLOEXEC
legacysupport.newest_darwin_requires_legacy 10

configure.args-append   -DBUILD_SHARED_LIBS=ON \
                        -DLEVELDB_BUILD_TESTS=OFF \
                        -DLEVELDB_BUILD_BENCHMARKS=OFF

variant tmalloc description {use tmalloc from gperftools} {
    depends_lib-append  port:gperftools
}

# it picks tmalloc when gperftools is enabled which leads to crashes
# See:
#  - https://trac.macports.org/ticket/56164
#  - https://trac.macports.org/ticket/56288
if {![variant_isset tmalloc]} {
    conflicts           gperftools
}

variant rtti description {build with RTTI} {
    post-patch {
        reinplace "s|-fno-rtti|-frtti|" ${worksrcpath}/CMakeLists.txt
    }
}

default_variants-append +rtti

if {[variant_isset rtti]} {
    # See: https://github.com/google/leveldb/issues/731
    notes-append "
Before version 1.23 leveldb has RTTI and a lot of code uses typeid.\
Version 1.23 disables RTTI which lead to broken things from plyvel to ceph.\
We re-enable RTTI by default, if you wish to disable it switch off rtti variant by:
   port upgrade --enforce-variants leveldb -rtti"
}

variant memenv description {Expose internal memenv API} {
    post-destroot {
        xinstall -m 755 -d ${destroot}${prefix}/include/helpers/memenv
        xinstall -m 644 ${worksrcpath}/helpers/memenv/memenv.h ${destroot}${prefix}/include/helpers/memenv/
        ln -s libleveldb.dylib ${destroot}${prefix}/lib/libmemenv.dylib
    }
}

default_variants-append +memenv

if {[variant_isset memenv]} {
    # See: https://trac.macports.org/ticket/68132
    notes-append "
Before version 1.21 leveldb exposed helpers/memenv/memenv.h and some code uses it.\
Version 1.21 prevent that which lead to broken things like qtwebkit.\
We re-enable exposing memenv by default, if you wish to disable it switch off memenv variant by:
   port upgrade --enforce-variants leveldb -memenv"
}