File kernel-devel-bpf.spec of Package kernel-devel-bpf

#
# spec file for package kernel-devel-bpf
#
# Copyright (c) 2026 SUSE LLC and contributors
#
# 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/
#
# needssslcertforbuild


%define build_flavor default
%define kernel_package_name kernel-%build_flavor
%define kver %(rpm -q --qf '%%{VERSION}' %kernel_package_name)
%define krel %(rpm -q --qf '%%{RELEASE}' %kernel_package_name)
# Extract the source release (e.g., removing the build number for directory
# matching if needed)
%define source_rel %(echo %krel | sed -r 's/\\.[0-9]+($|\\.[^.]*[^.0-9][^.]*$)/\\1/')

Name:           kernel-devel-bpf
BuildRequires:  %kernel_package_name
BuildRequires:  bpftool
BuildRequires:  coreutils
BuildRequires:  gzip
BuildRequires:  xz
# DEBUG
BuildRequires:  findutils
Summary:        Provides vmlinux.h for BPF CO-RE development
License:        GPL-2.0-only
Group:          Development/Languages/C and C++
URL:            http://www.kernel.org/
Version:        %kver
Release:        %krel.<RELEASE>
Requires:       %kernel_package_name = %{version}
# Does not have BTF
ExcludeArch:    i586 armv7hl

%description
This package contains a "vmlinux.h" header file generated from the
corresponding kernel's BTF (BPF Type Format) data.

This file provides all kernel types and definitions in a single header,
intended for use with BPF CO-RE (Compile Once - Run Everywhere) development. It
serves as a reference template; actual runtime relocation is handled by libbpf.

%prep
%setup -c -T

%build
echo "--- DEBUG: Locating Kernel Files ---"
# List /boot and /lib/modules to help debug path mismatches in the logs
ls -l /boot || true
find /lib/modules -maxdepth 2 || true
echo "------------------------------------"

VMLINUX_XZ="/lib/modules/%{kver}-%{source_rel}-%{build_flavor}/vmlinux.xz"
VMLINUX_BOOT_GZ="/boot/vmlinux-%{kver}-%{source_rel}-%{build_flavor}.gz"

echo "Looking for vmlinux in: $VMLINUX_XZ or $VMLINUX_BOOT_GZ"

if [ -f "$VMLINUX_XZ" ]; then
    echo "Found xz compressed vmlinux, decompressing..."
    cp "$VMLINUX_XZ" vmlinux.xz
    unxz vmlinux.xz
elif [ -f "$VMLINUX_BOOT_GZ" ]; then
    echo "Found gzip compressed vmlinux, decompressing..."
    cp "$VMLINUX_BOOT_GZ" vmlinux.gz
    gzip -d vmlinux.gz
else
    echo "Error: Could not locate vmlinux file with BTF data."
    exit 1
fi

echo "Generating vmlinux.h..."
/usr/sbin/bpftool btf dump file ./vmlinux format c > vmlinux.h

%install
install -d -m 755 %{buildroot}%{_includedir}
install -m 644 vmlinux.h %{buildroot}%{_includedir}/vmlinux.h

%files
%{_includedir}/vmlinux.h

%changelog
openSUSE Build Service is sponsored by