## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 3;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%global use_gcc_toolset 0%{?el8}
%global use_system_tbb  0%{?fedora} >= 40 || 0%{?rhel} >= 10

# 32-bit x86 is supported by RHEL < 10 and Fedora (the latter is implicitly
# covered by the conditional expression)
%global has_32bit_support 0%{?rhel} < 10

Name:           mold
Version:        2.36.0
Release:        %autorelease
Summary:        A Modern Linker

License:        MIT AND (Apache-2.0 OR MIT)
URL:            https://github.com/rui314/mold
Source0:        %{url}/archive/v%{version}/%{name}-%{version}.tar.gz

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

# Possibly https://sourceware.org/bugzilla/show_bug.cgi?id=29655
Patch1:         0002-ELF-S390X-Skip-tests-that-fail-due-to-buggy-code-pro.patch

BuildRequires:  blake3-devel
BuildRequires:  cmake
%if %{use_gcc_toolset}
BuildRequires:  gcc-toolset-13
%else
BuildRequires:  gcc
BuildRequires:  gcc-c++ >= 10
%endif
BuildRequires:  libzstd-devel
BuildRequires:  mimalloc-devel
BuildRequires:  xxhash-static
BuildRequires:  zlib-devel

%if %{use_system_tbb}
BuildRequires:  tbb-devel >= 2021.9
%else
# API-incompatible with older tbb 2020.3 shipped by Fedora < 40:
# https://bugzilla.redhat.com/show_bug.cgi?id=2036372
Provides:       bundled(tbb) = 2022.0
# Required by bundled oneTBB
BuildRequires:  hwloc-devel
%endif

# The following packages are only required for executing the tests
BuildRequires:  clang
BuildRequires:  gdb
BuildRequires:  glibc-static
%if ! 0%{?el8}
%ifarch x86_64
%if %{has_32bit_support}
# Koji 64-bit buildroots do not contain packages from 32-bit builds, therefore
# the 'glibc-devel.i686' variant is provided as 'glibc32'.
BuildRequires: (glibc32 or glibc-devel(%__isa_name-32))
%endif
%endif
BuildRequires:  libdwarf-tools
%endif
BuildRequires:  libstdc++-static
BuildRequires:  llvm
BuildRequires:  perl-interpreter

Requires(post): %{_sbindir}/alternatives
Requires(preun): %{_sbindir}/alternatives

%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
rm -r third-party/{blake3,mimalloc,xxhash,zlib,zstd}
%if %{use_system_tbb}
rm -r third-party/tbb
%endif

%build
%if %{use_gcc_toolset}
. /opt/rh/gcc-toolset-13/enable
%endif
%if %{use_system_tbb}
%define tbb_flags -DMOLD_USE_SYSTEM_TBB=ON
%endif
%cmake -DMOLD_USE_SYSTEM_MIMALLOC=ON %{?tbb_flags}
%cmake_build

%install
%cmake_install

%post
if [ "$1" = 1 ]; then
  %{_sbindir}/alternatives --install %{_bindir}/ld ld %{_bindir}/ld.mold 1
fi

%postun
if [ "$1" = 0 ]; then
  %{_sbindir}/alternatives --remove ld %{_bindir}/ld.mold
fi

%check
%if %{use_gcc_toolset}
. /opt/rh/gcc-toolset-13/enable
%endif
%ctest

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

%changelog
## START: Generated by rpmautospec
* Fri Jan 24 2025 Christoph Erhardt <fedora@sicherha.de> - 2.36.0-3
- Uncommitted changes

* Fri Jan 17 2025 Fedora Release Engineering <releng@fedoraproject.org> - 2.36.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild

