File linux-xanmod-edge.spec of Package xanmod-edge-custom

#
# Spec file for XanMod Edge kernel (openSUSE Tumbleweed)
# Fixed version - handles OBS dracut/rsync error
#
Name:           linux-xanmod-edge
Version:        0
Release:        xanmod1%{?dist}
Summary:        Linux XanMod Edge Kernel optimized for x86-64-v3 with Waydroid support
License:        GPL-2.0-only
Group:          System/Kernel
URL:            https://xanmod.org/

%define kernel_flavor xanmod-edge

# Disable package signing for OBS builds
%global _binary_payload w9.xzdio
%undefine _gpg_name
%undefine _gpg_path
%undefine _gpg_sign_cmd
#
# === CRITICAL FIX: AGGRESSIVELY DISABLE KSYMS ===
#
%global __find_requires %{nil}
%global __find_provides %{nil}
%global __find_provides_ksyms %{nil}
%global __find_requires_ksyms %{nil}
%global _use_internal_dependency_generator 0
%global __provides_exclude_from ^/lib/modules/.*\.ko$
%global __requires_exclude_from ^/lib/modules/.*\.ko$

Source0:        linux-%{version}.tar.zst
Source1:        config.conf
Source2:        waydroid-amd.fragment
Source3:        linux-xanmod-edge-rpmlintrc

# BuildRequires for openSUSE Tumbleweed
BuildRequires:  bc
BuildRequires:  bison
BuildRequires:  binutils
BuildRequires:  bash-sh
BuildRequires:  cpio
BuildRequires:  coreutils
BuildRequires:  dwarves
BuildRequires:  dracut
BuildRequires:  elfutils
BuildRequires:  fdupes
BuildRequires:  flex
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  glibc-devel
BuildRequires:  hmaccalc
BuildRequires:  modutils
BuildRequires:  kmod
BuildRequires:  libelf-devel
BuildRequires:  libkmod-devel
BuildRequires:  libopenssl-devel
BuildRequires:  make >= 4.3
BuildRequires:  module-init-tools
BuildRequires:  ncurses-devel
BuildRequires:  openssl-devel
BuildRequires:  openssl
#BuildRequires:  kernel-macros
#BuildRequires:  kernel-source
#BuildRequires:  kernel-syms
BuildRequires:  pahole
BuildRequires:  perl
BuildRequires:  perl-base
BuildRequires:  pkgconfig
BuildRequires:  python3
BuildRequires:  python3-base
#BuildRequires:  pesign-obs-integration
BuildRequires:  rsync
BuildRequires:  util-linux
BuildRequires:  xz
BuildRequires:  zstd

Requires(post): kmod
Requires(post): dracut
Requires(post): rsync

%if "%{compress_modules}" == "zstd"
BuildRequires:  zstd
# Make sure kmod supports zstd compressed modules
Requires(post): kmod-zstd
%endif

Requires(post): modutils
Requires(post): perl-Bootloader >= 0.4.15
Requires(post): dracut
Requires(post): distribution-release

%global kernel_release %{version}-%{release}.%{kernel_flavor}

# Allow RPM to handle kernel module dependencies properly
AutoReqProv: yes

%description
The Linux XanMod Edge kernel with custom settings and new features, built to
provide a stable, responsive and smooth desktop experience. Optimized for
x86-64-v3 with Waydroid support.

This is version %{version} of the XanMod kernel series.

%package devel
Summary:        Development files for the %{kernel_flavor} kernel
Group:          Development/Sources
Requires:       %{name} = %{version}-%{release}
Provides:       kernel-devel = %{version}
Provides:       kernel-%{kernel_flavor}-devel = %{version}
AutoReqProv:    no

%description devel
This package contains the kernel headers and makefiles sufficient to build
modules against the %{name} kernel package.

%prep
%setup -q -n linux-%{version}

# Copy base config
echo "Using custom base config: %{SOURCE1}"
cp %{SOURCE1} .config

