# -*- 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

# MAP_ANONYMOUS and clock_gettime
legacysupport.newest_darwin_requires_legacy 15

# Ports that depend on this port must be revbump after update.

name                abseil
github.setup        abseil ${name}-cpp 20260526.0
revision            0
categories          devel
maintainers         {judaew @judaew} {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
license             Apache-2

description         Abseil - C++ Common Libraries
long_description    Abseil is an open-source collection of C++ library \
                    code designed to augment the C++ standard \
                    library. The Abseil library code is collected from \
                    Google's own C++ code base, has been extensively \
                    tested and used in production.

checksums           rmd160  91fadb3d22c3cdeee301491deec1c95219139b79 \
                    sha256  6e1aee535473414164bf83e4ebc40240dec71a4701f8a642d906e95bea1aea0c \
                    size    2391476
github.tarball_from archive

patchfiles          3b33f7fd5c9b751c8463247c992b9f1faa7760a7.patch

patchfiles-append   patch-remove-Xarch-from-pkg-config.diff

patchfiles-append   patch-fix-config.h.diff

# See https://github.com/macports/macports-ports/pull/19905#issuecomment-1679652939
patchfiles-append   patch-pthread.diff

platform darwin 8 {
    patchfiles-append tiger-execinfo.patch
}

platform darwin {
    if {${configure.build_arch} in [list ppc ppc64]} {
        patchfiles-append patch-darwin-ppc.diff
    }

    if {${os.major} >= 11 && ${os.major} <= 12} {
        # some functions in xlocale.h are hidden without this define
        # https://trac.macports.org/ticket/67988
        configure.cxxflags-append -D_DARWIN_C_SOURCE
    }
}

if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
    configure.ldflags-append \
                    -latomic
}

compiler.cxx_standard   2017
compiler.thread_local_storage yes

# https://trac.macports.org/ticket/67553
# error: default initialization of an object of const type 'const absl::lts_20230125::Condition'
#   without a user-provided default constructo
compiler.blacklist-append \
                    {clang < 900}

configure.args-append \
                    -DABSL_BUILD_MONOLITHIC_SHARED_LIBS=OFF \
                    -DABSL_BUILD_TESTING=OFF \
                    -DABSL_PROPAGATE_CXX_STD=ON \
                    -DBUILD_SHARED_LIBS=ON

# Match protobuf here, avoid potentially problematic -Os:
configure.optflags

variant cxx17 conflicts cxx20 description "Use C++17" {
    configure.args-append   -DCMAKE_CXX_STANDARD=17
}

variant cxx20 conflicts cxx17 description "Use C++20" {
    compiler.cxx_standard   2020
    configure.args-append   -DCMAKE_CXX_STANDARD=20
}

if ![variant_isset cxx17] {
    default_variants +cxx20
}

# Explicit variants for thread_identity exist for debugging purposes. Therefore by default neither is used.

# pthread variants allows almost all tests to pass, however it works much slower.
variant pthread conflicts tls description "Enforce pthread usage instead of TLS" {
    configure.cppflags-append   -DABSL_FORCE_THREAD_IDENTITY_MODE=ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC
}

variant tls conflicts pthread description "Enforce TLS" {
    configure.cppflags-append   -DABSL_FORCE_THREAD_IDENTITY_MODE=ABSL_THREAD_IDENTITY_MODE_USE_TLS
}

variant tests description "Provide testing" {
    cmake.build_type    Debug

    configure.args-replace \
                    -DBUILD_SHARED_LIBS=ON -DBUILD_SHARED_LIBS=OFF \
                    -DABSL_BUILD_TESTING=OFF -DABSL_BUILD_TESTING=ON
    configure.args-append \
                    -DABSL_USE_EXTERNAL_GOOGLETEST=ON \
                    -DABSL_LOCAL_GOOGLETEST_DIR=${prefix}/src/googletest

    depends_build-append \
                    port:gtest
    depends_test    port:gtest

    configure.optflags

    known_fail yes
    pre-activate {
        ui_error "Do not install +tests variant, since it disables dynamic libs."
        error "Installation aborted"
    }

    if {${configure.cxx_stdlib} ne "libc++"} {
        test.env-append \
                    DYLD_LIBRARY_PATH=${prefix}/lib/libgcc:\$DYLD_LIBRARY_PATH
    }
    test.run        yes
    test.target     test
}

