# -*- 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       conflicts_build 1.0
PortGroup       boost 1.0

boost.version   1.81

name            thrift

# NOTE: This port must be kept at the same version as port:py-thrift and port:p5-thrift
version         0.20.0
checksums       rmd160  169129427960bb83cd4763cfe371923609d66e0d \
                sha256  b5d8311a779470e1502c027f428a1db542f5c051c8e1280ccd2163fa935ff2d6 \
                size    4397667
revision        0

categories      devel
license         Apache-2
maintainers     nomaintainer

description     framework for scalable cross-language services development
long_description \
    Thrift is a software framework for scalable cross-language \
    services development. It combines a software stack with a code \
    generation engine to build services that work efficiently and \
    seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, \
    Haskell, C#, Swift, Smalltalk, and OCaml.

homepage        https://thrift.apache.org/
master_sites    apache:${name}/${version}

patchfiles-append   dynamic_lookup-11.patch

depends_build       port:autoconf \
                    port:automake \
                    port:bison \
                    port:libevent \
                    port:libtool \
                    port:pkgconfig
depends_lib-append  path:lib/libssl.dylib:openssl

compiler.cxx_standard   2011

use_autoreconf      yes

pre-configure {
    foreach l {chrono filesystem system unit_test_framework thread} {
        reinplace \
            "s#libboost_${l}\.a#libboost_${l}-mt.dylib#g" \
            ${worksrcpath}/configure.ac
    }

    # Create these files otherwise automake fails.
    system -W ${worksrcpath} "touch AUTHORS ChangeLog NEWS README"
}

conflicts_build     ${name}

configure.args  --with-c_glib=no \
                --with-cl=no \
                --with-csharp=no \
                --with-d=no \
                --with-erlang=no \
                --with-go=no \
                --with-haskell=no \
                --with-java=no \
                --with-lua=no \
                --with-nodejs=no \
                --with-perl=no \
                --with-php=no \
                --with-php_extension=no \
                --with-python=no \
                --with-ruby=no \
                --with-rs=no \
                --with-swift=no \
                --with-boost=[boost::install_area]

configure.cppflags-append -DBOOST_TEST_DYN_LINK

if {${os.platform} eq "darwin" && ${os.major} > 21} {
    # https://trac.macports.org/ticket/68475
    if {[string match *clang* ${configure.compiler}]} {
        configure.cxxflags-append \
                -Wno-error=unused-but-set-variable
    }
}

variant java description "enable the Java library" {
    depends_build-append    bin:ant:apache-ant
    configure.env-append    JAVA_PREFIX=${prefix}/share/java
    configure.args-delete   --with-java=no
    configure.args-append   --with-java=yes
}

# CSharp and Netcore targets are deprecated and will be removed with
# the next release https://issues.apache.org/jira/browse/THRIFT-4723
variant csharp description "enable the C# library" {
    configure.args-delete   --with-csharp=no
    configure.args-append   --with-csharp=yes
    depends_lib-append      port:mono
}

variant glib2 description "enable the C (GLib) library" {
    configure.args-delete   --with-c_glib=no
    configure.args-append   --with-c_glib=yes
    depends_lib-append      path:lib/pkgconfig/glib-2.0.pc:glib2
}

# hs-http port no longer exists
#variant haskell description "enable the Haskell library" {
#    configure.args-delete   --with-haskell=no
#    configure.args-append   --with-haskell=yes
#    depends_lib-append      port:ghc \
#                            port:hs-http \
#}

variant php description "enable the PHP library" {
    configure.env-append    PHP_PREFIX=${prefix}/lib/php
    configure.args-delete   --with-php=no
    configure.args-append   --with-php=yes
    depends_lib-append      path:bin/php:php5
}

variant erlang description "enable the Erlang library" {
    configure.args-delete   --with-erlang=no
    configure.args-append   --with-erlang=yes
    depends_lib-append      port:erlang
}

# doesn't install into destroot
# variant ruby description "enable the Ruby library" {
#     configure.args-delete   --with-ruby=no
#     configure.args-append   --with-ruby=yes
#     depends_lib-append      port:ruby25
# }

variant rust description "enable the Rust library" {
    configure.args-delete   --with-rs=no
    configure.args-append   --with-rs=yes
    depends_lib-append      port:rust
}

variant nodejs description "enable the NodeJS library" {
    configure.args-delete   --with-nodejs=no
    configure.args-append   --with-nodejs=yes
    depends_lib-append      path:bin/node:nodejs12
}

variant swift description "enable the Swift library" {
    configure.args-delete   --with-swift=no
    configure.args-append   --with-swift=yes

    # require XCode
    use_xcode yes
}

# NOTE: Lisp support was removed at 0.17, and recovered as proxy to cl-thrift at 0.19
# this mean that `--with-cl=yes` is useless.
variant lisp description "enable the CL library" {
    depends_run-append      port:cl-thrift
}

test.run        yes
test.target     check

livecheck.type  regex
livecheck.url   https://www.apache.org/dist/thrift/
livecheck.regex {(\d+(?:\.\d+)*)/}
