# -*- Mode: rpm-spec -*-
#
# This Specfile is based on kernel-tmb spec done by
# Thomas Backlund <tmb@mandriva.org>
#
# The mkflavour() macroization done by Anssi Hannula <anssi@mandriva.org>
#
# ----------------------------------------------------------------------------
# Consult this page for extra docs:
#
# 	https://wiki.mageia.org/en/Kernel_update_workflow
#
# (feel free to adjust the wiki-page when adding or removing features
# to the spec file).
#
# After building a new kernel, remember to push:
#
# kmod-virtualbox
# kmod-vboxadditions
# kmod-xtables-addons
# drakx-installer-images (both core and nonfree)
# ----------------------------------------------------------------------------
# 
# Aarch64 still has problems with multithreaded rpmbuild 4.15-rc
%if 0%{?mageia} >= 8
%ifarch aarch64
%global _smp_nthreads_max 1
%endif
%endif

#
# Mageia kernels use kernel.org versioning
#
%define kernelversion	6
# WARNING: when patchlevel is bumped, please update drakx/kernel/list_modules.pm for new modules!!!
%define patchlevel	1
# sublevel is now used for -stable patches
%define sublevel	23

# Package release
%define mgarel		1.lowlatency

# kernel Makefile extraversion is substituted by
# rcX which are either 0 (empty), X (as in rcX)
%define rcX		0

# kernel base name (also name of srpm)
%define kname		kernel

# Patch tarball tag
%define ktag		mga

%define rpmtag		%{distsuffix}%{mgaver}
%if %{rcX}
%define rpmrel		%mkrel 0.rc%{rcX}.%{mgarel}
%else
%define rpmrel		%mkrel %{mgarel}
%endif

# fakerel and fakever never change, they are used to fool
# rpm/urpmi/smart and ensure the kernels are installed,
# not upgraded so old kernel is not overwritten or removed
%define fakever		1
%define fakerel	%mkrel	1

# version defines
%define kversion	%{kernelversion}.%{patchlevel}.%{sublevel}
%define kverrel		%{kversion}-%{rpmrel}

# When we are using a rcX patch, the tarball is a sublevel -1
%if %{rcX}
%if %sublevel
%define tar_ver		%{kernelversion}.%{patchlevel}
%else
%define tar_ver		%{kernelversion}.%(expr %{patchlevel} - 1)
%endif
%else
%define tar_ver		%{kernelversion}.%{patchlevel}
%endif

# Used for not making too long names for rpms or search paths
%if %rcX
%define buildrpmrel	0.rc%{rcX}.%{mgarel}%{rpmtag}
%else
%define buildrpmrel	%{mgarel}%{rpmtag}
%endif
%define buildrel	%{kversion}-%{buildrpmrel}

# libbpf major
%define bpfmajor	1

# Having different top level names for packges means that you have to remove
# them by hard :(
%define top_dir_name	%{kname}-%{_arch}

%define build_dir	${RPM_BUILD_DIR}/%{top_dir_name}
%define src_dir		%{build_dir}/linux-%{tar_ver}

# Disable useless debug rpms...
%global _enable_debug_packages	%{nil}
%global debug_package		%{nil}
%global __debug_package		%{nil}
%global __debug_install_post	%{nil}
%global _build_id_links		none

# no bytecompiling wanted as it breaks build on selftests we dont even ship
# for older buildsystems
%global _python_bytecompile_build 0
# for systems with >= rpm-mageia-setup-2.29-1.mga7
%global __brp_python_bytecompile %nil

# Build defines
%define build_doc		1
%define build_uheaders		1
%define build_source		1
%define build_devel		1

%define build_debug		0

# Build desktop i586 / 4GB
%ifarch %{ix86}
%define build_desktop586	0
%endif

# Build desktop (i686 / 64GB) / x86_64 / arm / aarch64
%define build_desktop		1

# Build server (i686 / 64GB)/x86_64 / aarch64
%ifnarch %{arm}
%define build_server		0
%else
%define build_server		0
%endif

# build cpupower
%ifnarch %{arm} aarch64
%define build_cpupower		0
%else
%define build_cpupower		0
%endif

# build perf
%define build_perf		0

# bpf
%define build_bpftool		0
%define build_libbpf		0

# compress modules with xz
%ifnarch %{arm}
%define build_modxz		1
%else
%define build_modxz		0
%endif
# End of user definitions

# buildtime override flags
%{?_without_desktop586: %global build_desktop586 0}
%{?_without_desktop: %global build_desktop 0}
%{?_without_server: %global build_server 0}
%{?_without_doc: %global build_doc 0}
%{?_without_uheaders: %global build_uheaders 0}
%{?_without_source: %global build_source 0}
%{?_without_devel: %global build_devel 0}
%{?_without_debug: %global build_debug 0}
%{?_without_perf: %global build_perf 0}
%{?_without_cpupower: %global build_cpupower 0}
%{?_without_bpftool: %global build_bpftool 0}
%{?_without_libbpf: %global build_libbpf 0}
%{?_without_modxz: %global build_modxz 0}

%{?_with_desktop586: %global build_desktop586 1}
%{?_with_desktop: %global build_desktop 1}
%{?_with_server: %global build_server 1}
%{?_with_doc: %global build_doc 1}
%{?_with_uheaders: %global build_uheaders 1}
%{?_with_source: %global build_source 1}
%{?_with_devel: %global build_devel 1}
%{?_with_debug: %global build_debug 1}
%{?_with_perf: %global build_perf 1}
%{?_with_cpupower: %global build_cpupower 1}
%{?_with_bpftool: %global build_bpftool 1}
%{?_with_libbpf: %global build_libbpf 1}
%{?_with_modxz: %global build_modxz 1}

# For the .nosrc.rpm
%define build_nosrc	0
%{?_with_nosrc: %global build_nosrc 1}

%if %(if [ -z "$CC" ] ; then echo 0; else echo 1; fi)
%define kmake %make_build CC="$CC"
%else
%define kmake %make_build
%endif
# there are places where parallel make don't work
%define smake make

# Parallelize xargs invocations on smp machines
%define kxargs xargs %([ -z "$RPM_BUILD_NCPUS" ] \\\
	&& RPM_BUILD_NCPUS="`/usr/bin/getconf _NPROCESSORS_ONLN`"; \\\
	[ "$RPM_BUILD_NCPUS" -gt 1 ] && echo "-P $RPM_BUILD_NCPUS")

# arm(64) arch matching
%define target_arch	%(echo %{_arch} | sed -e 's/arm.*/arm/' -e 's/aarch64/arm64/')


#
# SRC RPM description
#
Summary:	Linux kernel built for Mageia
Name:		%{kname}
Version:	%{kversion}
Release:	%{rpmrel}
License:	GPLv2
Group:		System/Kernel and hardware
ExclusiveArch:	%{ix86} x86_64 %{arm} aarch64
ExclusiveOS:	Linux
URL:		https://www.kernel.org/

####################################################################
#
# Sources
#
### This is for full SRC RPM
Source0:	https://cdn.kernel.org/pub/linux/kernel/v%{kernelversion}.x/linux-%{tar_ver}.tar.xz
Source1:	https://cdn.kernel.org/pub/linux/kernel/v%{kernelversion}.x/linux-%{tar_ver}.tar.sign
### This is for stripped SRC RPM
%if %build_nosrc
NoSource: 0
%endif
# This is for disabling *config, mrproper, prepare, scripts on -devel rpms
Source2:	disable-mrproper-in-devel-rpms.patch

Source4:	README.kernel-sources

# for creating stable queue patchlist
Source5:	generate-patchlist.sh

# copy to patched source tree along with the defconfigs and run it
Source10:	defconfig-updater.sh
Source09:	defconfig-updater-simple.sh
# x86_64 defconfigs
Source11:	defconfig-x86_64-desktop
Source12:	defconfig-x86_64-server
# i386 defconfigs
Source13:	defconfig-i386-desktop586
Source14:	defconfig-i386-desktop
Source15:	defconfig-i386-server
# arm64 defconfigs
Source16:	defconfig-arm64-desktop
Source17:	defconfig-arm64-server
# arm defconfigs
Source18:	defconfig-arm-desktop

# config and systemd service file from fedora
Source50:	cpupower.service
Source51:	cpupower.config

####################################################################
#
# Patches

#
# Patch0 to Patch10 are for core kernel upgrades.
#

%if %sublevel
Patch1:		https://cdn.kernel.org/pub/linux/kernel/v%{kernelversion}.x/patch-%{kernelversion}.%{patchlevel}.%{sublevel}.xz
%endif
%if %{rcX}
# (tmb) Created with:
# wget https://git.kernel.org/torvalds/p/v5.10-rc7/v5.9 -O patch-5.10-rc7
# xz -6e patch-5.10-rc7
Patch2:		patch-%{kernelversion}.%{patchlevel}-rc%{rcX}.xz
%endif

###
### Stable Queue coalesced in one single Patch
###
Patch090:	stable-queue-coalesced-6.1-20230410.patch

###
### Stable Queue can be big
### Patches from 100-999
###

### add patches here by copying contents of kernel matching queue-x.y from:
### https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git/tree/
### to SOURCES, generate patchlist with generate-patchlist.sh and paste it here
###

###
### Arch
### Patches from 1000
###

# laptop needing pci=assign-busses (#18989, needs to be submitted upstream)
Patch1000:	x86-pci-toshiba-equium-a60-assign-busses.patch

# If users choose a bad video mode, allow to jump to
# a working one (TTL: forever)
Patch1001:	x86-boot-video-80x25-if-break.patch

# Allow poweroff on UP machines running SMP kernels
Patch1005:	x86-default_poweroff_up_machines.patch

# raise vmalloc to fix https://bugs.mageia.org/show_bug.cgi?id=904
Patch1010:	x86-increase-default-minimum-vmalloc-area-by-64MB-to-192MB.patch

# slows down boot
Patch1015:	Revert-cpufreq-pcc-Enable-autoload-of-pcc-cpufreq-fo.patch

# 6.1.7 breakage
Patch1020:	Revert-x86-pat-Fix-pat_x_mtrr_type-for-MTRR-disabled.patch

###
### ACPI
### 

# CLEVO M360S acpi irq workaround
Patch1100:	acpi-CLEVO-M360S-disable_acpi_irq.patch

# Clevo M720SR freezes with C3
Patch1105:	acpi-processor-M720SR-limit-to-C2.patch

# ACPI PM fixes (TTL: 5.18)
Patch1130:	x86-ACPI-State-Optimize-C3-entry-on-AMD-CPUs.patch

###
### Block
###

# FIXME: Don't know know why this is needed
Patch1200:	scsi-megaraid-new-sysfs-name.patch

# adds aliases to support upgrade from old dm-raid45 patch
Patch1215:	dm-raid-aliases.patch

# disable floppy autoloading (mga #4696)
Patch1220:	block-floppy-disable-pnp-modalias.patch

###
### bpf
###

###
### Crypto
###

###
### dma
###

###
### File-system
###

###
### FireWire
###

# adding module aliases to ease upgrade from ieee1394
Patch1400:	firewire-ieee1394-module-aliases.patch

###
### Firmware
###

###
### GPU/DRM
###

# mga compat option
Patch1500:	drm-gpu-drm-treat-nokmsboot-as-nomodeset.patch

# amdgpu
# switch SI and CIK from radeon to amdgpu
Patch1520:	drm-amdgpu-SI-and-CIK-enabled-by-default.patch
#

# new Q57 Host Bridge id
Patch1530:	char-agp-intel-new-Q57-id.patch

# i915
# TGL
Patch1546:	drm-i915-psr-Disable-PSR2-selective-fetch-for-all-TGL-steps.patch
# DG2
Patch1547:	drm-i915-dg2-Drop-force_probe-requirement.patch

# https://bugzilla.kernel.org/show_bug.cgi?id=206653#c19
Patch1552:	i2c_nvidia_gpu-change-err-into-info.patch

###
### gpio
###

###
### hwmon
###

###
### i2c
###

###
### io_uring
###

###
### iommu
###

###
### Input
###

###
### HID
###

# surface bits
# from: https://github.com/linux-surface
Patch1750:	hid-Add-support-for-Intel-Precise-Touch-and-Stylus.patch
Patch1751:	hid-Add-support-for-Intel-Touch-Host-Controller.patch
Patch1752:	iommu-intel-Disable-source-id-verification-for-ITHC.patch

###
### kernel
###

# zstd 1.5.2 (TTL: 6.2)
Patch1800:	lib-zstd-clean-up-double-word-in-comment.patch
Patch1801:	MAINTAINERS-git-github-https-github.com-for-terrelln.patch
Patch1802:	lib-zstd-fix-repeated-words-in-comments.patch
Patch1803:	lib-zstd-Fix-comment-typo.patch
Patch1804:	zstd-Move-zstd-common-module-exports-to-zstd_common_.patch
Patch1805:	zstd-import-usptream-v1.5.2.patch

###
### MFD
###

###
### MM
###

# MGLRU performance fixes
Patch1860:	mm-add-vma_has_recency.patch
Patch1861:	mm-support-posix_fadv_noreuse.patch

###
### Network
###

# SiS 190 fixes
Patch1900:	net-sis190-fix-list-usage.patch

# netfilter IFWLOG support
Patch1910:	net-netfilter-IFWLOG.patch
Patch1911:	net-netfilter-IFWLOG-mdv.patch
Patch1912:	net-netfilter-IFWLOG-2.6.35-buildfix.patch
Patch1913:	net-netfilter-IFWLOG-2.6.37-buildfix.patch
Patch1914:	net-ipv4-netfilter-ipt_IFWLOG-3.6-buildfix.patch
Patch1915:	net-netfilter-IFWLOG-3.7-buildfix.patch
Patch1916:	net-netfilter-IFWLOG-remove-unused-label.patch
Patch1917:	net-netfilter-ipt_IFWLOG-4.12-buildfix.patch
Patch1918:	net-netfilter-IFWLOG-5.0-buildfix.patch

