%bcond_with ctest

Name:           mold
Version:        2.34.1
Release:        1
Summary:        A Modern Linker (mold)
License:        MIT
URL:            https://github.com/rui314/mold
Source:         https://github.com/rui314/mold/archive/v%{version}/%{name}-%{version}.tar.gz

ExclusiveArch:  %{ix86} x86_64 aarch64 riscv64 loongarch64
BuildRequires:  gcc gcc-c++ >= 10
BuildRequires:  python3 grep cmake openssl-devel
BuildRequires:  zlib-devel xxhash-devel libzstd libzstd-devel

# following pkgs are only required for the test
BuildRequires:  llvm clang perl
BuildRequires:  gdb glibc-devel
BuildRequires:  libstdc++-static libdwarf-tools

BuildRequires:  tbb-devel >= 2021.11

# Allow building against the system-provided `xxhash.h`
Patch0:     0001-Use-system-compatible-include-path-for-xxhash.h.patch

# Build blake3 as static
Patch1:     0002-build-blake3-as-static.patch

%define build_args -DMOLD_USE_MIMALLOC=OFF -DMOLD_USE_SYSTEM_TBB=ON -DMOLD_LTO=ON

%description
mold is a faster drop-in replacement for existing Unix linkers.
It is several times faster than the LLVM lld linker.
mold is designed to increase developer productivity by reducing
build time, especially in rapid debug-edit-rebuild cycles.

%prep
%autosetup -p1
# Prefer system xxhash/zlib/zstd instead of bundled one
rm -r third-party/{xxhash,zlib,zstd}

%build
%cmake -B %{_vpath_builddir} %{build_args}
%cmake_build

%if %{with ctest}
%check
%ctest
%endif

%install
%cmake_install
chmod +x %{buildroot}%{_libdir}/mold/mold-wrapper.so

%files
%license %{_docdir}/mold/LICENSE
%license %{_docdir}/mold/LICENSE.third-party
%{_bindir}/mold
%{_bindir}/ld.mold
%dir %{_libdir}/mold
%{_libdir}/mold/mold-wrapper.so
%dir %{_libexecdir}/mold
%{_libexecdir}/mold/ld
%{_mandir}/man1/ld.mold.1*
%{_mandir}/man1/mold.1*

%changelog
* Sat Oct 05 2024 Funda Wang <fundawang@yeah.net> - 2.34.1-1
- Upgrade to 2.34.1

* Tue Aug 13 2024 jchzhou <zhoujiacheng@iscas.ac.cn> - 2.33.0-1
- Upgrade to 2.33.0

* Wed Jul 17 2024 jchzhou <zhoujiacheng@iscas.ac.cn> - 2.32.1-1
- Upgrade to 2.32.1

* Tue Mar 19 2024 jchzhou <zhoujiacheng@iscas.ac.cn> - 2.30.0-1
- Init package
