File libpulp.spec of Package libpulp

#
# spec file for package libpulp
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name:           libpulp
Version:        0.3.14
Release:        0
Summary:        Userspace live patching library and tools
License:        LGPL-2.1-or-later
Group:          Productivity/Security
URL:            https://github.com/suse/libpulp
Source0:        %{name}-%{version}.tar.gz
Source1:        rpm-helper
Source2:        macros.userspace-livepatch
Source3:        selinux-ulp.conf
Source4:        ulp-tmp.conf
Source99:       libpulp.rpmlintrc
# Required to hardlink identical files.
BuildRequires:  fdupes
# Required to run the tests.
BuildRequires:  gcc-c++
# Required to build the tools, which are needed to run the tests.
BuildRequires:  libjson-c-devel
BuildRequires:  libelf-devel
BuildRequires:  procps
BuildRequires:  python3-pexpect
BuildRequires:  python3-psutil
BuildRequires:  libseccomp-devel

# Disable ptrace_scope on tumbleweed
%if 0%{?suse_version} >= 1600
BuildRequires:  aaa_base-yama-enable-ptrace
%endif

# Only available for these architectures.
%if 0%{?sle_version} >= 150700 || 0%{suse_version} >= 1570
# For ppc64le onwards we need gcc-13 for a fix to -fpatchable-function-entry
# which is not currently upstream and not in gcc-14.
BuildRequires: gcc13
BuildRequires: gcc13-c++
ExclusiveArch:  x86_64 ppc64le
%else
# Block to x86_64 for older versions of SLE.
ExclusiveArch:  x86_64
%endif

%description
Library and tools for user space live patching.

%package -n libpulp0
Summary:        User space live patching library
Group:          System/Libraries

%description -n libpulp0
Libpulp is a library (and a framework) that enables live patching of
user space libraries.

This package contains the runtime files.

%package tools
Summary:        User space live patching tools
Group:          System/Management

%description tools
This package contains the tools to apply user-space live patches.

# Disable LTO for libpulp, as it is currently not supported.
%define _lto_cflags %{nil}

%prep
%autosetup -p1

%build

# For ppc64le onwards we need gcc-13 for a fix to -fpatchable-function-entry
# which is not currently upstream and not in gcc-14.
%if 0%{?sle_version} >= 150700 || 0%{suse_version} >= 1570
export CC=gcc-13
export CXX=g++-13
%endif

%configure
%make_build

%check
%make_build check

%install
%make_install
install -D -m0755 %{SOURCE1} %{buildroot}%{_prefix}/lib/userspace-livepatch/rpm-helper
install -D -m0644 %{SOURCE2} %{buildroot}%{_prefix}/lib/rpm/macros.d/macros.userspace-livepatch
install -D -m0644 %{SOURCE3} %{buildroot}%{_prefix}/etc/tukit.conf.d/selinux-ulp.conf
install -D -m0644 %{SOURCE4} %{buildroot}%{_prefix}/lib/tmpfiles.d/ulp-tmp.conf

# Create /var/livepatches
mkdir -p %{buildroot}/var/livepatches/

# Convert identical files into hardlinks.
%fdupes %{buildroot}/%{_prefix}
# Remove .la and .so files.  libpulp.so is not supposed to be linked
# against any programs or libraries, but LD_PRELOAD'ed, so do not
# distribute it, not even in the devel package.
find %{buildroot}/%{_prefix} -name libpulp.la -delete
find %{buildroot}/%{_prefix} -name libpulp.so -delete

%post -n libpulp-tools
%define ld_so_conf  /etc/ld.so.conf
%define addline     include /var/livepatches/ld.so.conf

# There are special logic needed in sle-micro onwards.
%if 0%{?suse_version} >= 1600

# Add instance of /var/livepatches if it doesn't already exist.
grep -qxF '%{addline}' %{ld_so_conf} || echo '%{addline}' >> %{ld_so_conf}

%postun -n libpulp-tools

if [ "$1" == "0" ]; then
  # Delete all instances of libpulp in the ld_so_conf.
  sed -i '\#%{addline}#d' %{ld_so_conf}
fi
%endif

%post -n libpulp0 -p /sbin/ldconfig
%postun -n libpulp0 -p /sbin/ldconfig

%files -n libpulp0
%{_libdir}/lib*.so.*
%doc README.md
%license LICENSE

%files tools
%{_bindir}/*
%{_mandir}/*/*
%dir %{_prefix}/lib/userspace-livepatch
%{_prefix}/lib/userspace-livepatch/*
%{_prefix}/lib/rpm/*
%{_prefix}/lib/tmpfiles.d/ulp-tmp.conf
%{_prefix}/etc/tukit.conf.d/selinux-ulp.conf
%{_prefix}/etc/tukit.conf.d
%{_prefix}/etc
/var/livepatches
%license LICENSE

%changelog
openSUSE Build Service is sponsored by