# netfilter psd support
Patch1920:	net-netfilter-psd.patch
Patch1921:	net-netfilter-psd-mdv.patch
Patch1922:	net-netfilter-psd-2.6.35-buildfix.patch
Patch1923:	net-netfilter-psd-fix-redefines.patch

# rtw88 wifi
# add alias for the replaced r8822be staging driver
Patch1930:	net-wireless-rtw88-add-r8822be-alias.patch
# add alias for the replaced 8723de 3rdparty driver
Patch1931:	net-wireless-rtw88-add-8723de-alias.patch
# add support for 8723DU, 8821CU, 8822BU, 8822CU (TTL 6.2)
Patch1932:	net-wireless-rtw88-6.2-git.patch
Patch1933:	wifi-rtw88-usb-Set-qsel-correctly.patch
Patch1934:	wifi-rtw88-usb-send-Zero-length-packets-if-necessary.patch
Patch1935:	wifi-rtw88-usb-drop-now-unnecessary-URB-size-check.patch

# rtw89 wifi
# add support for 8852B, 8852BE (TTL 6.2)
Patch1940:	net-wireless-rtw89-6.2-git.patch

# iwlfiwi
Patch1980:	net-wireless-iwlwifi-add-new-pci-id-for-6235.patch
Patch1981:	wifi-iwlwifi-pcie-add-support-for-AX101NGW.patch

###
### PCI
###

###
### pinctrl
###

###
### Platform
###

# Allow access to Shuttle WMI interface controls
# (Mainly allow turning on/off webcam and wireless on Shuttle DA18IE and DA18IM)
Patch2050:	platform-x86-add-shuttle-wmi-driver.patch
Patch2051:	platform-x86-shuttle-wmi-drop-devinit-exit.patch
Patch2052:	platform-x86-shuttle-wmi-4.2-buildfix.patch
Patch2053:	platform-x86-shuttle-wmi-4.13-buildfix.patch
Patch2054:	platform-x86-shuttle-wmi-kernel-5.5.patch

###
### PM
###

###
### Sound
###

###
### SPI
###

###
### Staging
###

# add rtl8812 support (mga#21043)
# from https://github.com/aircrack-ng/rtl8812au.git
Patch2200:	staging-rtl8812au.patch
Patch2201:	staging-rtl8812au-rename.patch
Patch2202:	staging-rtl8812au-Kconfig-Makefile.patch

###
### Thermal
###

###
### Thunderbolt
###

###
### tpm
###

###
### USB
###

Patch2300:	hid-usbhid-IBM-BladeCenterHS20-quirk.patch

Patch2310:	usb-storage-unusual_devs-add-id.patch
Patch2311:	usb-storage-unusual_devs-add-id-2.6.37-buildfix.patch

###
### V4L
###

# pwc driver name in /proc/bus/devices, /sys fix and "advertisement" removal
Patch2400:	media-usb-pwc-lie-in-proc-usb-devices.patch

###
### Video
###

# Mageia framebuffer boot logo
Patch2500:	video-mageia-logo.patch

###
### Virt
###

# fix gcc-10 build
Patch2550:	KVM-squelch-uninitialized-variable-warning.patch

###
### Tools
###

# wipe powerpc refrence so we can nuke dangling symlinks (mga#17676)
Patch2600:	tools-testing-selftest-Makefile-remove-powerpc-reference.patch

# fix perf build
Patch2605:	tools-perf-ui-include-slang.patch

###
### UAPI
###

Patch2700:	uapi-avoid-namespace-conflict-in-linux-posix_types.h.patch

###
### Python fixes
###
Patch4000:	linux-6.1-python3.patch

###
### TTY
###

# broken rtla cleaner
Patch6000:	hack-broken-rtla-cleaner.patch


### Fixes from FC kernel
# Inspur Advantech PCI ids
Patch7000:	0001-scsi-smartpqi-add-inspur-advantech-ids.patch
# Vulcan AHCI PCI bar (aarch64)
Patch7001:	0001-Vulcan-AHCI-PCI-bar-fix-for-Broadcom-Vulcan-early-si.patch

### Patches for low latency
#
# amd-pstate
Patch20000:	0001-ACPI-CPPC-Add-AMD-pstate-energy-performance-preferen.patch
Patch20001:	0002-Documentation-amd-pstate-add-EPP-profiles-introducti.patch
Patch20002:	0003-cpufreq-amd-pstate-optimize-driver-working-mode-sele.patch
Patch20003:	0004-cpufreq-amd-pstate-implement-Pstate-EPP-support-for-.patch
Patch20004:	0005-cpufreq-amd-pstate-implement-amd-pstate-cpu-online-a.patch
Patch20005:	0006-cpufreq-amd-pstate-implement-suspend-and-resume-call.patch
Patch20006:	0007-cpufreq-amd-pstate-add-driver-working-mode-switch-su.patch
Patch20007:	0008-Documentation-amd-pstate-add-amd-pstate-driver-mode-.patch
Patch20008:	0009-Documentation-introduce-amd-pstate-active-mode-kerne.patch
Patch20009:	0010-cpufreq-amd-pstate-convert-sprintf-with-sysfs_emit.patch
Patch20010:	0011-Documentation-amd-pstate-introduce-new-global-sysfs-.patch
Patch20011:	0012-cpufreq-Make-cpufreq_unregister_driver-return-void-rediff.patch
Patch20012:	0013-acpi-cppc-Add-min-and-max-perf-reg-writing-support.patch
Patch20013:	0014-acpi-cppc-Add-auto-select-register-read-write-suppor.patch
Patch20014:	0015-Documentation-cpufreq-amd-pstate-Move-amd_pstate-par.patch
Patch20015:	0016-cpufreq-amd-pstate-Add-guided-autonomous-mode.patch
Patch20016:	0017-cpufreq-amd-pstate-Add-guided-mode-control-support-v.patch
Patch20017:	0018-Documentation-cpufreq-amd-pstate-Update-amd_pstate-s.patch
Patch20018:	0019-cpufreq-amd-pstate-avoid-uninitialized-variable-use.patch
Patch20019:	0020-cpufreq-amd_pstate-Fix-invalid-write-to-MSR_AMD_CPPC.patch
Patch20020:	0021-Documentation-amd-pstate-disambiguate-user-space-sec.patch
#
# v4l2loopback
Patch21000:	0001-media-v4l2-core-add-v4l2loopback.patch
#
# wine sync futex
Patch22000:	0001-winesync-Introduce-the-winesync-driver-and-character.patch
#
# bore scheduler
Patch23000:	0001-linux6.1-bore1.7.10.patch
#
# bbr2
Patch24000:	0001-net-tcp_bbr-broaden-app-limited-rate-sample-detectio.patch
Patch24001:	0002-net-tcp_bbr-v2-shrink-delivered_mstamp-first_tx_msta.patch
Patch24002:	0003-net-tcp_bbr-v2-snapshot-packets-in-flight-at-transmi.patch
Patch24003:	0004-net-tcp_bbr-v2-count-packets-lost-over-TCP-rate-samp.patch
Patch24004:	0005-net-tcp_bbr-v2-export-FLAG_ECE-in-rate_sample.is_ece.patch
Patch24005:	0006-net-tcp_bbr-v2-introduce-ca_ops-skb_marked_lost-CC-m.patch
Patch24006:	0007-net-tcp_bbr-v2-factor-out-tx.in_flight-setting-into-.patch
Patch24007:	0008-net-tcp_bbr-v2-adjust-skb-tx.in_flight-upon-merge-in.patch
Patch24008:	0009-net-tcp_bbr-v2-adjust-skb-tx.in_flight-upon-split-in.patch
Patch24009:	0010-net-tcp_bbr-v2-set-tx.in_flight-for-skbs-in-repair-w.patch
Patch24010:	0011-net-tcp-add-new-ca-opts-flag-TCP_CONG_WANTS_CE_EVENT.patch
Patch24011:	0012-net-tcp-re-generalize-TSO-sizing-in-TCP-CC-module-AP.patch
Patch24012:	0013-net-tcp-add-fast_ack_mode-1-skip-rwin-check-in-tcp_f.patch
Patch24013:	0014-net-tcp_bbr-v2-BBRv2-bbr2-congestion-control-for-Lin.patch
Patch24014:	0015-net-test-add-.config-for-kernel-circa-v5.10-with-man.patch
Patch24015:	0016-net-test-adds-a-gce-install.sh-script-to-build-and-i.patch
Patch24016:	0017-net-test-scripts-for-testing-bbr2-with-upstream-Linu.patch
Patch24017:	0018-net-tcp_bbr-v2-add-a-README.md-for-TCP-BBR-v2-alpha-.patch
Patch24018:	0019-net-tcp_bbr-v2-remove-unnecessary-rs.delivered_ce-lo.patch
Patch24019:	0020-net-gbuild-add-Gconfig.bbr2-to-gbuild-kernel-with-CO.patch
Patch24020:	0021-net-tcp_bbr-v2-remove-field-bw_rtts-that-is-unused-i.patch
Patch24021:	0022-net-tcp_bbr-v2-remove-cycle_rand-parameter-that-is-u.patch
Patch24022:	0023-net-test-use-crt-namespace-when-nsperf-disables-crt..patch
Patch24023:	0024-net-tcp_bbr-v2-don-t-assume-prior_cwnd-was-set-enter.patch
Patch24024:	0025-net-tcp_bbr-v2-Fix-missing-ECT-markings-on-retransmi.patch
Patch24025:	0026-ZEN-Remove-BBRv2-files-unused-by-kernel-build-system.patch
Patch24026:	0027-tcp_bbr2-use-correct-64-bit-division.patch
#
# zen interactive
Patch25000:	0002-ZEN-Add-VHBA-driver.patch
Patch25001:	0003-ZEN-Add-OpenRGB-patches.patch
Patch25002:	0004-ZEN-Add-ACS-override-support-rediff.patch
Patch25003:	0005-ZEN-PCI-Add-Intel-remapped-NVMe-device-support.patch
Patch25004:	0006-ZEN-Add-graysky-s-more-uarches-alt.patch
Patch25005:	0007-ZEN-Restore-CONFIG_OPTIMIZE_FOR_PERFORMANCE_O3.patch
Patch25006:	0008-ZEN-Disable-stack-conservation-for-GCC.patch
Patch25007:	0009-ZEN-Initialize-ata-before-graphics.patch
Patch25008:	0010-ZEN-Input-evdev-use-call_rcu-when-detaching-client.patch
Source25009:	0011-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-C.patch
Patch25010:	0012-ZEN-cpufreq-Remove-schedutil-dependency-on-Intel-AMD.patch
Patch25011:	0013-ZEN-intel-pstate-Implement-enable-parameter.patch
Patch25012:	0014-ZEN-mm-Disable-watermark-boosting-by-default.patch
Patch25013:	0015-ZEN-mm-Stop-kswapd-early-when-nothing-s-waiting-for-.patch
Patch25014:	0016-ZEN-mm-Increment-kswapd_waiters-for-throttled-direct.patch
Patch25015:	0017-ZEN-mm-Lower-the-non-hugetlbpage-pageblock-size-to-r.patch
Patch25016:	0018-ZEN-mm-Don-t-hog-the-CPU-and-zone-lock-in-rmqueue_bu.patch
Patch25017:	0019-ZEN-INTERACTIVE-Base-config-item.patch
Patch25018:	0020-ZEN-INTERACTIVE-Use-BFQ-as-the-elevator-for-SQ-devic.patch
Patch25019:	0021-ZEN-INTERACTIVE-Use-Kyber-as-the-elevator-for-MQ-dev.patch
Patch25020:	0022-ZEN-INTERACTIVE-Enable-background-reclaim-of-hugepag.patch
Patch25021:	0023-ZEN-INTERACTIVE-Tune-mgLRU-to-protect-cache-used-in-.patch
Source25022:	0026-ZEN-INTERACTIVE-mm-Disable-unevictable-compaction.patch
Source25023:	0027-ZEN-INTERACTIVE-mm-Disable-proactive-compaction-by-d.patch
Patch25024:	0028-ZEN-INTERACTIVE-dm-crypt-Disable-workqueues-for-cryp.patch
# skip
Source25025:	0029-ZEN-INTERACTIVE-mm-swap-Disable-swap-in-readahead.patch
Source25026:	0030-ZEN-INTERACTIVE-Document-PDS-BMQ-configuration.patch
Patch25027:	0031-fixup-ZEN-INTERACTIVE-dm-crypt-Disable-workqueues-fo.patch
#
# latency nice
#Patch26000:	0001-Add-latency-priority-for-CFS-class-rediff.patch
#
# xanmod
Source26500:	0001-XANMOD-x86-build-Add-more-x86_64-optimizations.patch
Source26501:	0004-XANMOD-rcu-Change-sched_setscheduler_nocheck-calls-t.patch
Source26502:	0005-XANMOD-block-mq-deadline-Increase-write-priority-to-.patch
Source26503:	0006-XANMOD-block-mq-deadline-Disable-front_merges-by-def.patch
Source26504:	0007-XANMOD-block-set-rq_affinity-to-force-full-multithre.patch
Source26505:	0008-XANMOD-kconfig-add-500Hz-timer-interrupt-kernel-conf.patch
Source26506:	0009-XANMOD-dcache-cache_pressure-50-decreases-the-rate-a.patch
Source26507:	0010-XANMOD-mm-vmscan-vm_swappiness-30-decreases-the-amou.patch
Source26508:	0011-XANMOD-sched-autogroup-Add-kernel-parameter-and-conf.patch
Source26509:	0012-XANMOD-cpufreq-tunes-ondemand-and-conservative-gover.patch
Source26510:	0013-XANMOD-lib-kconfig.debug-disable-default-CONFIG_SYMB.patch
Source26511:	0014-XANMOD-Makefile-Disable-GCC-vectorization-on-trees.patch
Source26512:	0015-XANMOD-scripts-setlocalversion-remove-tag-for-git-re.patch
Source26513:	0016-XANMOD-scripts-setlocalversion-Move-localversion-fil.patch
#
# xfs
Patch27000:	0001-xfs-write-page-faults-in-iomap-are-not-buffered-writ.patch
Patch27001:	0002-xfs-fully-initialize-xfs_da_args-in-xchk_directory_b.patch
Patch27002:	0003-xfs-don-t-track-the-AGFL-buffer-in-the-scrub-AG-cont.patch
Patch27003:	0004-xfs-log-the-AGI-AGF-buffers-when-rolling-transaction.patch
Patch27004:	0005-xfs-standardize-GFP-flags-usage-in-online-scrub.patch
Patch27005:	0006-xfs-make-AGFL-repair-function-avoid-crosslinked-bloc.patch
Patch27006:	0007-xfs-return-EINTR-when-a-fatal-signal-terminates-scru.patch
Patch27007:	0008-xfs-fix-return-code-when-fatal-signal-encountered-du.patch
Patch27008:	0009-xfs-initialize-the-check_owner-object-fully.patch
Patch27009:	0010-xfs-don-t-retry-repairs-harder-when-EAGAIN-is-return.patch
Patch27010:	0011-xfs-pivot-online-scrub-away-from-kmem.-ch.patch
Patch27011:	0012-xfs-load-rtbitmap-and-rtsummary-extent-mapping-btree.patch
Patch27012:	0013-xfs-skip-fscounters-comparisons-when-the-scan-is-inc.patch
Patch27013:	0014-xfs-don-t-return-EFSCORRUPTED-from-repair-when-resou.patch
Patch27014:	0015-xfs-make-rtbitmap-ILOCKing-consistent-when-scanning-.patch
Patch27015:	0016-xfs-online-checking-of-the-free-rt-extent-count.patch
Patch27016:	0017-xfs-fix-perag-loop-in-xchk_bmap_check_rmaps.patch
Patch27017:	0018-xfs-teach-scrub-to-check-for-adjacent-bmaps-when-rma.patch
Patch27018:	0019-xfs-block-map-scrub-should-handle-incore-delalloc-re.patch
Patch27019:	0020-xfs-check-quota-files-for-unwritten-extents.patch
Patch27020:	0021-xfs-check-that-CoW-fork-extents-are-not-shared.patch
Patch27021:	0022-xfs-teach-scrub-to-flag-non-extents-format-cow-forks.patch
Patch27022:	0023-xfs-don-t-warn-about-files-that-are-exactly-s_maxbyt.patch
Patch27023:	0024-xfs-check-inode-core-when-scrubbing-metadata-files.patch
Patch27024:	0025-xfs-fix-incorrect-error-out-in-xfs_remove.patch
Patch27025:	0026-xfs-fix-sb-write-verify-for-lazysbcount.patch
Patch27026:	0027-xfs-Print-XFS-UUID-on-mount-and-umount-events.patch
Patch27027:	0028-xfs-fix-incorrect-i_nlink-caused-by-inode-racing.patch
Patch27028:	0029-xfs-punching-delalloc-extents-on-write-failure-is-ra.patch
Patch27029:	0030-xfs-use-byte-ranges-for-write-cleanup-ranges.patch
Patch27030:	0031-xfs-iomap-move-delalloc-punching-to-iomap.patch
Patch27031:	0032-iomap-buffered-write-failure-should-not-truncate-the.patch
Patch27032:	0033-xfs-xfs_bmap_punch_delalloc_range-should-take-a-byte.patch
Patch27033:	0034-iomap-write-iomap-validity-checks.patch
Patch27034:	0035-xfs-use-iomap_valid-method-to-detect-stale-cached-io.patch
Patch27035:	0036-xfs-drop-write-error-injection-is-unfixable-remove-i.patch
Patch27036:	0037-xfs-add-debug-knob-to-slow-down-writeback-for-fun.patch
Patch27037:	0038-xfs-add-debug-knob-to-slow-down-write-for-fun.patch
Patch27038:	0039-xfs-invalidate-block-device-page-cache-during-unmoun.patch
Patch27039:	0040-xfs-use-memcpy-not-strncpy-to-format-the-attr-prefix.patch
Patch27040:	0041-xfs-shut-up-Wuninitialized-in-xfsaild_push.patch
Patch27041:	0042-xfs-attach-dquots-to-inode-before-reading-data-cow-f.patch
Patch27042:	0043-xfs-wait-iclog-complete-before-tearing-down-AIL.patch
Patch27043:	0044-xfs-fix-super-block-buf-log-item-UAF-during-force-sh.patch
Patch27044:	0045-xfs-hoist-refcount-record-merge-predicates.patch
Patch27045:	0046-xfs-estimate-post-merge-refcounts-correctly.patch
Patch27046:	0047-xfs-get-rid-of-assert-from-xfs_btree_islastblock.patch
Patch27047:	0048-xfs-invalidate-xfs_bufs-when-allocating-cow-extents.patch
Patch27048:	0049-xfs-Remove-duplicated-include-in-xfs_iomap.c.patch
Patch27049:	0050-xfs-dquot-shrinker-doesn-t-check-for-XFS_DQFLAG_FREE.patch
Patch27050:	0051-iomap-directly-use-logical-block-size.patch
#
# hhoffstaette
Patch28000:	bfq-20221108-ignore-oom_bfqq-in-bfq_check_waker.patch
Patch28001:	block-20220930-001-remove-redundant-code-in-elv_unregister_queue.patch
Patch28002:	block-20220930-002-remove-unnecessary-check-in-wbt_enable_default.patch
Patch28003:	block-20220930-003-make-enable_state-more-accurate.patch
Patch28004:	block-20220930-004-dont-show-valid-wbt_lat_usec-in-sysfs-while-wbt-is-disabled.patch
Patch28005:	block-20220930-005-add-new-field-flags-in-struct-elevator_queue.patch
Patch28006:	block-20220930-006-dont-enable-throttling-if-default-elevator-is-bfq.patch
Patch28007:	btrfs-20220909-skip-update-of-block-group-item-if-used-bytes-are-the-same.patch
Patch28008:	btrfs-20230306-fix-block-group-item-corruption-after-inserting-new-block-group.patch
Patch28009:	epoll-20221206-ep_autoremove_wake_function-should-use-list_del_init_careful.patch
Patch28010:	xfs-20221226-dont-assert-if-cmap-covers-imap-after-cycling-lock.patch
Patch28011:	xfs-20221226-fix-off-by-one-error-in-xfs_btree_space_to_height.patch
Patch28012:	xfs-20221226-get-root-inode-correctly-at-bulkstat.patch
Patch28013:	xfs-20221227-fix-deadlock-on-xfs_inodegc_worker.patch
Patch28014:	xfs-20230103-fix-extent-busy-updating.patch
Patch28015:	xfs-20230210-fix-uninitialized-variable-access.patch
#
# bitmap
Patch29000:	0001-bitmap-switch-from-inline-to-__always_inline.patch
#
# ddci-patches
Patch32000:	0001-drivers-ddcci-add-drivers-for-DDCCI.patch
Patch32001:	0002-drivers-ddcci-add-drivers-for-DDCCI.patch
Patch32002:	0003-drivers-ddcci-add-drivers-for-DDCCI.patch
Patch32003:	0004-ddcci-6.1-update-to-the-latest-git-HEAD.patch
Patch32004:	0005-ddcci-6.1-fix-UnicodeDecodeError-for-htmldocs.patch
Patch32005:	0006-ddcci-6.1-fix-bullet-list-newlines.patch
#
# drm
#Patch33000:	0001-drm-display-Don-t-block-HDR_OUTPUT_METADATA-on-unkno.patch
#Patch33001:	0002-drm-connector-print-max_requested_bpc-in-state-debug.patch

