File lld.spec of Package lld
%define realname lld
%define realver 17.0.1
%define srcext tar.xz
%bcond_without ninja
%define gen %(awk -F. '{print $1}' <<< %{realver})
%define mainver %(awk -F. '{printf "%i.%i", $1, $2}' <<< %{realver})
# turn off the generation of debuginfo rpm (RH9) ??
%global debug_package %{nil}
# Common info
Name: %{realname}
Version: %{realver}
Release: wiz%{?extraver:0.}1%{?dist}
License: BSD-3-Clause
Group: Development/Tools/Building
URL: http://lld.llvm.org/
Summary: The LLVM Linker
# Install-time parameters
Requires: /usr/sbin/update-alternatives
# Build-time parameters
BuildRequires: xz pkg-config cmake >= 3.4.3
BuildRequires: gcc-c++ binutils-gold
%if %{with ninja}
BuildRequires: ninja
%endif
BuildRequires: llvm-devel = %{version}
BuildRequires: libxml2-devel
BuildRequires: libzstd-devel
%if 0%{?suse_version}
BuildRequires: fdupes
%endif
BuildRoot: %{_tmppath}/%{name}-root
Source0: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{realver}/%{realname}-%{realver}%{?extraver}.src.%{srcext}
Source1: https://github.com/llvm/llvm-project/raw/llvmorg-%{realver}/libunwind/include/mach-o/compact_unwind_encoding.h
# Cmake modules
Source15: https://github.com/llvm/llvm-project/raw/llvmorg-%{realver}/cmake/Modules/CMakePolicy.cmake
%description
LLD is a linker from the LLVM project. That is a drop-in replacement
for system linkers and runs much faster than them. It also provides
features that are useful for toolchain developers.
The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS) and
WebAssembly in descending order of completeness. Internally, LLD consists
of several different linkers. The ELF port is the one that will be described
in this document. The PE/COFF port is complete, including Windows debug
info (PDB) support. The WebAssembly port is still a work in progress (See
WebAssembly lld port). The Mach-O port is built based on a different
architecture than the others. For the details about Mach-O, please read
ATOM-based lld.
%package -n liblld%{gen}
Group: System/Libraries
Summary: LLD shared libraries
Provides: liblld = %{version}-%{release}
Provides: libLLD = %{version}-%{release}
Provides: libLLD%{gen} = %{version}-%{release}
Provides: liblldCOFF%{gen} = %{version}-%{release}
Provides: liblldCommon%{gen} = %{version}-%{release}
Provides: liblldELF%{gen} = %{version}-%{release}
Provides: liblldMachO%{gen} = %{version}-%{release}
Provides: liblldMinGW%{gen} = %{version}-%{release}
Provides: liblldWasm%{gen} = %{version}-%{release}
%description -n liblld%{gen}
Shared libraries from the LLD - the linker from the LLVM project.
%package devel
Group: Development/Languages/C and C++
Summary: Developent files for %{name}
Requires: liblld%{gen} = %{version}-%{release}
### Requires: %{name} = %{version}-%{release}
%description devel
Developent files for %{name} - The LLVM Linker
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}.src
%{__install} -D -m0644 %{S:1} include/mach-o/compact_unwind_encoding.h
%{__install} -m0644 %{S:15} cmake/modules/
# Don't use upper level CMake modules
%{__sed} -ri \
-e '/^\s*set\(LLVM_COMMON_CMAKE_UTILS/ s|\.\./||' \
-e 's|/Modules|/modules|' \
CMakeLists.txt
%build
_CFLAGS='%{optflags}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro'
cmake -S . -B build \
%if %{with ninja}
-G Ninja \
%endif
-Wno-dev \
-DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="$_CFLAGS -std=gnu++17" \
-DCMAKE_C_FLAGS_RELEASE="$_CFLAGS" \
-DCMAKE_EXE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
-DCMAKE_MODULE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$_LDFLAGS -shared" \
-DCMAKE_SKIP_RPATH=YES \
-DCMAKE_VERBOSE_MAKEFILE=YES \
\
-DBUILD_SHARED_LIBS=YES \
-DLLVM_ENABLE_LTO=ON
%if %{with ninja}
ninja -v -C build %{?_smp_mflags}
%else
%{__make} -C build %{?_smp_mflags}
%endif
%install
%if %{with ninja}
DESTDIR=%{buildroot} ninja -v -C build install
%else
%{__make} -C build install DESTDIR=%{buildroot}
%endif
%{__install} -d -m755 %{buildroot}%{_sysconfdir}/alternatives/
touch %{buildroot}%{_sysconfdir}/alternatives/ld
%{__ln_s} -f %{_sysconfdir}/alternatives/ld %{buildroot}%{_bindir}/ld
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%files
%defattr(-,root,root)
%doc LICENSE.TXT README.md
%ghost %{_sysconfdir}/alternatives/ld
%{_bindir}/*
%files -n liblld%{gen}
%defattr(-,root,root)
%{_libdir}/*.so.%{gen}
%files devel
%defattr(-,root,root)
%{_includedir}/lld/
%{_libdir}/*.so
%dir %{_libdir}/cmake/lld
%dir %{_libdir}/cmake
%{_libdir}/cmake/lld/LLD*.cmake
%exclude %{_includedir}/mach-o/compact_unwind_encoding.h
%post
/usr/sbin/update-alternatives \
--install %{_bindir}/ld ld %{_bindir}/lld 3
%postun
if [ ${1} -eq 0 ]; then
/usr/sbin/update-alternatives --remove ld %{_bindir}/lld
/usr/sbin/update-alternatives --auto ld
fi
%post -n liblld%{gen} -p /sbin/ldconfig
%postun -n liblld%{gen} -p /sbin/ldconfig
%changelog