%undefine __cmake_in_source_build
%global chrome_syscall_ver 2024.02.01

Name:    sentry-native
Version: 0.7.7
Release: 1%{dist}
Summary: Sentry SDK for C, C++ and native applications
URL:     https://github.com/getsentry/sentry-native
License: MIT

Source0: https://github.com/getsentry/sentry-native/archive/refs/tags/%{version}.tar.gz#/sentry-native-%{version}.tar.gz
Source1: https://github.com/getsentry/libunwindstack-ndk/archive/refs/heads/master.zip#/libunwindstack-ndk-master.zip
Source2: https://github.com/getsentry/breakpad/archive/refs/heads/handler.zip#/breakpad-handler.zip
Source3: https://github.com/getsentry/crashpad/archive/refs/heads/getsentry.zip#/crashpad-getsentry.zip
Source4: https://chromium.googlesource.com/linux-syscall-support/+archive/refs/tags/v%{chrome_syscall_ver}.tar.gz#/linux-syscall-support-%{chrome_syscall_ver}.tar.gz
Source5: https://chromium.googlesource.com/chromium/mini_chromium/+archive/refs/heads/main.tar.gz#/mini_chromium.tar.gz
Source6: https://chromium.googlesource.com/chromium/src/third_party/zlib/+archive/refs/heads/main.tar.gz#/zlib.tar.gz

Patch1:  sentry-native-system-libcurl.patch

BuildRequires: cmake
BuildRequires: gcc-toolset-13-gcc-c++
BuildRequires: libcurl-devel
BuildRequires: glibc-headers
BuildRequires: zlib-devel
BuildRequires: gmp-devel

%description
%{summary}.

%package static
Requires: %{name} = %{version}-%{release}
Summary:  Static files for %{name}.

%description static
%{summary}.

%prep
%autosetup -p1

rm -rf external/{crashpad,breakpad,libunwindstack-ndk}

tar -xf %{SOURCE4} -C external/third_party/lss
unzip -q %{SOURCE1}
mv -f libunwindstack-ndk-master external/libunwindstack-ndk
unzip -q %{SOURCE3}
mv -f crashpad-getsentry external/crashpad
unzip -q %{SOURCE2}
mv -f breakpad-handler external/breakpad

mkdir -p external/crashpad/third_party/mini_chromium/mini_chromium
tar -xf %{SOURCE5} -C external/crashpad/third_party/mini_chromium/mini_chromium
tar -xf %{SOURCE6} -C external/crashpad/third_party/zlib/zlib
tar -xf %{SOURCE4} -C external/crashpad/third_party/lss/lss




%build
%enable_devtoolset13

%global _vpath_builddir build-static
%cmake \
    -DSENTRY_BUILD_SHARED_LIBS=OFF \
    -Wno-dev

%cmake_build

%global _vpath_builddir %{_target_platform}
%cmake \
    -Wno-dev

%cmake_build

%install
%global _vpath_builddir build-static
%cmake_install

%global _vpath_builddir %{_target_platform}
%cmake_install


%files
%license LICENSE
%doc README.md
%{_bindir}/crashpad_handler
%{_libdir}/libsentry.so
%{_includedir}/sentry.h
%{_libdir}/cmake/sentry/*.cmake

%files static
%{_libdir}/libcrashpad_handler_lib.a
%{_libdir}/libcrashpad_minidump.a
%{_libdir}/libcrashpad_compat.a
%{_libdir}/libcrashpad_util.a
%{_libdir}/libcrashpad_snapshot.a
%{_libdir}/libcrashpad_client.a
%{_libdir}/libcrashpad_tools.a
%{_libdir}/libmini_chromium.a
%{_libdir}/libsentry.a