# Merge custom options (Waydroid/AMD)
echo "Merging custom options from %{SOURCE2}"
scripts/kconfig/merge_config.sh -m .config %{SOURCE2}

%build
%define ARCH_TYPE x86

# Set kernel local version to include our flavor
sed -i "s/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=\"-%{kernel_flavor}\"/" .config

# Refresh .config
make ARCH=%{ARCH_TYPE} olddefconfig

# Build kernel + modules
make %{?_smp_mflags} ARCH=%{ARCH_TYPE}

%install
%define ARCH_TYPE x86

# Compute kernel release string
KREL=$(make -s ARCH=%{ARCH_TYPE} kernelrelease)
echo "Installing kernel with release string: ${KREL}"

# Install kernel artifacts to /boot
install -d %{buildroot}/boot
install -m 0644 arch/x86/boot/bzImage %{buildroot}/boot/vmlinuz-${KREL}
install -m 0644 System.map %{buildroot}/boot/System.map-${KREL}
install -m 0644 .config %{buildroot}/boot/config-${KREL}

# Install modules to /lib/modules (openSUSE standard location)
make ARCH=%{ARCH_TYPE} \
     INSTALL_MOD_PATH=%{buildroot} \
     DEPMOD=/bin/true \
     modules_install

# Remove build/source symlinks created by modules_install
rm -f %{buildroot}/lib/modules/${KREL}/build
rm -f %{buildroot}/lib/modules/${KREL}/source

# Prepare full kernel-devel tree
mkdir -p %{buildroot}/lib/modules/${KREL}/build

# Copy the complete source tree
rsync -a --exclude='*.o' \
         --exclude='*.ko' \
         --exclude='*.cmd' \
         --exclude='.tmp_*' \
         --exclude='*.mod.c' \
         --exclude='modules.order' \
         --exclude='Module.markers' \
         --exclude='.git*' \
         --exclude='Documentation' \
         . %{buildroot}/lib/modules/${KREL}/build/

# CRITICAL: Copy Module.symvers for ksym() dependency resolution
cp Module.symvers %{buildroot}/lib/modules/${KREL}/build/

# Ensure key files are present
cp System.map %{buildroot}/lib/modules/${KREL}/build/
cp .config %{buildroot}/lib/modules/${KREL}/build/

# Create source symlink (standard kernel convention)
ln -sf build %{buildroot}/lib/modules/${KREL}/source
# Create dracut config to omit rsync module
# This fixes failures in the OBS build environment
install -d %{buildroot}/etc/dracut.conf.d
cat > %{buildroot}/etc/dracut.conf.d/90-xanmod-edge.conf <<'EOF'
# Omit rsync module - not needed for basic initramfs
omit_dracutmodules+=" rsync "
EOF

# CRITICAL: Copy modules.builtin files manually
# make modules_install does not always copy them, but depmod and dracut NEED them
echo "Copying modules.builtin files..."
cp modules.builtin %{buildroot}/lib/modules/${KREL}/

# Copy modules.builtin.alias only if it exists (not present in all kernel versions)
if [ -f modules.builtin.alias ]; then
    cp modules.builtin.alias %{buildroot}/lib/modules/${KREL}/
fi

# Copy modules.builtin.modinfo only if it exists
if [ -f modules.builtin.modinfo ]; then
    cp modules.builtin.modinfo %{buildroot}/lib/modules/${KREL}/
fi

# CRITICAL: Copy Module.symvers to the module root
# The ksym scanner needs this to map symbols for all the .ko files
##########cp Module.symvers %{buildroot}/lib/modules/${KREL}/

# Skip depmod during build - it will run properly on target system in %post
# This avoids path issues in the OBS build environment
echo "Skipping depmod during build (will run in post on target system)..."