* Thu Jan 09 2025 Christoph Erhardt <fedora@sicherha.de> - 2.36.0-1
- Update to 2.36.0 (rhbz#2336512)

* Sat Dec 28 2024 Christoph Erhardt <fedora@sicherha.de> - 2.35.1-4
- Add support for epel10

* Thu Dec 19 2024 Christoph Erhardt <fedora@sicherha.de> - 2.35.1-2
- Fix linking against shared `libmimalloc`

* Mon Dec 16 2024 Christoph Erhardt <fedora@sicherha.de> - 2.35.1-1
- Update to 2.35.1 (rhbz#2332563)

* Sun Dec 08 2024 Christoph Erhardt <fedora@sicherha.de> - 2.35.0-1
- Update to 2.35.0 (rhbz#2330998)

* Fri Oct 04 2024 Christoph Erhardt <fedora@sicherha.de> - 2.34.1-1
- Update to 2.34.1

* Wed Sep 25 2024 Christoph Erhardt <fedora@sicherha.de> - 2.34.0-1
- Update to 2.34.0 (rhbz#2314598)

* Thu Aug 08 2024 Christoph Erhardt <fedora@sicherha.de> - 2.33.0-1
- Update to 2.33.0 (rhbz#2303405)

* Fri Jul 26 2024 Christoph Erhardt <fedora@sicherha.de> - 2.32.1-4
- Build with `gcc-toolset-13` on el8

* Thu Jul 18 2024 Fedora Release Engineering <releng@fedoraproject.org> - 2.32.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Sat Jun 29 2024 Christoph Erhardt <fedora@sicherha.de> - 2.32.1-1
- Update to 2.32.1

* Sun Jun 09 2024 Christoph Erhardt <fedora@sicherha.de> - 2.32.0-1
- Update to 2.32.0

* Fri May 03 2024 Christoph Erhardt <fedora@sicherha.de> - 2.31.0-1
- Update to 2.31.0 (rhbz#2278982)

* Sun Mar 17 2024 Christoph Erhardt <fedora@sicherha.de> - 2.30.0-1
- Update to 2.30.0 (rhbz#2269778)

* Sun Mar 17 2024 Christoph Erhardt <fedora@sicherha.de> - 2.4.1-3
- Convert tabs to spaces

* Sun Mar 17 2024 Christoph Erhardt <fedora@sicherha.de> - 2.4.1-2
- Switch to rpmautospec

* Fri Mar 01 2024 Christoph Erhardt <fedora@sicherha.de> - 2.4.1-1
- Bump version to 2.4.1

* Wed Feb 21 2024 Richard W.M. Jones <rjones@redhat.com> - 2.4.0-8
- Fix linking issue with the tests on riscv64

* Thu Jan 25 2024 Fedora Release Engineering <releng@fedoraproject.org> - 2.4.0-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Sat Jan 20 2024 Christoph Erhardt <fedora@sicherha.de> - 2.4.0-6
- Skip broken unit tests on s390x

* Sat Jan 20 2024 Christoph Erhardt <fedora@sicherha.de> - 2.4.0-5
- Build against system-provided tbb where available

* Sat Jan 20 2024 Christoph Erhardt <fedora@sicherha.de> - 2.4.0-4
- Drop upstreamed tbb patch

* Sat Jan 20 2024 Christoph Erhardt <fedora@sicherha.de> - 2.4.0-3
- Bump release number

* Thu Jan 18 2024 Pavel Raiskup <praiskup@redhat.com> - 2.4.0-2
- Don't build-require files outside of permitted directories

* Sun Dec 03 2023 Christoph Erhardt <fedora@sicherha.de> - 2.4.0-1
- Bump version to 2.4.0

* Tue Nov 14 2023 Christoph Erhardt <fedora@sicherha.de> - 2.3.3-1
- Bump version to 2.3.3

* Sun Nov 12 2023 Christoph Erhardt <fedora@sicherha.de> - 2.3.2-2
- Exclude i686 on Fedora >= 39

* Sun Nov 12 2023 Christoph Erhardt <fedora@sicherha.de> - 2.3.2-1
- Bump version to 2.3.2

* Wed Aug 23 2023 Christoph Erhardt <fedora@sicherha.de> - 2.1.0-1
- Bump version to 2.1.0

* Wed Jul 26 2023 Christoph Erhardt <fedora@sicherha.de> - 2.0.0-1
- Bump version to 2.0.0

* Thu Jul 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.11.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Thu Mar 16 2023 Christoph Erhardt <fedora@sicherha.de> - 1.11.0-2
- Update version number of bundled tbb package to 2021.7

* Thu Mar 16 2023 Christoph Erhardt <fedora@sicherha.de> - 1.11.0-1
- Bump version to 1.11.0

* Sun Jan 22 2023 Christoph Erhardt <fedora@sicherha.de> - 1.10.0-2
- Disable annobin plugin on el8

* Sat Jan 21 2023 Christoph Erhardt <fedora@sicherha.de> - 1.10.0-1
- Bump version to 1.10.0

* Thu Jan 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.9.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Fri Jan 06 2023 Christoph Erhardt <fedora@sicherha.de> - 1.9.0-1
- Bump version to 1.9.0

* Mon Dec 26 2022 Christoph Erhardt <fedora@sicherha.de> - 1.8.0-1
- Bump version to 1.8.0

* Sat Nov 19 2022 Christoph Erhardt <fedora@sicherha.de> - 1.7.1-1
- Bump version to 1.7.1

* Sat Nov 19 2022 Christoph Erhardt <fedora@sicherha.de> - 1.7.0-4
- Fix out-of-bounds error on ARM

* Fri Nov 18 2022 Christoph Erhardt <fedora@sicherha.de> - 1.7.0-3
- Build with GCC 12 on el8

* Fri Nov 18 2022 Christoph Erhardt <fedora@sicherha.de> - 1.7.0-2
- Move from `ExclusiveArch` to `ExcludeArch` as only MIPS remains
  unsupported

* Fri Nov 18 2022 Christoph Erhardt <fedora@sicherha.de> - 1.7.0-1
- Bump version to 1.7.0

* Sat Oct 22 2022 Christoph Erhardt <fedora@sicherha.de> - 1.6.0-1
- Bump version to 1.6.0

* Thu Sep 29 2022 Christoph Erhardt <christoph.erhardt@sicherha.de> - 1.5.1-1
- Bump version to 1.5.1

* Thu Sep 29 2022 Christoph Erhardt <christoph.erhardt@sicherha.de> - 1.4.2-2
- Fix rpmlint warning about macro in changelog

* Sun Sep 04 2022 Christoph Erhardt <fedora@sicherha.de> - 1.4.2-1
- Bump version to 1.4.2

* Thu Aug 18 2022 Christoph Erhardt <fedora@sicherha.de> - 1.4.1-1
- Bump version to 1.4.1

* Thu Aug 18 2022 Christoph Erhardt <fedora@sicherha.de> - 1.4.0-2
- Remove superfluous directory entries from `%%files`

* Sun Aug 07 2022 Christoph Erhardt <fedora@sicherha.de> - 1.4.0-1
- Bump version to 1.4.0

* Thu Jul 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Sun Jul 03 2022 Christoph Erhardt <fedora@sicherha.de> - 1.3.1-1
- Bump version to 1.3.1

* Sun Jul 03 2022 Christoph Erhardt <fedora@sicherha.de> - 1.3.0-3
- Use wildcard pattern in `.gitignore`

* Sat Jun 18 2022 Christoph Erhardt <fedora@sicherha.de> - 1.3.0-2
- Run testsuite in parallel again

* Sat Jun 18 2022 Christoph Erhardt <fedora@sicherha.de> - 1.3.0-1
- Bump version to 1.3.0

* Sat Apr 30 2022 Christoph Erhardt <fedora@sicherha.de> - 1.2.1-2
- Add support for 32-bit x86 and Arm

* Sat Apr 30 2022 Christoph Erhardt <fedora@sicherha.de> - 1.2.1-1
- Bump version to 1.2.1

* Sat Apr 30 2022 Christoph Erhardt <fedora@sicherha.de> - 1.2-5
- Drop compatibility patch for mimalloc < 2.0.6 on epel8

* Sun Apr 24 2022 Christoph Erhardt <fedora@sicherha.de> - 1.2-4
- Drop build dependency on 32-bit static libc

* Mon Apr 18 2022 Christoph Erhardt <fedora@sicherha.de> - 1.2-3
- Fix syntax of negated distribution check

* Sat Apr 16 2022 Christoph Erhardt <fedora@sicherha.de> - 1.2-2
- Refresh patch for compatibility with mimalloc >= 2.0.6

* Sat Apr 16 2022 Christoph Erhardt <fedora@sicherha.de> - 1.2-1
- Bump version to 1.2

* Sat Apr 16 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1.1-6
- Set correct version of bundled tbb

* Sat Apr 16 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1.1-5
- Add `-Wno-sign-compare` to `CXXFLAGS`

* Sat Apr 16 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1.1-4
- Do not override `CC` and `CXX`

* Sat Apr 16 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1.1-3
- Enable libdwarf-tools build dependency for el8 and above

* Sat Apr 16 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1.1-2
- Drop conditional statements for el7

* Tue Mar 08 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1.1-1
- Bump version to 1.1.1

* Tue Mar 08 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1-7
- Cleanup: Indent consistently with tabs

* Wed Feb 23 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1-6
- Revert "Try enabling %%{ix86}"

* Wed Feb 23 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1-5
- Revert "Fix failing unit test on i686"

* Wed Feb 23 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1-4
- Fix failing unit test on i686

* Wed Feb 23 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1-3
- Try enabling %%{ix86}

* Wed Feb 23 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1-2
- Do not parallelise the testsuite execution

* Tue Feb 22 2022 Christoph Erhardt <fedora@sicherha.de> - 1.1-1
- Bump version to 1.1

* Tue Feb 22 2022 Christoph Erhardt <fedora@sicherha.de> - 1.0.2-7
- Update description

* Tue Feb 22 2022 Christoph Erhardt <fedora@sicherha.de> - 1.0.2-6
- Don't explicitly require gcc on epel

* Thu Feb 17 2022 Christoph Erhardt <fedora@sicherha.de> - 1.0.2-5
- Rebuild due to mimalloc soname change

* Tue Jan 25 2022 Christoph Erhardt <erhardt@cs.fau.de> - 1.0.2-4
- Don't build on i686

* Tue Jan 25 2022 Christoph Erhardt <erhardt@cs.fau.de> - 1.0.2-3
- Make build dependency on glibc-static(x86-32) Koji-compatible

* Tue Jan 25 2022 Christoph Erhardt <erhardt@cs.fau.de> - 1.0.2-2
- Move libdwarf-tools build dependency into the correct place

* Tue Jan 25 2022 Christoph Erhardt <erhardt@cs.fau.de> - 1.0.2-1
- Initial import (fedora#2036468).
## END: Generated by rpmautospec