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

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup        mongodb mongo-c-driver 1.26.2
checksums           rmd160  e114fd6e6e12f63fa250d017fa316ce4e9602f06 \
                    sha256  7084c488a758bf226cc0b3d500e7e001f0e2e37391cbeecd341050a9a899857d \
                    size    7318005

categories          devel
maintainers         {ryandesign @ryandesign} openmaintainer
license             Apache-2

# As of 1.25.0 a release download is no longer provided.
github.tarball_from archive

# It cannot figure out its own version when not in a git repository.
# https://jira.mongodb.org/browse/CDRIVER-4767
configure.args-append \
                    -DBUILD_VERSION=${version}

configure.args-append \
                    -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF \
                    -DENABLE_EXAMPLES=OFF \
                    -DENABLE_TESTS=OFF \
                    -DENABLE_UNINSTALL=OFF \
                    -DMONGO_USE_CCACHE=OFF

if {${subport} eq ${name}} {
    revision        0

    categories-append \
                    databases

    homepage        http://mongoc.org/libmongoc/${version}/

    description     library for using mongodb from C code

    long_description \
                    ${subport} provides libmongoc, a ${description}.

    depends_build-append \
                    path:bin/pkg-config:pkgconfig

    depends_lib-append \
                    port:cyrus-sasl2 \
                    port:libbson \
                    port:snappy \
                    port:zlib

    # bson-dsl.h: error: thread-local storage not supported for this target
    compiler.thread_local_storage yes

    # mongoc-log.c: error: implicit declaration of function 'pthread_threadid_np'
    patchfiles-append \
                    pthread_threadid_np.patch

    configure.args-append \
                    -DENABLE_MONGOC=ON \
                    -DENABLE_SASL=CYRUS \
                    -DENABLE_SNAPPY=ON \
                    -DENABLE_ZLIB=SYSTEM \
                    -DUSE_SYSTEM_LIBBSON=TRUE

    # error: implicit declaration of function 'SecKeyCreateSignature' is invalid in C99
    if {${os.platform} eq "darwin" && ${os.major} >= 16} {
        configure.args-append \
                    -DENABLE_SSL=DARWIN
    } else {
        depends_lib-append \
                    path:lib/libssl.dylib:openssl
        configure.args-append \
                    -DENABLE_SSL=OPENSSL
    }

    github.livecheck.regex \
                    {([0-9.]+)}
} else {
    livecheck.type  none
}

subport libbson {
    revision        0

    homepage        http://mongoc.org/${subport}/${version}/

    description     library for using BSON documents

    long_description \
                    ${subport} is a library providing useful routines related \
                    to building, parsing, and iterating BSON documents.

    patchfiles-append \
                    aligned_alloc.patch \
                    libbson.patch

    configure.args-append \
                    -DENABLE_BSON=ON \
                    -DENABLE_MONGOC=OFF
}