# Create convenience symlinks
ln -sf vmlinuz-${KREL} %{buildroot}/boot/vmlinuz-%{kernel_flavor}
ln -sf System.map-${KREL} %{buildroot}/boot/System.map-%{kernel_flavor}
ln -sf config-${KREL} %{buildroot}/boot/config-%{kernel_flavor}

# Save kernel release for post-install scripts
echo "${KREL}" > %{buildroot}/boot/.kernel-release-%{kernel_flavor}

%post
KREL=$(cat /boot/.kernel-release-%{kernel_flavor} 2>/dev/null || echo "")

if [ -n "${KREL}" ] && [ -d "/lib/modules/${KREL}" ]; then
    echo "Regenerating module dependencies for ${KREL}..."
    /sbin/depmod -a "${KREL}" || true
    
    echo "Generating initramfs for kernel ${KREL}..."
    /usr/bin/dracut --force --hostonly --kver "${KREL}" /boot/initrd-${KREL} || true
    
    # Update bootloader if using grub2
    if [ -x /usr/sbin/grub2-mkconfig ]; then
        echo "Updating bootloader configuration..."
        /usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg || true
    fi
fi

%preun
# Only on uninstall (not upgrade)
if [ "$1" = "0" ]; then
    KREL=$(cat /boot/.kernel-release-%{kernel_flavor} 2>/dev/null || echo "")
    if [ -n "${KREL}" ]; then
        echo "Removing initramfs for kernel ${KREL}..."
        rm -f /boot/initrd-${KREL}
    fi
fi

%postun
# Update bootloader after removal
if [ "$1" = "0" ]; then
    if [ -x /usr/sbin/grub2-mkconfig ]; then
        /usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg || true
    fi
fi

%files
%defattr(-,root,root)
/boot/vmlinuz-*%{kernel_flavor}*
/boot/System.map-*%{kernel_flavor}*
/boot/config-*%{kernel_flavor}*
/boot/.kernel-release-%{kernel_flavor}
/lib/modules/*%{kernel_flavor}*
%dir /etc/dracut.conf.d
%config(noreplace) /etc/dracut.conf.d/90-xanmod-edge.conf
%exclude /lib/modules/*%{kernel_flavor}*/build
%exclude /lib/modules/*%{kernel_flavor}*/source

%files devel
%defattr(-,root,root)
/lib/modules/*%{kernel_flavor}*/build
/lib/modules/*%{kernel_flavor}*/source

%changelog
* Sun Nov 16 2025 itachi_re <xanbenson99@gmail.com> - 6.17.5-xanmod3
- CRITICAL FIX: Added dracut conf to omit 'rsync' module
- This fixes the 'Failed to install 'rsync'' error in OBS
- Kept --hostonly flag in post for a small, fast initrd on user's machine

* Sat Nov 15 2025 itachi_re <xanbenson99@gmail.com> - 6.17.5-xanmod2
- CRITICAL FIX: Added modules.builtin* files to module directory
- These files are required by dracut to build initramfs correctly
- Corrected module installation path to /lib/modules (openSUSE standard)
- Fixed depmod basedir to match actual module location
- Restored proper dependency generation for ksym() matching

* Sat Nov 15 2025 itachi_re <xanbenson99@gmail.com> - 6.17.5-xanmod1
- Fixed boot hang by restoring proper dependency generation
- Corrected build/ tree to include full source for depmod
- Added Module.symvers to build/ tree for external module compilation

* Sun Nov 09 2025 itachi_re <xanbenson99@gmail.com> - 6.17.5-5
- Build 5: Additional optimizations and fixes
- Improved version control for clean package naming

* Sun Nov 09 2025 itachi_re <xanbenson99@gmail.com> - 6.17.5-1
- Updated to XanMod 6.17.5
- Improved version control and package naming

* Sun Aug 24 2025 itachi_re <xanbenson99@gmail.com>
- Initial XanMod Edge kernel for openSUSE Tumbleweed
openSUSE Build Service is sponsored by