#Patch33002:	0003-drm-connector-Drop-COLORIMETRY_NO_DATA.patch
#Patch33003:	0004-drm-connector-Convert-DRM_MODE_COLORIMETRY-to-enum.patch
#Patch33004:	0005-drm-connector-Pull-out-common-create_colorspace_prop.patch
#Patch33005:	0006-drm-connector-Allow-drivers-to-pass-list-of-supporte.patch
#Patch33006:	0007-drm-connector-Print-connector-colorspace-in-state-de.patch
#Patch33007:	0008-drm-amd-display-Always-pass-connector_state-to-strea.patch
#Patch33008:	0009-drm-amd-display-Register-Colorspace-property-for-DP-.patch
#Patch33009:	0010-drm-amd-display-Set-colorspace-for-HDMI-infoframe.patch
#Patch33010:	0011-drm-amd-display-Send-correct-DP-colorspace-infopacke.patch
#Patch33011:	0012-drm-amd-display-Always-set-crtcinfo-from-create_stre.patch
#Patch33012:	0013-drm-amd-display-Add-support-for-explicit-BT601_YCC.patch
#Patch33013:	0014-drm-amd-display-Add-debugfs-for-testing-output-color.patch
#Patch33014:	0015-drm-amd-display-Add-default-case-for-output_color_sp.patch
#Patch33015:	0016-drm-amd-display-Don-t-restrict-bpc-to-8-bpc.patch
#Patch33016:	0017-drm-amd-display-Fallback-to-2020_YCBCR-if-the-pixel-.patch
#Patch33017:	0018-drm-amd-display-Refactor-avi_info_frame-colorimetry-.patch
#Patch33018:	0019-drm-amd-display-Use-COLORIMETRYEX_BT2020YCC-for-COLO.patch
#Patch33019:	0020-drm-amd-display-Calculate-output_color_space-after-p.patch
#Patch33020:	0021-drm-amd-display-Hook-up-content_type-property.patch
#Patch33021:	0022-drm-amd-display-Remove-unused-display_content_suppor.patch
#
# ext4
Patch34000:	0001-fs-ext4-replace-ternary-operator-with-min-max-and-mi.patch
Patch34001:	0002-ext4-remove-redundant-variable-err.patch
Patch34002:	0003-ext4-check-the-return-value-of-ext4_xattr_inode_dec_.patch
Patch34003:	0004-ext4-split-ext4_journal_start-trace-for-debug.patch
Patch34004:	0005-ext4-simplify-fast-commit-CRC-calculation.patch
Patch34005:	0006-ext4-init-quota-for-old.inode-in-ext4_rename.patch
Patch34006:	0007-ext4-print-file-system-UUID-on-mount-remount-and-unm.patch
Patch34007:	0008-ext4-replace-kmem_cache_create-with-KMEM_CACHE.patch
Patch34008:	0009-ext4-make-ext4_mb_initialize_context-return-void.patch
#Patch34009:	0010-ext4-handle-redirtying-in-ext4_bio_write_page.patch
#Patch34010:	0011-ext4-move-keep_towrite-handling-to-ext4_bio_write_pa.patch
#Patch34011:	0012-ext4-remove-nr_submitted-from-ext4_bio_write_page.patch
#Patch34012:	0013-ext4-drop-pointless-IO-submission-from-ext4_bio_writ.patch
Patch34013:	0014-ext4-add-support-for-writepages-calls-that-cannot-ma.patch
Patch34014:	0015-ext4-provide-ext4_do_writepages.patch
Patch34015:	0016-ext4-move-percpu_rwsem-protection-into-ext4_writepag.patch
Patch34016:	0017-ext4-switch-to-using-ext4_do_writepages-for-ordered-.patch
Patch34017:	0018-jbd2-switch-jbd2_submit_inode_data-to-use-fs-provide.patch
Patch34018:	0019-ext4-switch-to-using-write_cache_pages-for-data-jour.patch
Patch34019:	0020-mm-export-buffer_migrate_folio_norefs.patch
Patch34020:	0021-ext4-stop-providing-.writepage-hook.patch
#
# fixes misc (subset)
Patch35000:	0001-mm-Change-dirty-writeback-defaults.patch
Patch35001:	0003-leds-trigger-Add-block-device-LED-trigger.patch
Patch35002:	0004-docs-Add-block-device-blkdev-LED-trigger-documentati.patch
Patch35003:	0011-mm-vmscan-make-rotations-a-secondary-factor-in-balan.patch
Patch35004:	0012-objtool-Optimize-elf_dirty_reloc_sym.patch
Patch35005:	0013-kbuild-revive-parallel-execution-for-.tmp_initcalls..patch
Patch35006:	0014-padata-Do-not-mark-padata_mt_helper-as-__init.patch
Patch35007:	0015-modpost-Include-.text.-in-TEXT_SECTIONS.patch
Patch35008:	0017-Fix-sound-on-ASUS-Zenbook-UM5302TA.patch
Patch35009:	0019-mm-remove-PageMovable-export.patch
Source35010:	0020-hwmon-nct6775-Fix-incorrect-parenthesization-in-nct6.patch
# to review
Source35011:	0022-x86-acpi-boot-Do-not-register-processors-that-cannot.patch
Patch35012:	0023-kthread_worker-check-all-delayed-works-when-destroy-.patch
Patch35013:	0029-x86-pm-Force-out-of-line-memcpy.patch
Patch35014:	0030-mm-compaction-Rename-compact_control-rescan-to-finis.patch
Patch35015:	0031-mm-compaction-Check-if-a-page-has-been-captured-befo.patch
Patch35016:	0032-mm-compaction-Finish-scanning-the-current-pageblock-.patch
Patch35017:	0033-mm-compaction-Finish-pageblocks-on-complete-migratio.patch
Patch35018:	0034-Revert-Revert-mm-compaction-fix-set-skip-in-fast_fin.patch
Patch35019:	0035-x86-cpu-Use-cpu_feature_enabled-when-checking-global.patch
#
# bcachefs
Patch36000:	0001-bcachefs-6.1-introduce-bcachefs-patchset-rediff.patch
#
# mm-dmapool
Patch37000:	0001-dmapool-add-alloc-free-performance-test.patch
Patch37001:	0002-dmapool-remove-checks-for-dev-NULL.patch
Patch37002:	0003-dmapool-use-sysfs_emit-instead-of-scnprintf.patch
Patch37003:	0004-dmapool-cleanup-integer-types.patch
Patch37004:	0005-dmapool-speedup-DMAPOOL_DEBUG-with-init_on_alloc.patch
Patch37005:	0006-dmapool-move-debug-code-to-own-functions.patch
Patch37006:	0007-dmapool-rearrange-page-alloc-failure-handling.patch
Patch37007:	0008-dmapool-consolidate-page-initialization.patch
Patch37008:	0009-dmapool-simplify-freeing.patch
Patch37009:	0010-dmapool-don-t-memset-on-free-twice.patch
Patch37010:	0011-dmapool-link-blocks-across-pages.patch
Patch37011:	0012-dmapool-create-destroy-cleanup.patch
#
# ntfs3
Patch37100:	0001-fs-ntfs3-Add-comments-about-cluster-size.patch
Patch37101:	0002-fs-ntfs3-Add-hidedotfiles-option.patch
Patch37102:	0003-fs-ntfs3-Change-destroy_inode-to-free_inode.patch
Patch37103:	0004-fs-ntfs3-Add-option-nocase.patch
Patch37104:	0005-fs-ntfs3-Rename-variables-and-add-comment.patch
Patch37105:	0006-fs-ntfs3-Add-overflow-check-for-attribute-size.patch
Patch37106:	0007-Revert-ntfs3-rework-xattr-handlers-and-switch-to-POS.patch
Patch37107:	0008-fs-ntfs3-Fix-df-mask-display-in-proc-mounts.patch
Patch37108:	0009-fs-ntfs3-Use-kmalloc_array-for-allocating-multiple-e.patch
Patch37109:	0010-fs-ntfs3-Fix-junction-point-resolution.patch
Patch37110:	0011-fs-ntfs3-Use-strcmp-to-determine-attribute-type.patch
Patch37111:	0012-fs-ntfs3-Don-t-use-uni1-uninitialized-in-ntfs_d_comp.patch
Patch37112:	0013-fs-ntfs3-Eliminate-unnecessary-ternary-operator-in-n.patch
Patch37113:	0014-fs-ntfs3-Add-windows_names-mount-option.patch
Patch37114:	0015-fs-ntfs3-Document-windows_names-mount-option.patch
Patch37115:	0016-fs-ntfs3-Fix-hidedotfiles-mount-option-by-reversing-.patch
Patch37116:	0017-fs-ntfs3-Make-hidedotfiles-mount-option-work-when-re.patch
Patch37117:	0018-fs-ntfs3-Add-hidedotfiles-to-the-list-of-enabled-mou.patch
Patch37118:	0019-fs-ntfs3-Document-the-hidedotfiles-mount-option.patch
Patch37119:	0020-fs-ntfs3-Rename-hidedotfiles-mount-option-to-hide_do.patch
Patch37120:	0021-fs-ntfs3-Add-system.ntfs_attrib_be-extended-attribut.patch
Patch37121:	0022-fs-ntfs3-Document-system.ntfs_attrib_be-extended-att.patch
Patch37122:	0023-fs-ntfs3-Fix-endian-conversion-in-ni_fname_name.patch
Patch37123:	0024-fs-ntfs3-Add-functions-to-modify-LE-bitmaps.patch
Patch37124:	0025-fs-ntfs3-Use-_le-variants-of-bitops-functions.patch
Patch37125:	0026-fs-ntfs3-Add-ntfs_bitmap_weight_le-function-and-refa.patch
Patch37126:	0027-fs-ntfs3-Fix-sparse-problems.patch
Patch37127:	0028-fs-ntfs3-Remove-unused-functions.patch
Patch37128:	0029-fs-ntfs3-Simplify-ntfs_update_mftmirr-function.patch
Patch37129:	0030-fs-ntfs3-Fixing-work-with-sparse-clusters.patch
Patch37130:	0031-fs-ntfs3-Change-new-sparse-cluster-processing.patch
Patch37131:	0032-fs-ntfs3-Fix-wrong-indentations.patch
Patch37132:	0033-fs-ntfs3-atomic_open-implementation.patch
Patch37133:	0034-fs-ntfs3-Fixing-wrong-logic-in-attr_set_size-and-ntf.patch
Patch37134:	0035-fs-ntfs3-Changing-locking-in-ntfs_rename.patch
Patch37135:	0036-fs-ntfs3-Restore-correct-state-after-ENOSPC-in-attr_.patch
Patch37136:	0037-fs-ntfs3-Correct-ntfs_check_for_free_space.patch
Patch37137:	0038-fs-ntfs3-Check-fields-while-reading.patch
Patch37138:	0039-fs-ntfs3-Fix-incorrect-if-in-ntfs_set_acl_ex.patch
Patch37139:	0040-fs-ntfs3-Use-ALIGN-kernel-macro.patch
Patch37140:	0041-fs-ntfs3-Fix-wrong-if-in-hdr_first_de.patch
Patch37141:	0042-fs-ntfs3-Improve-checking-of-bad-clusters.patch
Patch37142:	0043-fs-ntfs3-Make-if-more-readable.patch
#
# zsmalloc patches
Patch37300:	0001-zsmalloc-rework-zspage-chain-size-selection.patch
Patch37301:	0002-zsmalloc-skip-chain-size-calculation-for-pow_of_2-cl.patch
Patch37302:	0003-zsmalloc-make-zspage-chain-size-configurable.patch
Patch37303:	0004-zsmalloc-set-default-zspage-chain-size-to-8.patch
#
# zswap patches
Patch37400:	0001-zswap-fix-writeback-lock-ordering-for-zsmalloc.patch
Patch37401:	0002-zpool-clean-out-dead-code.patch
Patch37402:	0003-zsmalloc-Consolidate-zs_pool-s-migrate_lock-and-size.patch
Patch37403:	0004-zsmalloc-Add-a-LRU-to-zs_pool-to-keep-track-of-zspag.patch
Patch37404:	0005-zsmalloc-Add-zpool_ops-field-to-zs_pool-to-store-evi.patch
Patch37405:	0006-zsmalloc-Implement-writeback-mechanism-for-zsmalloc.patch
#
# zstd 1.5.4
Patch37600:	0005-zstd-common-fix-repeated-words-in-comments.patch
Patch37601:	0006-zstd-compress-fix-repeated-words-in-comments.patch
Patch37602:	0007-zstd-decompress-fix-repeated-words-in-comments.patch
Patch37603:	0008-lib-zstd-Fix-Wstringop-overflow-warning.patch
Patch37604:	0009-zstd-Update-to-upstream-v1.5.4.patch
Patch37605:	0010-Revert-zstd-Update-to-upstream-v1.5.4.patch
Patch37606:	0011-zstd-Update-to-upstream-v1.5.4.patch
#
# openmandriva
Patch39000:	revert-721412ed3d819e767cac2b06646bf03aa158aaec.patch
Patch39001:	android-enable-building-ashmem-and-binder-as-modules.patch
Patch39002:	export-symbols-needed-by-android-drivers.patch
Patch39003:	acpi-use-kern_warning_even_when_error.patch
Patch39004:	fix-acpi_dbg_level.patch
Patch39005:	linux-5.5-corsair-strafe-quirks.patch
Patch39006:	Unknow-SSD-HFM128GDHTNG-8310B-QUIRK_NO_APST.patch
Patch39007:	0001-Add-support-for-Acer-Predator-macro-keys.patch
Patch39008:	1005-panfrost-Silence-Panfrost-gem-shrinker-loggin.patch
#
# opensuse
Patch40000:	char-pcmcia-cm4000_cs-Fix-use-after-free-in-cm4000_f.patch
Patch40001:	0001-regulator-mt6360-Add-OF-match-table.patch
Patch40002:	0002-regulator-mt6358-Add-OF-match-table.patch
Patch40003:	0003-regulator-mt6323-Add-OF-match-table.patch
#
# ubuntu lunar
Patch41000:	0003-UBUNTU-SAUCE-no-up-cdrom-default-to-not-locking-the-.patch
Patch41001:	0005-UBUNTU-SAUCE-no-up-x86-reboot-Make-Dell-Latitude-E65.patch
Patch41002:	0006-UBUNTU-SAUCE-no-up-x86-reboot-Make-Dell-Optiplex-790.patch
Patch41003:	0007-UBUNTU-SAUCE-no-up-x86-reboot-Make-Dell-Optiplex-990.patch
Patch41004:	0008-UBUNTU-SAUCE-no-up-x86-reboot-Make-Dell-Latitude-E62.patch
Patch41005:	0010-UBUNTU-SAUCE-no-up-Allow-filtering-of-cpufreq-driver.patch
Patch41006:	0012-UBUNTU-SAUCE-no-up-rds_ib_send-prevent-local-pings-t.patch
Patch41007:	0014-UBUNTU-SAUCE-no-up-Input-Cypress-PS-2-Trackpad-simul.patch
Patch41008:	0015-UBUNTU-SAUCE-no-up-PCI-fix-system-hang-issue-of-Marv.patch
Patch41009:	0016-UBUNTU-SAUCE-no-up-x86-reboot-Make-Dell-Optiplex-390.patch
Patch41010:	0017-UBUNTU-SAUCE-no-up-intel_ips-blacklist-ASUSTek-G60JX.patch
Patch41011:	0018-UBUNTU-SAUCE-no-up-mei_me-Add-module-parameter-to-di.patch
Patch41012:	0022-UBUNTU-SAUCE-no-up-arm64-gicv3-its-Increase-FORCE_MA.patch
Patch41013:	0023-UBUNTU-SAUCE-no-up-ACPI-Disable-Windows-8-compatibil.patch
Patch41014:	0024-UBUNTU-SAUCE-no-up-Added-quirk-to-recognize-GE0301-3.patch
Patch41015:	0025-UBUNTU-SAUCE-isapnp_init-make-isa-PNP-scans-occur-as.patch
Patch41016:	0026-UBUNTU-SAUCE-kthread-Do-not-leave-kthread_create-imm.patch
Patch41017:	0027-UBUNTU-SAUCE-kvm-BIOS-disabled-kvm-support-should-be.patch
Patch41018:	0054-UBUNTU-SAUCE-cdc-acm-Exclude-Exar-USB-serial-ports.patch
Source41019:	0057-UBUNTU-SAUCE-overlayfs-Skip-permission-checking-for-.patch
Patch41020:	0058-UBUNTU-SAUCE-ima-Downgrade-error-to-warning.patch
Patch41021:	0084-UBUNTU-SAUCE-mwifiex-Switch-WiFi-LED-state-according.patch
Patch41022:	0085-UBUNTU-SAUCE-Bluetooth-Support-for-LED-on-Edge-Gatew.patch
Patch41023:	0086-UBUNTU-SAUCE-x86-PCI-Export-find_cap-to-be-used-in-e.patch
Source41024:	0088-UBUNTU-SAUCE-x86-quirks-Scan-all-busses-for-early-PC.patch
Patch41025:	0157-UBUNTU-SAUCE-Revert-radix-tree-Use-local_lock-for-pr.patch
Patch41026:	0190-UBUNTU-SAUCE-dccp-avoid-double-free-of-ccid-on-child.patch
Patch41027:	0191-UBUNTU-SAUCE-doc-remove-python3-venv-dependency.patch
Patch41028:	0198-Microsemi-PCIe-expansion-board-DT-entry.patch
Patch41029:	0201-UBUNTU-SAUCE-Input-i8042-add-dmi-quirk.patch
Patch41030:	0224-UBUNTU-ODM-hwmon-add-driver-for-AAEON-devices.patch
Patch41031:	0225-UBUNTU-ODM-leds-add-driver-for-AAEON-devices.patch
Patch41032:	0226-UBUNTU-ODM-gpio-add-driver-for-AAEON-devices.patch
Patch41033:	0227-UBUNTU-ODM-mfd-Add-support-for-IO-functions-of-AAEON.patch
Patch41034:	0230-UBUNTU-SAUCE-arm-Fix-instruction-set-selection-for-G.patch
Patch41035:	0231-UBUNTU-ODM-mfd-Check-AAEON-BFPI-version-before-addin.patch
Patch41036:	0232-Revert-r8169-avoid-link-up-interrupt-issue-on-RTL810.patch
Patch41037:	0234-UBUNTU-SAUCE-ACPICA-avoid-accessing-operands-out-of-.patch
Patch41038:	0235-PCI-ASPM-Introduce-a-new-helper-to-report-ASPM-capab.patch
Patch41039:	0239-UBUNTU-SAUCE-RDMA-core-Introduce-peer-memory-interfa.patch
Patch41040:	0240-UBUNTU-SAUCE-RDMA-core-Updated-ib_peer_memory.patch
Patch41041:	0241-UBUNTU-SAUCE-RDMA-core-ib_peer_memory-fix-build-erro.patch
Patch41042:	0259-ASoC-Intel-sof_sdw-Add-support-for-SKU-0B13-product.patch
Patch41043:	0260-ASoC-Intel-sof_sdw-Add-support-for-SKU-0B29-product.patch
Patch41044:	0261-ASoC-Intel-sof_sdw-Add-support-for-SKU-0B12-product.patch
Patch41045:	0323-UBUNTU-SAUCE-iommu-intel-ipu-use-IOMMU-passthrough-m.patch
Patch41046:	0421-UBUNTU-SAUCE-net-phy-marvell-Skip-setting-LED-on-Del.patch
Patch41047:	0460-UBUNTU-SAUCE-PCI-ASPM-Enable-ASPM-for-links-under-VM.patch
Patch41048:	0461-UBUNTU-SAUCE-PCI-ASPM-Enable-LTR-for-endpoints-behin.patch
Patch41049:	0462-UBUNTU-SAUCE-vmd-fixup-bridge-ASPM-by-driver-name-in.patch
Patch41050:	0484-UBUNTU-SAUCE-Revert-rfkill-make-new-event-layout-opt.patch
Source41051:	0502-UBUNTU-SAUCE-overlayfs-fix-incorrect-mnt_id-of-files.patch
Patch41052:	0522-UBUNTU-SAUCE-igc-wait-for-the-MAC-copy-when-enabled-.patch
Patch41053:	0539-UBUNTU-SAUCE-x86-tdx-Add-TDX-Guest-attestation-inter.patch
Patch41054:	0540-UBUNTU-SAUCE-selftests-tdx-Test-GetReport-TDX-attest.patch
Patch41055:	0710-ASoC-Intel-sof_sdw-Add-support-for-SKU-0C10-product.patch
Patch41056:	0711-ASoC-Intel-soc-acpi-add-SKU-0C10-SoundWire-configura.patch
Patch41057:	0712-ASoC-Intel-sof_sdw-Add-support-for-SKU-0C40-product.patch
Patch41058:	0713-ASoC-Intel-soc-acpi-add-SKU-0C40-SoundWire-configura.patch
Patch41059:	0714-ASoC-Intel-sof_sdw-Add-support-for-SKU-0C4F-product.patch
Patch41060:	0717-ASoC-Intel-sof_sdw-Add-support-for-SKU-0C11-product.patch
Patch41061:	0718-ASoC-Intel-soc-acpi-add-SKU-0C11-SoundWire-configura.patch
Patch41062:	0719-UBUNTU-SAUCE-ASoC-Intel-soc-acpi-update-codec-addr-o.patch
Source41063:	0730-UBUNTU-SAUCE-Bluetooth-btusb-Add-support-for-Foxconn.patch
Patch41064:	0731-Revert-mm-kfence-apply-kmemleak_ignore_phys-on-early.patch
Patch41065:	0732-Revert-PCI-portdrv-Don-t-disable-AER-reporting-in-ge.patch
Patch41066:	0735-UBUNTU-SAUCE-platform-x86-int3472-support-independen.patch
Patch41067:	0736-Revert-clk-ti-Stop-using-legacy-clkctrl-names-for-om.patch
Patch41068:	0737-Revert-fs-check-FMODE_LSEEK-to-control-internal-pipe.patch
Patch41069:	0740-net-wwan-t7xx-use-union-to-group-port-type-specific-.patch
Patch41070:	0741-net-wwan-t7xx-Add-port-for-modem-logging.patch
Patch41071:	0742-UBUNTU-SAUCE-iommu-intel-ipu-use-IOMMU-passthrough-m.patch
Patch41072:	0744-UBUNTU-SAUCE-input-i8042-fix-section-mismatch-warnin.patch
Patch41073:	0749-drm-i915-rpl-p-Add-stepping-info.patch
Patch41074:	1001-drm-amdgpu-Revert-drm-amdgpu-getting-fan-speed-pwm-f.patch
Patch41075:	1231-wifi-mac80211-fix-memory-leak-in-ieee80211_if_add.patch
#
# local patches
Patch43000:	0001-disable-smt-at-boot.patch
#END
####################################################################

