# -*- 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       compiler_blacklist_versions 1.0
PortGroup       python 1.0
PortGroup       github 1.0

name            py-protobuf3
version         3.14.0
revision        0
categories-append   devel
maintainers     {toby @tobypeterson} openmaintainer
license         BSD
description     Encode data in an efficient yet extensible format.

long_description \
                Google Protocol Buffers are a flexible, efficient, \
                automated mechanism for serializing structured data -- \
                think XML, but smaller, faster, and simpler.  You \
                define how you want your data to be structured once, \
                then you can use special generated source code to \
                easily write and read your structured data to and from \
                a variety of data streams and using a variety of \
                languages.  You can even update your data structure \
                without breaking deployed programs that are compiled \
                against the "old" format.  You specify how you want \
                the information you're serializing to be structured by \
                defining protocol buffer message types in .proto \
                files.  Each protocol buffer message is a small \
                logical record of information, containing a series of \
                name-value pairs.

github.setup    google protobuf ${version} v
github.tarball_from releases
homepage        https://github.com/google/protobuf
master_sites    https://github.com/google/protobuf/releases/download/v${version}
distfiles       protobuf-python-${version}.tar.gz
worksrcdir      protobuf-${version}

checksums       sha256  969019c5fd9c1345f0b34afa06ab2664c1441d159d5ae87ded5fa01d79f028c1 \
                rmd160  498920f161944574781c011ae5687753f34e36ef \
                size    4982470

platforms       darwin

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

python.versions 27 35 36 37 38 39

if {${name} ne ${subport}} {
    conflicts       py${python.version}-protobuf

    depends_build-append \
                    port:py${python.version}-setuptools \
                    port:py${python.version}-pip \
                    port:py${python.version}-wheel

    depends_lib-append \
                    port:protobuf3-cpp \
                    port:py${python.version}-six

    worksrcdir      ${worksrcdir}/python
    
    # tricks to force the right -stdlib setting
    # and to put a needed CXX flag on the 10.6 build
    # see https://trac.macports.org/ticket/56482
    patchfiles-append patch-py-protobuf3-settings.diff

    post-patch {
        set extraargs ""
        set clang_stdlib ""

        if {[string match *clang* ${configure.compiler}]} {
            set clang_stdlib -stdlib=${configure.cxx_stdlib}

            if {${os.platform} eq "darwin" && ${os.major} < 11} {
                set extraargs -DGOOGLE_PROTOBUF_NO_THREADLOCAL
            }
        }
        
        reinplace "s|@@MACPORTS_STDLIB@@|${clang_stdlib}|g" setup.py
        reinplace "s|@@MACPORTS_EXTRAARG@@|${extraargs}|g" setup.py
    }

    build.cmd-append       --cpp_implementation

    destroot.cmd-append    --cpp_implementation

    test.run        yes
    test.cmd        "${python.bin} setup.py"
    test.target     test --cpp_implementation

    livecheck.type  none
}

github.livecheck.regex  {([0-9.]+)}
