# The naming scheme in non-Mandriva-based distros
%if 0%{!?mklibname:1}
%define mklibname(ds)  lib%{1}%{?2:%{2}}%{-s:-static}%{-d:-devel}
%endif
%if 0%{!?mkrel:1}
%define mkrel(c) %{1}%{?dist}
%endif

%if 0%{!?cmake_build:1}
%define cmake_build cmake --build .
%endif
%if 0%{!?cmake_install:1}
%define cmake_install DESTDIR="%{buildroot}" cmake --install .
%endif

# Should major the configure.patch and the upstream LTS branch name.
%define major   20250127
%define libname %mklibname %{name} %{major}
%define devname %mklibname %{name} -d

%define desc \
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, and is the same code we depend on in our daily coding lives. \
\
In some cases, Abseil provides pieces missing from the C++ standard; in \
others, Abseil provides alternatives to the standard for special needs we've \
found through usage in the Google code base. We denote those cases clearly \
within the library code we provide you. \
\
Abseil is not meant to be a competitor to the standard library; we've just \
found that many of these utilities serve a purpose within our code base, \
and we now want to provide those resources to the C++ community as a whole.

Name:           abseil-cpp
Version:        %{major}.1
Release:        %mkrel 1
Summary:        Collection of C++ libraries augmenting the C++ standard library
Group:          Development/C++
License:        ASL 2.0
URL:            https://abseil.io
Source0:        https://github.com/abseil/abseil-cpp/archive/%{version}/%{name}-%{version}.tar.gz

# Originally from Debian, fixes SONAME and SSE2 on i386
# https://salsa.debian.org/debian/abseil/-/blob/master/debian/patches/configure.diff
# IMPORTANT: This patch has Mageia modification, don't update it without reviewing the diff.
Patch0:         abseil-cpp-configure.patch

BuildRequires:  cmake >= 3.16
BuildRequires:  gcc-c++

%description
%{desc}

%package -n %{libname}
Summary:        Collection of C++ libraries augmenting the C++ standard library
Group:          System/Libraries

# SONAME changed twice during mga9 development.
Conflicts:      %{_lib}abseil-cpp2206.0.0 < 20220623.1-2
Obsoletes:      %{_lib}abseil-cpp20220623.0.0 < 20220623.1-2

%description -n %{libname}
%{desc}

%package -n %{devname}
Summary:        Development files for the Abseil C++ libraries
Group:          Development/C++
Requires:       %{libname} = %{version}-%{release}
Provides:       %{name}-devel = %{version}-%{release}

%description -n %{devname}
Development files for the Abseil C++ libraries.

%prep
%autosetup -p1

%build
command -v ninja >/dev/null 2>&1 && export CMAKE_GENERATOR=Ninja
# libphonenumber >= 8.13 needs libabseil-cpp built with -DCMAKE_POSITION_INDEPENDENT_CODE=ON
%cmake \
  -DCMAKE_CXX_STANDARD=17 \
  -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
  -DABSL_PROPAGATE_CXX_STD=ON
%cmake_build

%install
%cmake_install

%files -n %{libname}
%license LICENSE
%doc FAQ.md README.md UPGRADES.md
%{_libdir}/libabsl_*.so.%{major}
%{_libdir}/libabsl_*.so.%{version}

%files -n %{devname}
%{_includedir}/absl/
%{_libdir}/cmake/absl/
%{_libdir}/libabsl_*.so
%{_libdir}/pkgconfig/absl_*.pc