# Defines for the things that are needed for all the kernels
#
%define common_desc_kernel The kernel package contains the Linux kernel (vmlinuz), the core of your \
Mageia operating system. The kernel handles the basic functions \
of the operating system: memory allocation, process allocation, device \
input and output, etc.

%define common_desc_kernel_smp This kernel relies on in-kernel smp alternatives to switch between up & smp \
mode depending on detected hardware. To force the kernel to boot in single \
processor mode, use the "nosmp" boot parameter.

### Global Requires/Provides
%define requires1	bootloader-utils >= 1.16-1
%define requires2	dracut >= 046-2
%define requires3	kmod >= 12-2
%define requires4	sysfsutils >= 2.1.0-16
%define requires5	kernel-firmware >= 20190603-1
# ldetect-lst with SI/CIK swich from radeon to amdgpu
%define requires6	ldetect-lst >= 0.6.25-1

%define kprovides1	%{kname} = %{kverrel}
%define kprovides2	kernel = %{tar_ver}
%define kprovides3	alsa = 1.0.26
%define kprovides_server drbd-api = 88

# conflict dkms packages that dont support kernel-5.19
%define kconflicts1	dkms-broadcom-wl < 6.30.223.271-64
%define kconflicts2	dkms-nvidia-current < 470.141.03-1
%define kconflicts3	dkms-nvidia470 < 470.141.03-1
%define kconflicts4	dkms-nvidia390 < 390.154-1
%define kconflicts5	dkms-virtualbox < 6.1.36-1
%define kconflicts6	dkms-xtables-addons < 3.21-1
# (tmb) conflict older btrfs-progs to get the new in same transaction and in initrd
%define kconflicts8	btrfs-progs < 5.10-1
# (tmb) conflict too old radeon-firmware to get the uvd firmwares in initrd
%define kconflicts9	radeon-firmware < 20201218-1
# (tmb) conflict old firmware to get the firmwares in initrd
%define kconflicts10	kernel-firmware-nonfree < 20201230-1
# (tmb) conflict old microcode to get updated ones in initrd for early loading
%define kconflicts11	microcode < 0.20201118-2
# (tmb) conflict old theme to get mga8 theme in initrd
%define kconflicts12    mageia-gfxboot-theme < 4.5.14.11-2
# (tmb) conflict too old grub2(-efi)
%define kconflicts13	grub2 < 2.02.0-15
%define kconflicts14	grub2-efi < 2.02.0-15
# (tmb) conflict too old efibootmgr
%define kconflicts15	efibootmgr < 16-3
# (tmb) force new theme in initrd
%define kconflicts16	mageia-theme < 8.0-2

