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

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup    protobuf-c protobuf-c 1.5.2 v
revision        3
categories      devel
license         BSD
maintainers     nomaintainer
description     Pure C code generator and runtime libraries for Protocol Buffers

long_description \
                ${name} is a C implementation of the Google \
                Protocol Buffers data serialization format. It \
                includes libprotobuf-c, a pure C library that \
                implements protobuf encoding and decoding, and \
                protoc-c, a code generator that converts Protocol \
                Buffer .proto files to C descriptor code, based \
                on the original protoc.

checksums       sha256  e2c86271873a79c92b58fef7ebf8de1aa0df4738347a8bd5d4e65a80a16d0d24 \
                rmd160  7a24dec822f4753232c09c4367655cefb8d6ade6 \
                size    532447
github.tarball_from releases

patch.pre_args-replace  -p0 -p1

# https://github.com/protobuf-c/protobuf-c/pull/797
patchfiles      protobuf-34.patch

use_autoreconf  yes
autoreconf.args -fiv

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

depends_lib-append \
                port:abseil \
                port:protobuf

compiler.cxx_standard 2017

configure.optflags

# error: constexpr constructor never produces a constant expression [-Winvalid-constexpr]
compiler.blacklist-append {clang < 900}

configure.args-append \
                --disable-silent-rules

variant cxx17 conflicts cxx20 description "Use C++17" {
    require_active_variants protobuf cxx17
}

variant cxx20 conflicts cxx17 description "Use C++20" {
    require_active_variants protobuf cxx20
    compiler.cxx_standard   2020
    # github.com/protobuf-c/protobuf-c/issues/776
    patchfiles-append       patch-cxx20.diff
    configure.cxxflags-append \
                            -std=c++20
}

if ![variant_isset cxx17] {
    default_variants +cxx20
}

if [variant_isset debug] {
    post-patch {
        reinplace "s|-lprotoc|-lprotocd|" ${worksrcpath}/Makefile.am
    }
}

test.run        yes
test.target     check
