File anbox-modules.spec of Package anbox-modules

#
# spec file for package anbox-modules
#
# Copyright (c) 2026 SUSE LLC
# Copyright (c) 2026 James "Jim" Ed Randson <jimedrand@disroot.org>
#
# 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/
#
#


%ifarch x86_64
%if 0%{?suse_version} > 1600
%define kmp_longterm 1
%endif
%endif

Name:           anbox-modules
Version:        20250305.18f37ba
Release:        0
Summary:        Anbox binder kernel module
License:        GPL-2.0-only
Group:          System/Kernel
URL:            https://github.com/ericfrs/anbox-modules

Source0:        %{name}-%{version}.tar.gz
Source1:        %{name}-preamble

%if 0%{?suse_version} == 1550
Patch0:         fix-leap-15_5.patch
%endif

BuildRequires:  %{kernel_module_package_buildreqs}
BuildRequires:  pesign-obs-integration

%if 0%{?kmp_longterm}
BuildRequires:  kernel-syms-longterm
%endif

%kernel_module_package -n anbox -p %{SOURCE1} -x debug -x trace

%description
Anbox binder out-of-tree kernel module for running Android containers.
This package provides the kernel module package (KMP) variant that is
built against specific kernel versions.

%package common
Summary:        Common configuration files for anbox kernel modules
Group:          System/Kernel

%description common
Common configuration files for Anbox kernel module.
This package is architecture-independent and shared between all
kernel module flavors.

%package dkms
Summary:        DKMS source for anbox kernel modules
Group:          System/Kernel
Requires:       dkms
Requires:       gcc
Requires:       make
BuildArch:      noarch
Provides:       %{name}-kmod = %{version}
Conflicts:      anbox-kmp
Obsoletes:      %{name}-kmod < %{version}

%description dkms
This package provides the anbox kernel module source code and DKMS configuration
for automatic building against installed kernels. The modules include the binder
driver required for Anbox Android container runtime.

DKMS will automatically rebuild the module when new kernels are installed,
ensuring compatibility across kernel updates without requiring manual intervention.

%prep
# Source code setup
%setup -q -n %{name}-%{version}

# Apply specific patch for Leap 15.5
%if 0%{?suse_version} == 1550
%patch -P 0 -p1
%endif

set -- *
mkdir source
mv "$@" source/
mkdir obj

%build
for flavor in %{flavors_to_build} ; do
    rm -rf obj/$flavor
    cp -r source obj/$flavor
    %make_build V=1 -C %{kernel_source $flavor} %{?linux_make_arch} modules M=$PWD/obj/$flavor/binder
done

%install
export INSTALL_MOD_PATH=%{buildroot}
export INSTALL_MOD_DIR='%{kernel_module_package_moddir}'

for flavor in %{flavors_to_build} ; do
    make V=1 -C %{kernel_source $flavor} modules_install M=$PWD/obj/$flavor/binder
done

export BRP_PESIGN_FILES='*.ko'

# configs for common package
install -D -m 0644 source/anbox.conf %{buildroot}%{_modulesloaddir}/anbox.conf
install -D -m 0644 source/99-anbox.rules %{buildroot}%{_udevrulesdir}/99-anbox.rules

# Install DKMS source
mkdir -p %{buildroot}%{_usrsrc}/%{name}-%{version}
cp -r source/binder %{buildroot}%{_usrsrc}/%{name}-%{version}/
cp source/anbox.conf %{buildroot}%{_usrsrc}/%{name}-%{version}/
cp source/99-anbox.rules %{buildroot}%{_usrsrc}/%{name}-%{version}/
install -D -m 0644 source/debian/copyright %{buildroot}%{_usrsrc}/%{name}-%{version}/copyright
install -D -m 0644 source/README.md %{buildroot}%{_usrsrc}/%{name}-%{version}/README.md

# Create DKMS configuration
cat > %{buildroot}%{_usrsrc}/%{name}-%{version}/dkms.conf << 'EOF'
PACKAGE_NAME="anbox-modules"
PACKAGE_VERSION="%{version}"
MAKE[0]="make -C binder KERNEL_DIR=${kernel_source_dir} KERNELRELEASE=${kernelver}"
CLEAN="make -C binder clean"
BUILT_MODULE_NAME[0]="binder_linux"
BUILT_MODULE_LOCATION[0]="binder/"
DEST_MODULE_LOCATION[0]="/kernel/drivers/misc/"
AUTOINSTALL="yes"
REMAKE_INITRD="yes"
EOF

%post dkms
dkms add -m %{name} -v %{version} --rpm_safe_upgrade 2>/dev/null || true
dkms build -m %{name} -v %{version} -k "$(uname -r)" 2>/dev/null || true
dkms install -m %{name} -v %{version} -k "$(uname -r)" 2>/dev/null || true

%preun dkms
if [ "$1" = "0" ]; then
    dkms remove -m %{name} -v %{version} --all --rpm_safe_upgrade 2>/dev/null || true
fi

%files
%license source/debian/copyright
%doc source/README.md

%files common
%dir %{_modulesloaddir}
%{_modulesloaddir}/anbox.conf
%{_udevrulesdir}/99-anbox.rules

%files dkms
%license source/debian/copyright
%doc source/README.md
%{_usrsrc}/%{name}-%{version}/

%changelog
* Sat Jan 18 2026 James "Jim" Ed Randson <jimedrand@disroot.org> - 20250305.18f37ba-0
- Revised for openSUSE Factory compliance
- Added automatic DKMS rebuild on kernel updates via systemd service
- Improved DKMS cleanup on package removal
- Added posttrans scriptlet for post-upgrade rebuild
- Added kernel update trigger script
- Enhanced conflict resolution between KMP and DKMS variants
- Fixed file installation to avoid conflicts
- Added module reload capability in post scripts
- Improved error handling in all scriptlets
openSUSE Build Service is sponsored by