Autoreqprov:		no

# require new gcc & binutils
BuildRequires:		gcc >= 10.4.0-2
BuildRequires:		binutils >= 1:2.36.1-1.4
#
BuildRequires:		kmod >= 12-2
BuildRequires:		bc
# for crypto stuff
BuildRequires:		pkgconfig(openssl)
# since 4.16
BuildRequires:		bison
BuildRequires:		diffutils
BuildRequires:		elfutils-devel
BuildRequires:		flex
# for headers_install
BuildRequires:		rsync
# for cpupower
%if %{build_cpupower}
BuildRequires:		pkgconfig(libpci)
%endif
# for perf
%if %{build_perf}
BuildRequires:		audit-devel
BuildRequires:		binutils-devel
BuildRequires:		gtk2-devel
BuildRequires:		libunwind-devel
BuildRequires:		newt-devel
BuildRequires:		python3-devel
BuildRequires:		zlib-devel
BuildRequires:		asciidoc
BuildRequires:		xmlto-notex
BuildRequires:		perl-devel
%if 0%{?mageia} >= 8
BuildRequires:		systemtap-sdt-devel
BuildRequires:		babeltrace-devel
%else
BuildRequires:		libbabeltrace-devel
%endif
%ifarch %{ix86} x86_64
BuildRequires:		numa-devel
%endif
%endif
%if %{build_bpftool}
BuildRequires:		python3-docutils
BuildRequires:		cap-devel
%endif

%description
%common_desc_kernel
%ifnarch %{arm}
%common_desc_kernel_smp
%endif

# mkflavour() name flavour processor
# name: the flavour name in the package name
# flavour: first parameter of CreateKernel()
%define mkflavour()					\
%package -n %{kname}-%{1}-%{buildrel}			\
Version:	%{fakever}				\
Release:	%{fakerel}				\
Provides:	%kprovides1 %kprovides2 %kprovides3	\
%{expand:%%{?kprovides_%{1}:Provides: %{kprovides_%{1}}}} \
Provides:	%{kname}-%{1}				\
Requires(pre):	%requires1 %requires2 %requires3 %requires4 \
Requires:	%requires2 %requires5 %requires6	\
Conflicts:	%kconflicts1 %kconflicts2 %kconflicts3	\
Conflicts:	%kconflicts4 %kconflicts5 %kconflicts6	\
Conflicts:	%kconflicts8 %kconflicts9		\
Conflicts:	%kconflicts10 %kconflicts11 %kconflicts12 \
Conflicts:	%kconflicts13 %kconflicts14 %kconflicts15 \
Conflicts:	%kconflicts16				\
%if 0%{?mageia} >= 8					\
Obsoletes:	crda					\
Obsoletes:	crda-devel				\
Obsoletes:	fuse-exfat				\
%endif							\
Provides:	should-restart = system			\
Provides:	installonlypkg(kernel)			\
Recommends:	iw cpupower microcode			\
Recommends:	%{kname}-%{1}-latest			\
%ifarch %{ix86}						\
Conflicts:	arch(x86_64)				\
%endif							\
Summary:	%{expand:%{summary_%(echo %{1} | sed -e "s/-/_/")}} \
Group:		System/Kernel and hardware		\
%description -n %{kname}-%{1}-%{buildrel}		\
%common_desc_kernel %{expand:%{info_%(echo %{1} | sed -e "s/-/_/")}} \
%ifnarch %{arm}						\
%common_desc_kernel_smp					\
%endif							\
							\
%if %build_devel					\
%package -n	%{kname}-%{1}-devel-%{buildrel}		\
Version:	%{fakever}				\
Release:	%{fakerel}				\
Requires:	glibc-devel ncurses-devel make gcc perl	\
Requires:	gcc >= 5.5.0-1				\
%ifarch x86_64						\
Requires:	pkgconfig(libelf)			\
%endif							\
Summary:	The kernel-devel files for %{kname}-%{1}-%{buildrel} \
Group:		Development/Kernel			\
Provides:	%{kname}-devel = %{kverrel}		\
Provides:	%{kname}-%{1}-devel			\
Recommends:	%{kname}-%{1}-devel-latest		\
%ifarch %{ix86}						\
Conflicts:	arch(x86_64)				\
%endif							\
%description -n %{kname}-%{1}-devel-%{buildrel}		\
This package contains the kernel files (headers and build tools) \
that should be enough to build additional drivers for	\
use with %{kname}-%{1}-%{buildrel}.			\
							\
If you want to build your own kernel, you need to install the full \
%{kname}-source-%{buildrel} rpm.			\
							\
%endif							\
							\
%if %build_debug					\
%package -n	%{kname}-%{1}-%{buildrel}-debuginfo	\
Version:	%{fakever}				\
Release:	%{fakerel}				\
Summary:	Files with debuginfo for %{kname}-%{1}-%{buildrel} \
Group:		Development/Debug			\
Provides:	kernel-debug = %{kverrel}		\
%ifarch %{ix86}						\
Conflicts:	arch(x86_64)				\
%endif							\
%description -n %{kname}-%{1}-%{buildrel}-debuginfo	\
This package contains the files with debuginfo to aid in debug tasks	\
when using %{kname}-%{1}-%{buildrel}.			\
							\
If you need to look at debug information or use some application that	\
needs debugging info from the kernel, this package may help.	\
							\
%endif							\
							\
%package -n %{kname}-%{1}-latest			\
Version:	%{kversion}				\
Release:	%{rpmrel}				\
Summary:	Virtual rpm for latest %{kname}-%{1}	\
Group:		System/Kernel and hardware		\
Requires:	%{kname}-%{1}-%{buildrel}		\
%ifarch %{ix86}						\
Conflicts:	arch(x86_64)				\
%endif							\
Obsoletes:	vboxadditions-kernel-%{1}-latest	\
Obsoletes:	kernel-tmb-%{1}-latest			\
%description -n %{kname}-%{1}-latest			\
This package is a virtual rpm that aims to make sure you always have the \
latest %{kname}-%{1} installed...			\
							\
%if %build_devel					\
%package -n %{kname}-%{1}-devel-latest			\
Version:	%{kversion}				\
Release:	%{rpmrel}				\
Summary:	Virtual rpm for latest %{kname}-%{1}-devel \
Group:		Development/Kernel			\
Requires:	%{kname}-%{1}-devel-%{buildrel}		\
%ifarch %{ix86}						\
Conflicts:	arch(x86_64)				\
%endif							\
Provides:	%{kname}-devel-latest			\
Obsoletes:	kernel-tmb-%{1}-devel-latest		\
%description -n %{kname}-%{1}-devel-latest		\
This package is a virtual rpm that aims to make sure you always have the \
latest %{kname}-%{1}-devel installed...			\
							\
%endif							\
							\
%posttrans -n %{kname}-%{1}-%{buildrel} -f kernel_files.%{1}-posttrans \
%postun -n %{kname}-%{1}-%{buildrel} -f kernel_files.%{1}-postun \
							\
%if %build_devel					\
%post -n %{kname}-%{1}-devel-%{buildrel} -f kernel_devel_files.%{1}-post \
%preun -n %{kname}-%{1}-devel-%{buildrel} -f kernel_devel_files.%{1}-preun \
%postun -n %{kname}-%{1}-devel-%{buildrel} -f kernel_devel_files.%{1}-postun \
%endif							\
							\
%files -n %{kname}-%{1}-%{buildrel} -f kernel_files.%{1} \
%files -n %{kname}-%{1}-latest				\
							\
%if %build_devel					\
%files -n %{kname}-%{1}-devel-%{buildrel} -f kernel_devel_files.%{1} \
%files -n %{kname}-%{1}-devel-latest			\
%endif							\
							\
%if %build_debug					\
%files -n %{kname}-%{1}-%{buildrel}-debuginfo -f kernel_debug_files.%{1} \
%endif

