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

name                apache-orc
github.setup        apache orc 2.3.1 v
revision            0
categories          devel
license             Apache-2
maintainers         nomaintainer
description         Smallest, fastest columnar storage for Hadoop workloads
long_description    {*}${description}
homepage            https://orc.apache.org

github.tarball_from archive

# https://github.com/apache/orc/blob/main/subprojects/packagefiles/orc-format/meson.build
set format_ver      1.1.1

master_sites-append https://archive.apache.org/dist/orc/orc-format-${format_ver}/:orc_format
distfiles-append    orc-format-${format_ver}${extract.suffix}:orc_format

checksums           ${distname}${extract.suffix} \
                    rmd160  77ad2f9cbca5d24e52d8ad832df91be44bd5b623 \
                    sha256  5c5fb4bf752a880da08c8a10a17e1a98a4422b25eaa2391f5286e509b1ae43fa \
                    size    13460687 \
                    orc-format-${format_ver}${extract.suffix} \
                    rmd160  026ca2a36f9a51af75527c62078fbd6e25f09bfd \
                    sha256  584dfe2a4202946178fd8fc7d1239be7805b9ed4596ab2042dee739e7880992b \
                    size    522475

extract.only        ${distname}${extract.suffix}

post-extract {
    copy ${distpath}/orc-format-${format_ver}${extract.suffix} ${workpath}/
}

# https://github.com/apache/orc/issues/2736
patchfiles-append   patch-ORC-2159-nodiscard.diff

patchfiles-append   patch-ColumnReader-32bit.diff

# Fix linking protobuf and abseil:
patchfiles-append   patch-FindProtobufAlt-config.diff

post-patch {
    reinplace "s|__PPC64LE__|__POWERPC__|" ${worksrcpath}/c++/src/CpuInfoUtil.cc
}

depends_build-append \
                    port:gtest

depends_lib-append  port:abseil \
                    port:lz4 \
                    port:protobuf \
                    port:snappy \
                    port:zlib \
                    port:zstd

compiler.cxx_standard   2017
compiler.thread_local_storage yes

configure.env-append    ORC_FORMAT_URL=${workpath}/orc-format-${format_ver}${extract.suffix} \
                        ZSTD_HOME=${prefix}
configure.args-append   -DBUILD_CPP_TESTS=OFF \
                        -DBUILD_ENABLE_AVX512=OFF \
                        -DBUILD_ENABLE_RVV=OFF \
                        -DBUILD_SHARED_LIBS=ON \
                        -DBUILD_JAVA=OFF \
                        -DFETCHCONTENT_FULLY_DISCONNECTED=ON \
                        -DGTEST_HOME=${prefix} \
                        -DLZ4_HOME=${prefix} \
                        -DORC_ENABLE_CLANG_TOOLS=OFF \
                        -DORC_PREFER_STATIC_GMOCK=ON \
                        -DORC_PREFER_STATIC_LZ4=OFF \
                        -DORC_PREFER_STATIC_PROTOBUF=OFF \
                        -DORC_PREFER_STATIC_SNAPPY=OFF \
                        -DORC_PREFER_STATIC_ZLIB=OFF \
                        -DORC_PREFER_STATIC_ZSTD=OFF \
                        -DPROTOBUF_HOME=${prefix} \
                        -DSNAPPY_HOME=${prefix} \
                        -DZLIB_HOME=${prefix}

# CpuInfoUtil.cc:487:52: error: unused parameter 'simdLevel' [-Werror=unused-parameter]
configure.cxxflags-append \
                        -Wno-error=unused-parameter

# https://github.com/apache/orc/issues/2737
if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
    configure.ldflags-append \
                        -latomic
}

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

variant cxx20 conflicts cxx17 description "Use C++20" {
    post-patch {
        reinplace "s|CMAKE_CXX_STANDARD 17|CMAKE_CXX_STANDARD 20|" ${worksrcpath}/CMakeLists.txt
    }

    require_active_variants abseil cxx20
    require_active_variants protobuf cxx20
    compiler.cxx_standard   2020
}

if ![variant_isset cxx17] {
    default_variants +cxx20
}