# FIXME:
# On powerpc, 20260526.0 with C++17:

# 94% tests passed, 15 tests failed out of 241
# Total Test time (real) = 379.72 sec
# The following tests FAILED:
# 	 18 - absl_sysinfo_test (Bus error)
# 	 20 - absl_thread_identity_test (Bus error)
# 	 24 - absl_strerror_test (Failed)
# 	 51 - absl_hashtablez_sampler_test (ILLEGAL)
# 	113 - absl_scoped_mock_log_test (ILLEGAL)
# 	125 - absl_sample_recorder_test (ILLEGAL)
# 	138 - absl_random_exponential_distribution_test (Failed)
# 	162 - absl_random_internal_iostream_state_saver_test (Failed)
# 	201 - absl_str_format_convert_test (Failed)
# 	208 - absl_cordz_handle_test (ILLEGAL)
# 	211 - absl_cordz_sample_token_test (Bus error)
# 	222 - absl_barrier_test (Bus error)
# 	225 - absl_mutex_test (ILLEGAL)
# 	227 - absl_notification_test (Bus error)
# 	233 - absl_simulated_clock_test (ILLEGAL)

# On powerpc, 20260526.0 with C++20:

# The following tests FAILED:
# 	 12 - absl_spinlock_test (ILLEGAL)
# 	 15 - absl_call_once_test (ILLEGAL)
# 	 18 - absl_sysinfo_test (Bus error)
# 	 20 - absl_thread_identity_test (Bus error)
# 	 24 - absl_strerror_test (Failed)
# 	 51 - absl_hashtablez_sampler_test (ILLEGAL)
# 	125 - absl_sample_recorder_test (ILLEGAL)
# 	138 - absl_random_exponential_distribution_test (Failed)
# 	162 - absl_random_internal_iostream_state_saver_test (Failed)
# 	201 - absl_str_format_convert_test (Failed)
# 	208 - absl_cordz_handle_test (ILLEGAL)
# 	210 - absl_cordz_info_statistics_test (Bus error)
# 	211 - absl_cordz_sample_token_test (ILLEGAL)
# 	222 - absl_barrier_test (Bus error)
# 	225 - absl_mutex_test (ILLEGAL)
# 	227 - absl_notification_test (Bus error)
# 	233 - absl_simulated_clock_test (ILLEGAL)

# On powerpc, 20260526.0 with C++17 and +pthread:

# 98% tests passed, 4 tests failed out of 241
# Total Test time (real) = 2967.66 sec
# The following tests FAILED:
# 	 24 - absl_strerror_test (Failed)
# 	138 - absl_random_exponential_distribution_test (Failed)
# 	162 - absl_random_internal_iostream_state_saver_test (Failed)
# 	201 - absl_str_format_convert_test (Failed)
# Specific test cases that failed inside failing tests:
# [  FAILED  ] 1 test, listed below:
# [  FAILED  ] StrErrorTest.MultipleThreads
# [  FAILED  ] 1 test, listed below:
# [  FAILED  ] ExponentialDistributionTest.AlgorithmBounds
# [  FAILED  ] 1 test, listed below:
# [  FAILED  ] IOStreamStateSaver.RoundTripLongDoubles
# [  FAILED  ] 13 tests, listed below:
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/0.AllIntsWithFlags, where TypeParam = int
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/1.AllIntsWithFlags, where TypeParam = unsigned int
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/2.AllIntsWithFlags, where TypeParam = int
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/3.AllIntsWithFlags, where TypeParam = short
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/4.AllIntsWithFlags, where TypeParam = unsigned short
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/5.AllIntsWithFlags, where TypeParam = long
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/6.AllIntsWithFlags, where TypeParam = unsigned long
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/7.AllIntsWithFlags, where TypeParam = long long
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/8.AllIntsWithFlags, where TypeParam = unsigned long long
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/9.AllIntsWithFlags, where TypeParam = signed char
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/10.AllIntsWithFlags, where TypeParam = unsigned char
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/11.AllIntsWithFlags, where TypeParam = char
# [  FAILED  ] TypedFormatConvertTestWithAllIntTypes/TypedFormatConvertTest/12.AllIntsWithFlags, where TypeParam = wchar_t

# Random tests fail due to precision, it seems, but other are apparently genuinely broken.

# ignore pre releases
github.livecheck.regex  {([0-9.]+)}