%ifarch %{ix86}
#
# kernel-desktop586: i586, smp-alternatives, 4GB
#
%if %build_desktop586
%define summary_desktop586 Linux kernel for desktop use with i586 and less than 4GB RAM
%define info_desktop586 This kernel is compiled for desktop use, single or \
multiple i586 processor(s)/core(s) and less than 4GB RAM (usually 3-3.5GB \
detected, if you need/want to use all 4GB or more, install kernel-server), \
using HZ_1000, voluntary preempt, CFS cpu scheduler and cfq i/o scheduler.
%mkflavour desktop586
%endif
%endif

#
# kernel-desktop: i686, smp-alternatives, 64 GB / x86_64 / arm / aarch64
#
%if %build_desktop
%ifarch %{ix86}
%define summary_desktop Linux Kernel for desktop use with i686 and up to 64GB RAM
%define info_desktop This kernel is compiled for desktop use, single or \
multiple i686 processor(s)/core(s) and up to 64GB RAM, using HZ_1000, \
voluntary preempt, CFS cpu scheduler and cfq i/o scheduler.
%else
%define summary_desktop Linux Kernel for desktop use with %{_arch}
%define info_desktop This kernel is compiled for desktop use, single or \
multiple %{_arch} processor(s)/core(s), using HZ_1000, voluntary preempt, \
CFS cpu scheduler and cfq i/o scheduler.
%endif
%mkflavour desktop
%endif

#
# kernel-server: i686, smp-alternatives, 64 GB / x86_64 / aarch64
#
%if %build_server
%ifarch %{ix86}
%define summary_server Linux Kernel for server use with i686 & 64GB RAM
%define info_server This kernel is compiled for server use, single or \
multiple i686 processor(s)/core(s) and up to 64GB RAM using PAE, using \
no preempt, HZ_100, CFS cpu scheduler and cfq i/o scheduler.
%else
%define summary_server Linux Kernel for server use with %{_arch}
%define info_server This kernel is compiled for server use, single or \
multiple %{_arch} processor(s)/core(s), using no preempt, HZ_100, \
CFS cpu scheduler and cfq i/o scheduler.
%endif
%mkflavour server
%endif

#
# kernel-source
#
%if %build_source
%package -n %{kname}-source-%{buildrel}
Version:	%{fakever}
Release:	%{fakerel}
Requires:	glibc-devel, ncurses-devel, make, gcc, perl, diffutils
Summary:	The Linux source code for %{kname}-%{buildrel}
Group:		Development/Kernel
Autoreqprov:	no
Provides:	kernel-source = %{kverrel}
Buildarch:	noarch

%description -n %{kname}-source-%{buildrel}
The %{kname}-source package contains the source code files for the Mageia
kernel. Theese source files are only needed if you want to build your
own custom kernel that is better tuned to your particular hardware.

If you only want the files needed to build 3rdparty (nVidia, Ati, dkms-*,...)
drivers against, install the *-devel-* rpm that is matching your kernel.

#
# kernel-source-latest: virtual rpm
#
%package -n %{kname}-source-latest
Version: 	%{kversion}
Release: 	%{rpmrel}
Summary: 	Virtual rpm for latest %{kname}-source
Group:   	Development/Kernel
Requires: 	%{kname}-source-%{buildrel}
Buildarch:	noarch

%description -n %{kname}-source-latest
This package is a virtual rpm that aims to make sure you always have the
latest %{kname}-source installed...
%endif

#
# kernel-doc: documentation for the Linux kernel
#
%if %build_doc
%package -n %{kname}-doc
Version: 	%{kversion}
Release: 	%{rpmrel}
Summary: 	Various documentation bits found in the %{kname} source
Group: 		Documentation
Buildarch:	noarch

%description -n %{kname}-doc
This package contains documentation files from the %{kname} source.
Various bits of information about the Linux kernel and the device drivers
shipped with it are documented in these files. You also might want install
this package if you need a reference to the options that can be passed to
Linux kernel modules at load time.
%endif

#
# kernel userspace-headers
#
%if %{build_uheaders}
%package -n %{kname}-userspace-headers
Version:	%{kversion}
Release:	%{rpmrel}
Summary:	Linux kernel header files for userspace
Group:		System/Kernel and hardware
%rename		linux-userspace-headers
Provides:	kernel-headers = 1:%{version}-%{release}

%description -n %{kname}-userspace-headers
C header files from the Linux kernel. The header files define structures
and constants that are needed for building most standard programs.

This package is not suitable for building kernel modules.
%endif

#
# kernel/tools
#
%if %{build_perf}
%package -n perf
Version:	%{kversion}
Release:	%{rpmrel}
Summary:	perf tool and the supporting documentation
Group:		System/Kernel and hardware

%description -n perf
the perf tool and the supporting documentation.
%endif

%if %{build_cpupower}
%package -n cpupower
Version:	%{kversion}
Release:	%{rpmrel}
Summary:	the cpupower tools
Group:		System/Kernel and hardware
Requires(post):  rpm-helper >= 0.24.8-1
Requires(preun): rpm-helper >= 0.24.8-1
Obsoletes:	cpufreq cpufrequtils

%description -n cpupower
the cpupower tools.

%post -n cpupower
%_post_service cpupower

%preun -n cpupower
%_preun_service cpupower

%package -n cpupower-devel
Version:	%{kversion}
Release:	%{rpmrel}
Summary:	devel files for cpupower
Group:		Development/Kernel
Requires:	cpupower = %{kversion}-%{rpmrel}
Conflicts:	%{_lib}cpufreq-devel

%description -n cpupower-devel
This package contains the development files for cpupower.
%endif

%if %{build_bpftool}
%package -n bpftool
Summary:	Inspection and simple manipulation of eBPF programs and maps
Group:		System/Kernel and hardware

%description -n bpftool
This package contains the bpftool, which allows inspection and simple
manipulation of eBPF programs and maps.
%endif

%if %{build_libbpf}
%package -n %{_lib}bpf%{bpfmajor}
Summary:	The bpf library from kernel source
Group:		System/Libraries

%description -n %{_lib}bpf%{bpfmajor}
This package contains the kernel source bpf library.

%package -n %{_lib}bpf-devel
Summary: 	Developement files for the bpf library from kernel source
Group:		Development/Kernel
Requires:	%{_lib}bpf%{bpfmajor}

%description -n %{_lib}bpf-devel
This package includes libraries and header files needed for development
of applications which use bpf library from kernel source.
%endif

#
# End packages - here begins build stage
#
%prep
%setup -q -n %top_dir_name -c

cd %src_dir

%autopatch -p1

# PATCH END

#
# Setup Begin
#

# install x86 defconfigs
install -m 644 %{SOURCE11} %{SOURCE12} %{SOURCE13} %{SOURCE14} %{SOURCE15} arch/x86/configs/
# install arm64 defconfigs
install -m 644 %{SOURCE16} %{SOURCE17} arch/arm64/configs/
# install arm defconfigs
install -m 644 %{SOURCE18} arch/arm/configs/

# make sure the kernel has the sublevel we know it has...
LC_ALL=C perl -p -i -e "s/^SUBLEVEL.*/SUBLEVEL = %{sublevel}/" Makefile

# get rid of unwanted files
find . -name '*~' -o -name '*.orig' -o -name '*.append' | %kxargs rm -f

# fix missing exec flag on file introduced in 4.14.10-rc1
chmod 755 tools/objtool/sync-check.sh

%build
# Common target directories
%define _kerneldir /usr/src/kernel-%{kversion}-%{buildrpmrel}
%define _bootdir /boot
%define _modulesdir /lib/modules
%define _efidir %{_bootdir}/efi/mageia

# Directories definition needed for building
%define temp_root %{build_dir}/temp-root
%define temp_source %{temp_root}%{_kerneldir}
%define temp_boot %{temp_root}%{_bootdir}
%define temp_modules %{temp_root}%{_modulesdir}

PrepareKernel() {
	name=$1
	extension=$2

	echo "Make config for kernel $extension"

	%smake ARCH=%{target_arch} -s mrproper

	if [ "%{target_arch}" == "i386" -o "%{target_arch}" == "x86_64" ]; then
		conf_dir=arch/x86/configs
	else
		conf_dir=arch/%{target_arch}/configs
	fi
	if [ -z "$name" ]; then
		cp $conf_dir/defconfig-%{target_arch}-desktop .config
	else
		cp $conf_dir/defconfig-%{target_arch}-$name .config
	fi

	# make sure EXTRAVERSION says what we want it to say
	LC_ALL=C perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -$extension/" Makefile

	%smake ARCH=%{target_arch} oldconfig
}

BuildKernel() {
	KernelVer=$1

	echo "Building kernel $KernelVer"

	%kmake ARCH=%{target_arch} -s all

	# Start installing stuff
	install -d %{temp_boot}
	install -m 644 System.map %{temp_boot}/System.map-$KernelVer
	install -m 644 .config %{temp_boot}/config-$KernelVer
	xz -c Module.symvers > %{temp_boot}/symvers-$KernelVer.xz

	%ifarch %{arm}
		IMAGE=zImage
	%else
		%ifarch aarch64
			IMAGE=Image.gz
		%else
			IMAGE=bzImage
		%endif
	%endif
	cp -f arch/%{target_arch}/boot/$IMAGE %{temp_boot}/vmlinuz-$KernelVer

	%ifarch %{arm} aarch64
		install -d %{temp_root}%{_libdir}/linux-$KernelVer/
		find arch/%{target_arch}/boot/dts/ -name *.dtb -execdir install -D -m644 {} %{temp_root}%{_libdir}/linux-$KernelVer/{} \;
	%endif

	# modules
	install -d %{temp_modules}/$KernelVer
	%smake ARCH=%{target_arch} INSTALL_MOD_PATH=%{temp_root} KERNELRELEASE=$KernelVer modules_install
}

