File lld.spec of Package lld
%define realname lld
%define realver 14.0.6
%define srcext tar.xz
%bcond_without ninja
#define so_ver %(awk -F. '{printf "%i_%i", $1, $2}' <<< %{realver})
#define gen %(awk -F. '{print $1}' <<< %{realver})
#define mainver %(awk -F. '{printf "%i.%i", $1, $2}' <<< %{realver})
%define so_ver 14
%define gen 14
%define mainver 14.0
# 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
Requires: %{realname}%{gen} = %{version}-%{release}
# Build-time parameters
BuildRequires: xz pkg-config cmake >= 3.4.3
BuildRequires: gcc-c++ binutils-gold
%if %{with ninja}
BuildRequires: ninja
%endif
BuildRequires: llvm%{gen}-devel
BuildRequires: libxml2-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
Source11: https://github.com/llvm/llvm-project/raw/llvmorg-%{realver}/cmake/Modules/ExtendPath.cmake
Source12: https://github.com/llvm/llvm-project/raw/llvmorg-%{realver}/cmake/Modules/FindPrefixFromConfig.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 %{realname}%{gen}
License: BSD-3-Clause
Group: Development/Tools/Building
URL: http://lld.llvm.org/
Summary: The LLVM Linker
%description -n %{realname}%{gen}
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%{so_ver}
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%{so_ver}
Shared libraries from the LLD - the linker from the LLVM project.
%package devel
Group: Development/Languages/C and C++
Summary: Developent files for %{name}
Provides: %{name}%{gen}-devel = %{version}-%{release}
Provides: liblld%{gen}-devel = %{version}-%{release}
Provides: liblld%{so_ver}-devel = %{version}-%{release}
Requires: liblld%{so_ver} = %{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:11} cmake/modules/
%{__install} -m0644 %{S:12} cmake/modules/
%{__ln_s} modules cmake/Modules
%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 \
\
-DLLVM_COMMON_CMAKE_UTILS=$(pwd -P)/cmake \
-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
# alteratives
mv -f %{buildroot}%{_bindir}/lld %{buildroot}%{_bindir}/lld-%{gen}
%{__install} -d -m755 %{buildroot}%{_sysconfdir}/alternatives/
for binary in ld.lld ld64.lld lld-link wasm-ld; do
touch %{buildroot}%{_sysconfdir}/alternatives/$binary
%{__ln_s} -fn %{_sysconfdir}/alternatives/$binary %{buildroot}%{_bindir}/$binary
done
touch %{buildroot}%{_sysconfdir}/alternatives/lld
%{__ln_s} -f %{_sysconfdir}/alternatives/lld %{buildroot}%{_bindir}/lld
touch %{buildroot}%{_sysconfdir}/alternatives/ld
%{__ln_s} -f %{_sysconfdir}/alternatives/ld %{buildroot}%{_bindir}/ld
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%files
%defattr(-,root,root)
%doc README.md
%license LICENSE.TXT
%ghost %{_sysconfdir}/alternatives/*
%{_bindir}/*
%exclude %{_bindir}/lld-%{gen}
%files -n %{realname}%{gen}
%defattr(-,root,root)
%doc README.md
%license LICENSE.TXT
%{_bindir}/lld-%{gen}
%files -n liblld%{so_ver}
%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}/ld.lld 3
/usr/sbin/update-alternatives \
--install %{_bindir}/lld lld %{_bindir}/lld-%{gen} %{gen} \
--slave %{_bindir}/ld.lld ld.lld %{_bindir}/lld-%{gen} \
--slave %{_bindir}/ld64.lld ld64.lld %{_bindir}/lld-%{gen} \
--slave %{_bindir}/lld-link lld-link %{_bindir}/lld-%{gen} \
--slave %{_bindir}/wasm-ld wasm-ld %{_bindir}/lld-%{gen}
%postun
if [ ${1} -eq 0 ]; then
/usr/sbin/update-alternatives --remove ld %{_bindir}/ld.lld
/usr/sbin/update-alternatives --auto ld
/usr/sbin/update-alternatives --remove lld %{_bindir}/lld-%{gen}
/usr/sbin/update-alternatives --auto lld
fi
%post -n liblld%{so_ver} -p /sbin/ldconfig
%postun -n liblld%{so_ver} -p /sbin/ldconfig
%changelog