SaveDevel() {
	devel_flavour=$1

	DevelRoot=/usr/src/kernel-%{kversion}-$devel_flavour-%{buildrpmrel}
	TempDevelRoot=%{temp_root}$DevelRoot

	mkdir -p $TempDevelRoot
	for i in $(find . -name 'Makefile*'); do cp -R --parents $i $TempDevelRoot;done
	for i in $(find . -name 'Kconfig*' -o -name 'Kbuild*'); do cp -R --parents $i $TempDevelRoot;done
	cp -fR include $TempDevelRoot
	cp -fR scripts $TempDevelRoot
	cp -fR kernel/bounds.c $TempDevelRoot/kernel
	cp -fR tools/include $TempDevelRoot/tools/
	# needed for selinux
	cp -R --parents security/selinux/include/*.h $TempDevelRoot
	%ifarch %{arm}
		cp -fR arch/%{target_arch}/tools $TempDevelRoot/arch/%{target_arch}/
		cp -fR arch/%{target_arch}/kernel/signal.h $TempDevelRoot/arch/%{target_arch}/kernel/
	%endif
	%ifarch aarch64
		cp -fR arch/x86/entry/syscalls/syscall_32.tbl $TempDevelRoot/arch/x86/entry/syscalls/
		cp -fR arch/arm64/kernel/vdso/*.{S,sh} $TempDevelRoot/arch/arm64/kernel/vdso/
		cp -fR arch/arm64/kernel/vdso/vgettimeofday.c $TempDevelRoot/arch/arm64/kernel/vdso/
		cp -fR arch/arm64/tools/{cpucaps,gen-cpucaps.awk,gen-sysreg.awk,sysreg} $TempDevelRoot/arch/arm64/tools/
		# aarch64 build wants x86 syscall tables
		cp -fR arch/x86/entry/syscalls/syscall_{32,64}.tbl $TempDevelRoot/arch/x86/entry/syscalls/
		cp -fR lib/vdso/gettimeofday.c $TempDevelRoot/lib/vdso/
	%endif
	%ifarch %{ix86} x86_64
		cp -fR arch/x86/kernel/asm-offsets.{c,s} $TempDevelRoot/arch/x86/kernel/
		cp -fR arch/x86/kernel/asm-offsets_{32,64}.c $TempDevelRoot/arch/x86/kernel/
		mkdir -p $TempDevelRoot/arch/x86/kvm/vmx
		cp -fR arch/x86/kvm/vmx/*.h $TempDevelRoot/arch/x86/kvm/vmx/
		cp -fR arch/x86/kvm/*.h $TempDevelRoot/arch/x86/kvm/
		cp -fR arch/x86/lib/insn.c $TempDevelRoot/arch/x86/lib/
		cp -fR arch/x86/purgatory/* $TempDevelRoot/arch/x86/purgatory/
		cp -fR arch/x86/entry/syscalls/syscall* $TempDevelRoot/arch/x86/entry/syscalls/
		cp -fR arch/x86/include $TempDevelRoot/arch/x86/
		cp -fR arch/x86/tools $TempDevelRoot/arch/x86/
	%else
		cp -fR arch/%{target_arch}/kernel/asm-offsets.{c,s} $TempDevelRoot/arch/%{target_arch}/kernel/
		for f in $(find arch/%{target_arch} -name include); do cp -fR --parents $f $TempDevelRoot; done
	%endif
	cp -fR .config Module.symvers $TempDevelRoot

	# Needed for truecrypt build (Danny)
	cp -fR drivers/md/dm.h $TempDevelRoot/drivers/md/

	# needed by include/generated/timeconst.h
	cp -fR kernel/time/timeconst.bc $TempDevelRoot/kernel/time/

	# Needed for lirc_gpio (#39004)
	cp -fR drivers/media/pci/bt8xx/bttv{,p}.h $TempDevelRoot/drivers/media/pci/bt8xx/
	cp -fR drivers/media/pci/bt8xx/bt848.h $TempDevelRoot/drivers/media/pci/bt8xx/
	cp -fR drivers/media/common/btcx-risc.h $TempDevelRoot/drivers/media/common/

	# rtl8812au
	mkdir -p $TempDevelRoot/drivers/staging/rtl8812au/hal/phydm/
	cp -f drivers/staging/rtl8812au/hal/phydm/phydm.mk $TempDevelRoot/drivers/staging/rtl8812au/hal/phydm/

	%ifarch x86_64
	# orc unwinder needs theese
		cp -fR tools/build/Build{,.include} $TempDevelRoot/tools/build
		cp -fR tools/build/fixdep.c $TempDevelRoot/tools/build
		cp -fR tools/lib/{rbtree.c,ctype.c,str_error_r.c,string.c} $TempDevelRoot/tools/lib
		cp -fR tools/lib/subcmd/* $TempDevelRoot/tools/lib/subcmd
		cp -fR tools/objtool/* $TempDevelRoot/tools/objtool
		cp -fR tools/scripts/utilities.mak $TempDevelRoot/tools/scripts
		mkdir -p $TempDevelRoot/tools/arch/x86/tools
		cp -fR tools/arch/x86/tools/gen-insn-attr-x86.awk $TempDevelRoot/tools/arch/x86/tools/
		mkdir -p $TempDevelRoot/tools/arch/x86/lib
		cp -fR tools/arch/x86/lib/{inat.c,insn.c,x86-opcode-map.txt} $TempDevelRoot/tools/arch/x86/lib/
		mkdir -p $TempDevelRoot/tools/arch/x86/include/asm
		cp -fR tools/arch/x86/include/asm/{asm.h,emulate_prefix.h,inat.h,inat_types.h,insn.h,nops.h,orc_types.h} $TempDevelRoot/tools/arch/x86/include/asm/
	%endif

	for i in alpha arc avr32 blackfin c6x cris csky frv h8300 hexagon ia64 loongarch m32r m68k m68knommu metag microblaze \
		 mips mn10300 nds32 nios2 openrisc parisc powerpc riscv s390 score sh sparc tile unicore32 xtensa; do
		rm -rf $TempDevelRoot/arch/$i
		rm -rf $TempDevelRoot/scripts/dtc/include-prefixes/$i
		rm -rf $TempDevelRoot/tools/arch/$i
	done

	%ifnarch %{arm} aarch64
		rm -rf $TempDevelRoot/arch/arm*
		rm -rf $TempDevelRoot/include/kvm/arm*
		rm -rf $TempDevelRoot/include/soc
		rm -rf $TempDevelRoot/scripts/dtc/include-prefixes/arm*
		rm -rf $TempDevelRoot/tools/arch/arm*
	%endif
	%ifnarch %{ix86} x86_64
		rm -rf $TempDevelRoot/arch/x86
		rm -rf $TempDevelRoot/tools/arch/x86
		# arch/x86/ras/Kconfig is included by drivers/ras/Kconfig
		# and kconfig's source command seems to be evaluated even under a false conditional
		mkdir -p $TempDevelRoot/arch/x86/ras
		cp -fR arch/x86/ras/Kconfig $TempDevelRoot/arch/x86/ras
	%endif

	# (6.1 breakage) keep crypto Kconfig deps happy
	cp --parents arch/arm/crypto/Kconfig $TempDevelRoot
	cp --parents arch/arm64/crypto/Kconfig $TempDevelRoot
	cp --parents arch/mips/crypto/Kconfig $TempDevelRoot
	cp --parents arch/powerpc/crypto/Kconfig $TempDevelRoot
	cp --parents arch/s390/crypto/Kconfig $TempDevelRoot
	cp --parents arch/sparc/crypto/Kconfig $TempDevelRoot
	cp --parents arch/x86/crypto/Kconfig $TempDevelRoot

	# Clean the scripts tree, and make sure everything is ok (sanity check)
	# running prepare+scripts (tree was already "prepared" in build)
	pushd $TempDevelRoot >/dev/null
		%smake ARCH=%{target_arch} -s prepare scripts
		%smake ARCH=%{target_arch} -s clean
	popd >/dev/null
	rm -f $TempDevelRoot/.config.old

	# fix permissions
	chmod -R a+rX $TempDevelRoot

	# disable mrproper in -devel rpms
	patch -p1 --fuzz=0 -d $TempDevelRoot -i %{SOURCE2}

	kernel_devel_files=../kernel_devel_files.$devel_flavour


### Create the kernel_devel_files.*
cat > $kernel_devel_files <<EOF
%dir $DevelRoot
%dir $DevelRoot/arch
%dir $DevelRoot/include
$DevelRoot/Documentation
$DevelRoot/arch/arm
$DevelRoot/arch/arm64
$DevelRoot/arch/mips
$DevelRoot/arch/powerpc
$DevelRoot/arch/s390
$DevelRoot/arch/sparc
$DevelRoot/arch/um
$DevelRoot/arch/x86
$DevelRoot/block
$DevelRoot/certs
$DevelRoot/crypto
$DevelRoot/drivers
$DevelRoot/fs
$DevelRoot/include/acpi
$DevelRoot/include/asm-generic
$DevelRoot/include/clocksource
$DevelRoot/include/config
$DevelRoot/include/crypto
$DevelRoot/include/drm
$DevelRoot/include/dt-bindings
$DevelRoot/include/generated
$DevelRoot/include/keys
$DevelRoot/include/kunit
$DevelRoot/include/kvm
$DevelRoot/include/linux
$DevelRoot/include/math-emu
$DevelRoot/include/media
$DevelRoot/include/memory
$DevelRoot/include/misc
$DevelRoot/include/net
$DevelRoot/include/pcmcia
$DevelRoot/include/ras
$DevelRoot/include/rdma
$DevelRoot/include/rv
$DevelRoot/include/scsi
%ifarch %{arm} aarch64
$DevelRoot/include/soc
%endif
$DevelRoot/include/sound
$DevelRoot/include/target
$DevelRoot/include/trace
$DevelRoot/include/uapi
$DevelRoot/include/ufs
$DevelRoot/include/vdso/*.h
$DevelRoot/include/video
$DevelRoot/include/xen
$DevelRoot/init
$DevelRoot/io_uring
$DevelRoot/ipc
$DevelRoot/kernel
$DevelRoot/lib
$DevelRoot/mm
$DevelRoot/net
$DevelRoot/rust
$DevelRoot/samples
$DevelRoot/scripts
$DevelRoot/security
$DevelRoot/sound
$DevelRoot/tools
$DevelRoot/usr
$DevelRoot/virt
$DevelRoot/.config
$DevelRoot/Kbuild
$DevelRoot/Kconfig
$DevelRoot/Makefile
$DevelRoot/Module.symvers
$DevelRoot/arch/Kconfig
EOF


### Create -devel Post script on the fly
cat > $kernel_devel_files-post <<EOF
if [ -d /lib/modules/%{kversion}-$devel_flavour-%{buildrpmrel} ]; then
	rm -f /lib/modules/%{kversion}-$devel_flavour-%{buildrpmrel}/{build,source}
	ln -sf $DevelRoot /lib/modules/%{kversion}-$devel_flavour-%{buildrpmrel}/build
	ln -sf $DevelRoot /lib/modules/%{kversion}-$devel_flavour-%{buildrpmrel}/source
fi
EOF


### Create -devel Preun script on the fly
cat > $kernel_devel_files-preun <<EOF
if [ -L /lib/modules/%{kversion}-$devel_flavour-%{buildrpmrel}/build ]; then
	rm -f /lib/modules/%{kversion}-$devel_flavour-%{buildrpmrel}/build
fi
if [ -L /lib/modules/%{kversion}-$devel_flavour-%{buildrpmrel}/source ]; then
	rm -f /lib/modules/%{kversion}-$devel_flavour-%{buildrpmrel}/source
fi
exit 0
EOF

### Create -devel Postun script on the fly
cat > $kernel_devel_files-postun <<EOF
rm -rf /usr/src/kernel-%{kversion}-$devel_flavour-%{buildrpmrel} >/dev/null
EOF
}

SaveDebug() {
	debug_flavour=$1

	install -m 644 vmlinux \
	      %{temp_boot}/vmlinux-%{kversion}-$debug_flavour-%{buildrpmrel}
	kernel_debug_files=../kernel_debug_files.$debug_flavour
	echo "%{_bootdir}/vmlinux-%{kversion}-$debug_flavour-%{buildrpmrel}" \
		>> $kernel_debug_files

	find %{temp_modules}/%{kversion}-$debug_flavour-%{buildrpmrel}/kernel \
		-name "*.ko" | \
		%kxargs -I '{}' objcopy --only-keep-debug '{}' '{}'.debug
	find %{temp_modules}/%{kversion}-$debug_flavour-%{buildrpmrel}/kernel \
		-name "*.ko" | %kxargs -I '{}' \
		sh -c 'cd `dirname {}`; \
		       objcopy --add-gnu-debuglink=`basename {}`.debug \
		       --strip-debug `basename {}`'

	pushd %{temp_modules}
	find %{kversion}-$debug_flavour-%{buildrpmrel}/kernel \
		-name "*.ko.debug" > debug_module_list
	popd
	cat %{temp_modules}/debug_module_list | \
		sed 's|\(.*\)|%{_modulesdir}/\1|' >> $kernel_debug_files
	cat %{temp_modules}/debug_module_list | \
		sed 's|\(.*\)|%exclude %{_modulesdir}/\1|' \
		>> ../kernel_exclude_debug_files.$debug_flavour
	rm -f %{temp_modules}/debug_module_list
}

CreateFiles() {
	kernel_flavour=$1

	kernel_files=../kernel_files.$kernel_flavour

ker="vmlinuz"
### Create the kernel_files.*
cat > $kernel_files <<EOF
%{_bootdir}/System.map-%{kversion}-$kernel_flavour-%{buildrpmrel}
%{_bootdir}/symvers-%{kversion}-$kernel_flavour-%{buildrpmrel}.xz
%{_bootdir}/config-%{kversion}-$kernel_flavour-%{buildrpmrel}
%{_bootdir}/$ker-%{kversion}-$kernel_flavour-%{buildrpmrel}
%dir %{_modulesdir}/%{kversion}-$kernel_flavour-%{buildrpmrel}/
%{_modulesdir}/%{kversion}-$kernel_flavour-%{buildrpmrel}/kernel
%{_modulesdir}/%{kversion}-$kernel_flavour-%{buildrpmrel}/modules.*
%doc README.kernel-sources
%ifarch %arm aarch64
%dir %{_libdir}/linux-%{kversion}-$kernel_flavour-%{buildrpmrel}
%{_libdir}/linux-%{kversion}-$kernel_flavour-%{buildrpmrel}/*.dtb
%endif
EOF

%if %build_debug
    cat ../kernel_exclude_debug_files.$kernel_flavour >> $kernel_files
%endif

### Create kernel Posttrans script
cat > $kernel_files-posttrans <<EOF
%if %build_devel
# create kernel-devel symlinks if matching -devel- rpm is installed
if [ -d /usr/src/kernel-%{kversion}-$kernel_flavour-%{buildrpmrel} ]; then
	ln -sf /usr/src/kernel-%{kversion}-$kernel_flavour-%{buildrpmrel} /lib/modules/%{kversion}-$kernel_flavour-%{buildrpmrel}/build
	ln -sf /usr/src/kernel-%{kversion}-$kernel_flavour-%{buildrpmrel} /lib/modules/%{kversion}-$kernel_flavour-%{buildrpmrel}/source
fi
%endif
if [ -z "$DURING_INSTALL" ] ; then
    if [ -x /usr/sbin/dkms_autoinstaller -a -d /usr/src/kernel-%{kversion}-$kernel_flavour-%{buildrpmrel} ]; then
	/usr/sbin/dkms_autoinstaller start %{kversion}-$kernel_flavour-%{buildrpmrel}
    fi
fi
/sbin/installkernel %{kversion}-$kernel_flavour-%{buildrpmrel}
pushd /boot > /dev/null
if [ -e initrd-%{kversion}-$kernel_flavour-%{buildrpmrel}.img ]; then
	ln -sf vmlinuz-%{kversion}-$kernel_flavour-%{buildrpmrel} vmlinuz-$kernel_flavour
	ln -sf vmlinuz-%{kversion}-$kernel_flavour-%{buildrpmrel} vmlinuz
	ln -sf initrd-%{kversion}-$kernel_flavour-%{buildrpmrel}.img initrd-$kernel_flavour.img
	ln -sf initrd-%{kversion}-$kernel_flavour-%{buildrpmrel}.img initrd.img
fi
popd > /dev/null
EOF

### Create kernel Postun script on the fly
cat > $kernel_files-postun <<EOF
pushd /boot > /dev/null
if [ -f "vmlinuz-%{kversion}-$kernel_flavour-%{buildrpmrel}" ]; then
	echo "The kernel is still installed in postun, probably a reinstall, skipping cleanup." >&2
	exit
fi
if [ -L vmlinuz-$kernel_flavour ]; then
	if [ "$(readlink vmlinuz-$kernel_flavour)" = "vmlinuz-%{kversion}-$kernel_flavour-%{buildrpmrel}" ]; then
		rm -f vmlinuz-$kernel_flavour
	fi
fi
if [ -L initrd-$kernel_flavour.img ]; then
	if [ "$(readlink initrd-$kernel_flavour.img)" = "initrd-%{kversion}-$kernel_flavour-%{buildrpmrel}.img" ]; then
		rm -f initrd-$kernel_flavour.img
	fi
fi
popd > /dev/null
rm -rf /lib/modules/%{kversion}-$kernel_flavour-%{buildrpmrel} >/dev/null
/sbin/kernel_remove_initrd %{kversion}-$kernel_flavour-%{buildrpmrel}
/sbin/installkernel -R %{kversion}-$kernel_flavour-%{buildrpmrel}
if [ -d /var/lib/dkms ]; then
    rm -f /var/lib/dkms/*/kernel-%{kversion}-$devel_flavour-%{buildrpmrel}-%{_target_cpu} >/dev/null
    rm -rf /var/lib/dkms/*/*/%{kversion}-$devel_flavour-%{buildrpmrel} >/dev/null
    rm -f /var/lib/dkms-binary/*/kernel-%{kversion}-$devel_flavour-%{buildrpmrel}-%{_target_cpu} >/dev/null
    rm -rf /var/lib/dkms-binary/*/*/%{kversion}-$devel_flavour-%{buildrpmrel} >/dev/null
fi
EOF
}


CreateKernel() {
	flavour=$1

	PrepareKernel $flavour $flavour-%{buildrpmrel}

	BuildKernel %{kversion}-$flavour-%{buildrpmrel}
	%if %build_devel
		SaveDevel $flavour
	%endif
	%if %build_debug
		SaveDebug $flavour
	%endif
	CreateFiles $flavour
}


###
# DO it...
###


# Create a simulacro of buildroot
rm -rf %{temp_root}
install -d %{temp_root}


# make sure we are in the directory
cd %src_dir

%ifarch %{ix86}
%if %build_desktop586
CreateKernel desktop586
%endif
%endif

%if %build_desktop
CreateKernel desktop
%endif

%if %build_server
CreateKernel server
%endif

# set extraversion to match srpm to get nice version reported by the tools
LC_ALL=C perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -%{rpmrel}/" Makefile

# build perf
%if %{build_perf}
# perf
%smake -s -C tools/perf NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 WERROR=0 NO_LIBUNWIND=1 \
	HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_STRLCPY=1 NO_BIONIC=1 NO_JVMTI=1 prefix=%{_prefix} lib=%{_lib} all
%smake -C tools/perf -s prefix=%{_prefix} man
%endif

%if %{build_cpupower}
# cpupower
# make sure version-gen.sh is executable.
chmod +x tools/power/cpupower/utils/version-gen.sh
%make_build -C tools/power/cpupower CPUFREQ_BENCH=false
%endif

# build bpftool
%if %{build_bpftool}
pushd tools/bpf/bpftool
make
popd
%endif

# build libbpf
%if %{build_libbpf}
pushd tools/lib/bpf
make V=1
popd
%endif

# We don't make to repeat the depend code at the install phase
%if %build_source
PrepareKernel "" %{buildrpmrel}custom
%smake ARCH=%{target_arch} -s mrproper
%endif


###
### install
###
%install
install -m 644 %{SOURCE4}  .

cd %src_dir

# Directories definition needed for installing
%define target_source %{buildroot}%{_kerneldir}
%define target_boot %{buildroot}%{_bootdir}
%define target_modules %{buildroot}%{_modulesdir}
%define target_headers %{buildroot}%{_prefix}

# We want to be able to test several times the install part
rm -rf %{buildroot}
cp -a %{temp_root} %{buildroot}

# Create directories infastructure
%if %build_source
install -d %{target_source}

tar cf - . | tar xf - -C %{target_source}
chmod -R a+rX %{target_source}

# we remove all the source files that we don't ship
# first architecture files
for i in alpha arc avr32 blackfin c6x cris csky frv h8300 hexagon ia64 loongarch m32r m68k m68knommu metag microblaze \
	 mips nds32 nios2 openrisc parisc powerpc riscv s390 score sh sh64 sparc tile unicore32 v850 xtensa mn10300; do
	rm -rf %{target_source}/arch/$i
	rm -rf %{target_source}/scripts/dtc/include-prefixes/$i
	rm -rf %{target_source}/tools/arch/$i
	rm -rf %{target_source}/tools/testing/selftests/$i
done
%ifnarch %{arm} aarch64
	rm -rf %{target_source}/include/kvm/arm*
	rm -rf %{target_source}/scripts/dtc/include-prefixes/arm*
	rm -rf %{target_source}/tools/arch/arm*
%endif

# other misc files
rm -f %{target_source}/{.clang-format,.cocciconfig,.config.cmd,.config.old,.get_maintainer.ignore,.gitattributes,.gitignore,.tmp_gas_check,.mailmap,.missing-syscalls.d,arch/.gitignore,rust/.gitignore}
rm -rf %{target_source}/.tmp_depmod/

# more cleaning
pushd %{target_source}
# lots of gitignore files
find -iname ".gitignore" -delete
# clean tools tree
%smake -C tools clean
%smake -C tools/build clean
%smake -C tools/build/feature clean
# dont ship generated vdso.so*
%ifarch aarch64
rm -f arch/arm64/kernel/vdso/vdso.so*
%endif
popd

# nuke last as it gets re-created
rm -f %{target_source}/.cache.mk

#endif %build_source
%endif

# compressing modules
%if %{build_modxz}
find %{target_modules} -name "*.ko" | %kxargs xz -6
%else
find %{target_modules} -name "*.ko" | %kxargs gzip -9
%endif

# We used to have a copy of PrepareKernel here
# Now, we make sure that the thing in the linux dir is what we want it to be
for i in %{target_modules}/*; do
	rm -f $i/build $i/source
done

# sniff, if we compressed all the modules, we change the stamp :(
# we really need the depmod -ae here
pushd %{target_modules}
for i in *; do
	/sbin/depmod -ae -b %{buildroot} -F %{target_boot}/System.map-$i $i
	echo $?
done

for i in *; do
	pushd $i
	echo "Creating modules.description for $i"
	modules=`find . -name "*.ko.[g,x]z"`
	echo $modules | xargs /sbin/modinfo \
	| perl -lne 'print "$name\t$1" if $name && /^description:\s*(.*)/; $name = $1 if m!^filename:\s*(.*)\.k?o!; $name =~ s!.*/!!' > modules.description
	popd
done
popd

# need to set extraversion to match srpm again to avoid rebuild
LC_ALL=C perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -%{rpmrel}/" Makefile

# install userspace-headers
%if %{build_uheaders}
%smake ARCH=%{target_arch} headers_install INSTALL_HDR_PATH=%{target_headers}
# for drakx
cp include/linux/pci_ids.h %{target_headers}/include/linux/
%endif

%if %{build_perf}
# perf tool binary and supporting scripts/binaries
%smake -s -C tools/perf V=1 DESTDIR=%{buildroot} NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 WERROR=0 NO_LIBUNWIND=1 \
	HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_STRLCPY=1 NO_BIONIC=1 NO_JVMTI=1 prefix=%{_prefix} lib=%{_lib} install

# perf man pages (note: implicit rpm magic compresses them later)
make -C tools/perf V=1 DESTDIR=%{buildroot} prefix=%{_prefix} install-man

# remove perf files we dont ship
rm -rf %{buildroot}/usr/lib/perf/examples
rm -rf %{buildroot}/usr/lib/perf/include/bpf
rm -rf %{buildroot}/usr/include/perf/perf_dlfilter.h
%endif

%if %{build_cpupower}
make -C tools/power/cpupower DESTDIR=%{buildroot} libdir=%{_libdir} mandir=%{_mandir} CPUFREQ_BENCH=false install
rm -f %{buildroot}%{_libdir}/*.{a,la}
%find_lang cpupower
mv cpupower.lang ../
chmod 0755 %{buildroot}%{_libdir}/libcpupower.so*
mkdir -p %{buildroot}%{_unitdir} %{buildroot}%{_sysconfdir}/sysconfig
install -m644 %{SOURCE50} %{buildroot}%{_unitdir}/cpupower.service
install -m644 %{SOURCE51} %{buildroot}%{_sysconfdir}/sysconfig/cpupower
%endif

# install bpftool
%if %{build_bpftool}
pushd tools/bpf/bpftool
make DESTDIR=%{buildroot} prefix=%{_prefix} bash_compdir=%{_sysconfdir}/bash_completion.d/ mandir=%{_mandir} install doc-install
popd
%endif

# install libbpf
%if %{build_libbpf}
pushd tools/lib/bpf
make DESTDIR=%{buildroot} prefix=%{_prefix} libdir=%{_libdir} V=1 install install_headers
popd
%endif

###
### clean
###
%clean
rm -rf %{buildroot}


# We don't want to remove this, the whole reason of its existence is to be
# able to do several rpm --short-circuit -bi for testing install
# phase without repeating compilation phase
#rm -rf %{temp_root}

###
### source and doc file lists
###

%if %build_source
%files -n %{kname}-source-%{buildrel}
%doc %{_kerneldir}/LICENSES
%dir %{_kerneldir}
%dir %{_kerneldir}/arch
%dir %{_kerneldir}/include
%{_kerneldir}/.rustfmt.toml
%{_kerneldir}/Documentation
%{_kerneldir}/arch/Kconfig
%{_kerneldir}/arch/arm
%{_kerneldir}/arch/arm64
%{_kerneldir}/arch/um
%{_kerneldir}/arch/x86
%{_kerneldir}/block
%{_kerneldir}/certs
%{_kerneldir}/crypto
%{_kerneldir}/drivers
%{_kerneldir}/fs
%{_kerneldir}/include/acpi
%{_kerneldir}/include/asm-generic
%{_kerneldir}/include/clocksource
%{_kerneldir}/include/crypto
%{_kerneldir}/include/drm
%{_kerneldir}/include/dt-bindings
%{_kerneldir}/include/keys
%{_kerneldir}/include/kunit
%{_kerneldir}/include/kvm
%{_kerneldir}/include/linux
%{_kerneldir}/include/math-emu
%{_kerneldir}/include/media
%{_kerneldir}/include/memory
%{_kerneldir}/include/misc
%{_kerneldir}/include/net
%{_kerneldir}/include/pcmcia
%{_kerneldir}/include/ras
%{_kerneldir}/include/rdma
%{_kerneldir}/include/rv
%{_kerneldir}/include/scsi
%{_kerneldir}/include/soc
%{_kerneldir}/include/sound
%{_kerneldir}/include/target
%{_kerneldir}/include/trace
%{_kerneldir}/include/uapi
%{_kerneldir}/include/ufs
%{_kerneldir}/include/vdso/*.h
%{_kerneldir}/include/video
%{_kerneldir}/include/xen
%{_kerneldir}/init
%{_kerneldir}/io_uring
%{_kerneldir}/ipc
%{_kerneldir}/kernel
%{_kerneldir}/lib
%{_kerneldir}/mm
%{_kerneldir}/net
%{_kerneldir}/rust
%{_kerneldir}/samples
%{_kerneldir}/scripts
%{_kerneldir}/security
%{_kerneldir}/sound
%{_kerneldir}/tools
%{_kerneldir}/usr
%{_kerneldir}/virt
%{_kerneldir}/COPYING
%{_kerneldir}/CREDITS
%{_kerneldir}/Kbuild
%{_kerneldir}/Kconfig
%{_kerneldir}/MAINTAINERS
%{_kerneldir}/Makefile
%{_kerneldir}/README
%doc README.kernel-sources

%files -n %{kname}-source-latest
%endif

%if %build_doc
%files -n %{kname}-doc
%doc linux-%{tar_ver}/Documentation/*
%endif

%if %build_uheaders
%files -n %{kname}-userspace-headers
%defattr(0644,root,root,0755)
%{_includedir}/asm/
%{_includedir}/asm-generic/
%{_includedir}/drm/
%{_includedir}/linux/
%{_includedir}/misc/
%{_includedir}/mtd/
%{_includedir}/rdma/
%{_includedir}/scsi/
%{_includedir}/sound/
%{_includedir}/video/
%{_includedir}/xen/
%endif

%if %{build_perf}
%files -n perf
%{_bindir}/perf
%{_bindir}/trace
%{_datadir}/perf-core/strace/groups/file
%{_datadir}/perf-core/strace/groups/string
%{_datadir}/doc/perf-tip/tips.txt
%dir %{_libdir}/traceevent
%dir %{_libdir}/traceevent/plugins
%{_libdir}/traceevent/plugins/plugin_*
%dir %{_prefix}/libexec/perf-core
%{_prefix}/libexec/perf-core/*
%{_mandir}/man[1-8]/perf*
%{_sysconfdir}/bash_completion.d/perf
%endif

%if %{build_cpupower}
%files -n cpupower -f cpupower.lang
%config(noreplace) %{_sysconfdir}/sysconfig/cpupower
%{_bindir}/cpupower
%{_datadir}/bash-completion/completions/cpupower
%{_libdir}/libcpupower.so.0
%{_libdir}/libcpupower.so.0.0.1
%{_unitdir}/cpupower.service
%{_mandir}/man[1-8]/cpupower*

%files -n cpupower-devel
%{_libdir}/libcpupower.so
%{_includedir}/cpuidle.h
%{_includedir}/cpufreq.h
%endif

%if %{build_bpftool}
%files -n bpftool
%{_sbindir}/bpftool
%{_sysconfdir}/bash_completion.d/bpftool
%{_mandir}/man8/bpftool-*.8*
%{_mandir}/man8/bpftool.8*
%endif

%if %{build_libbpf}
%files -n %{_lib}bpf%{bpfmajor}
%{_libdir}/libbpf.so.%{bpfmajor}{,.*}

%files -n %{_lib}bpf-devel
%{_libdir}/libbpf.a
%{_libdir}/libbpf.so
%{_libdir}/pkgconfig/libbpf.pc
%{_includedir}/bpf/bpf.h
%{_includedir}/bpf/bpf_core_read.h
%{_includedir}/bpf/bpf_endian.h
%{_includedir}/bpf/bpf_helper_defs.h
%{_includedir}/bpf/bpf_helpers.h
%{_includedir}/bpf/bpf_tracing.h
%{_includedir}/bpf/btf.h
%{_includedir}/bpf/libbpf.h
%{_includedir}/bpf/libbpf_common.h
%{_includedir}/bpf/libbpf_legacy.h
%{_includedir}/bpf/libbpf_version.h
%{_includedir}/bpf/skel_internal.h
%{_includedir}/bpf/usdt.bpf.h
%endif