44a40b
# All Global changes to build and install go here.
44a40b
# Per the below section about __spec_install_pre, any rpm
44a40b
# environment changes that affect %%install need to go
44a40b
# here before the %%install macro is pre-built.
44a40b
44a40b
# Include Fedora files
44a40b
%global include_fedora 0
44a40b
# Include RHEL files
44a40b
%global include_rhel 1
44a40b
44a40b
# Disable LTO in userspace packages.
44a40b
%global _lto_cflags %{nil}
44a40b
44a40b
# Option to enable compiling with clang instead of gcc.
44a40b
%bcond_with toolchain_clang
44a40b
44a40b
%if %{with toolchain_clang}
44a40b
%global toolchain clang
44a40b
%endif
44a40b
44a40b
# Compile the kernel with LTO (only supported when building with clang).
44a40b
%bcond_with clang_lto
44a40b
44a40b
%if %{with clang_lto} && %{without toolchain_clang}
44a40b
{error:clang_lto requires --with toolchain_clang}
44a40b
%endif
44a40b
44a40b
# Cross compile on copr for arm
44a40b
# See https://bugzilla.redhat.com/1879599
44a40b
%if 0%{?_with_cross_arm:1}
44a40b
%global _target_cpu armv7hl
44a40b
%global _arch arm
44a40b
%global _build_arch arm
44a40b
%global _with_cross    1
44a40b
%endif
44a40b
44a40b
# The kernel's %%install section is special
44a40b
# Normally the %%install section starts by cleaning up the BUILD_ROOT
44a40b
# like so:
44a40b
#
44a40b
# %%__spec_install_pre %%{___build_pre}\
44a40b
#     [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "${RPM_BUILD_ROOT}"\
44a40b
#     mkdir -p `dirname "$RPM_BUILD_ROOT"`\
44a40b
#     mkdir "$RPM_BUILD_ROOT"\
44a40b
# %%{nil}
44a40b
#
44a40b
# But because of kernel variants, the %%build section, specifically
44a40b
# BuildKernel(), moves each variant to its final destination as the
44a40b
# variant is built.  This violates the expectation of the %%install
44a40b
# section.  As a result we snapshot the current env variables and
44a40b
# purposely leave out the removal section.  All global wide changes
44a40b
# should be added above this line otherwise the %%install section
44a40b
# will not see them.
44a40b
%global __spec_install_pre %{___build_pre}
44a40b
44a40b
# At the time of this writing (2019-03), RHEL8 packages use w2.xzdio
44a40b
# compression for rpms (xz, level 2).
44a40b
# Kernel has several large (hundreds of mbytes) rpms, they take ~5 mins
44a40b
# to compress by single-threaded xz. Switch to threaded compression,
44a40b
# and from level 2 to 3 to keep compressed sizes close to "w2" results.
44a40b
#
44a40b
# NB: if default compression in /usr/lib/rpm/redhat/macros ever changes,
44a40b
# this one might need tweaking (e.g. if default changes to w3.xzdio,
44a40b
# change below to w4T.xzdio):
44a40b
#
44a40b
# This is disabled on i686 as it triggers oom errors
44a40b
44a40b
%ifnarch i686
44a40b
%define _binary_payload w3T.xzdio
44a40b
%endif
44a40b
44a40b
Summary: The Linux kernel
44a40b
44a40b
# Set debugbuildsenabled to 1 to build separate base and debug kernels
44a40b
#  (on supported architectures). The kernel-debug-* subpackages will
44a40b
#  contain the debug kernel.
44a40b
# Set debugbuildsenabled to 0 to not build a separate debug kernel, but
44a40b
#  to build the base kernel using the debug configuration. (Specifying
44a40b
#  the --with-release option overrides this setting.)
44a40b
%define debugbuildsenabled 1
44a40b
44a40b
%if 0%{?fedora}
44a40b
%define secure_boot_arch x86_64
44a40b
%else
44a40b
%define secure_boot_arch x86_64 aarch64 s390x ppc64le
44a40b
%endif
44a40b
44a40b
# Signing for secure boot authentication
44a40b
%ifarch %{secure_boot_arch}
44a40b
%global signkernel 1
44a40b
%else
44a40b
%global signkernel 0
44a40b
%endif
44a40b
44a40b
# Sign modules on all arches
44a40b
%global signmodules 1
44a40b
44a40b
# Compress modules only for architectures that build modules
44a40b
%ifarch noarch
44a40b
%global zipmodules 0
44a40b
%else
44a40b
%global zipmodules 1
44a40b
%endif
44a40b
44a40b
%if %{zipmodules}
44a40b
%global zipsed -e 's/\.ko$/\.ko.xz/'
44a40b
# for parallel xz processes, replace with 1 to go back to single process
44a40b
%global zcpu `nproc --all`
44a40b
%endif
44a40b
44a40b
# define buildid .local
44a40b
44a40b
44a40b
%if 0%{?fedora}
44a40b
%define primary_target fedora
44a40b
%else
44a40b
%define primary_target rhel
44a40b
%endif
44a40b
44a40b
# The kernel tarball/base version
44a40b
%define kversion 5.14
44a40b
44a40b
%define rpmversion 5.14.0
dc9f2b
%define pkgrelease 70.22.1.el9_0
44a40b
44a40b
# This is needed to do merge window version magic
44a40b
%define patchlevel 14
44a40b
44a40b
# allow pkg_release to have configurable %%{?dist} tag
dc9f2b
%define specrelease 70.22.1%{?buildid}%{?dist}
44a40b
44a40b
%define pkg_release %{specrelease}
44a40b
44a40b
# libexec dir is not used by the linker, so the shared object there
44a40b
# should not be exported to RPM provides
44a40b
%global __provides_exclude_from ^%{_libexecdir}/kselftests
44a40b
44a40b
%define _with_kabidupchk 1
44a40b
# The following build options are enabled by default, but may become disabled
44a40b
# by later architecture-specific checks. These can also be disabled by using
44a40b
# --without <opt> in the rpmbuild command, or by forcing these values to 0.
44a40b
#
44a40b
# standard kernel
44a40b
%define with_up        %{?_without_up:        0} %{?!_without_up:        1}
44a40b
# kernel PAE (only valid for ARM (lpae))
44a40b
%define with_pae       %{?_without_pae:       0} %{?!_without_pae:       1}
44a40b
# kernel-debug
44a40b
%define with_debug     %{?_without_debug:     0} %{?!_without_debug:     1}
44a40b
# kernel-zfcpdump (s390 specific kernel for zfcpdump)
44a40b
%define with_zfcpdump  %{?_without_zfcpdump:  0} %{?!_without_zfcpdump:  1}
44a40b
# kernel-doc
44a40b
%define with_doc       %{?_without_doc:       0} %{?!_without_doc:       1}
44a40b
# kernel-headers
44a40b
%define with_headers   %{?_without_headers:   0} %{?!_without_headers:   1}
44a40b
%define with_cross_headers   %{?_without_cross_headers:   0} %{?!_without_cross_headers:   1}
44a40b
# perf
44a40b
%define with_perf      %{?_without_perf:      0} %{?!_without_perf:      1}
44a40b
# tools
44a40b
%define with_tools     %{?_without_tools:     0} %{?!_without_tools:     1}
44a40b
# bpf tool
44a40b
%define with_bpftool   %{?_without_bpftool:   0} %{?!_without_bpftool:   1}
44a40b
# kernel-debuginfo
44a40b
%define with_debuginfo %{?_without_debuginfo: 0} %{?!_without_debuginfo: 1}
44a40b
# kernel-abi-stablelists
44a40b
%define with_kernel_abi_stablelists %{?_without_kernel_abi_stablelists: 0} %{?!_without_kernel_abi_stablelists: 1}
44a40b
# internal samples and selftests
44a40b
%define with_selftests %{?_without_selftests: 0} %{?!_without_selftests: 1}
44a40b
#
44a40b
# Additional options for user-friendly one-off kernel building:
44a40b
#
44a40b
# Only build the base kernel (--with baseonly):
44a40b
%define with_baseonly  %{?_with_baseonly:     1} %{?!_with_baseonly:     0}
44a40b
# Only build the pae kernel (--with paeonly):
44a40b
%define with_paeonly   %{?_with_paeonly:      1} %{?!_with_paeonly:      0}
44a40b
# Only build the debug kernel (--with dbgonly):
44a40b
%define with_dbgonly   %{?_with_dbgonly:      1} %{?!_with_dbgonly:      0}
44a40b
# Control whether we perform a compat. check against published ABI.
44a40b
%define with_kabichk   %{?_without_kabichk:   0} %{?!_without_kabichk:   1}
44a40b
# Temporarily disable kabi checks until RC.
44a40b
%define with_kabichk 0
44a40b
# Control whether we perform a compat. check against DUP ABI.
44a40b
%define with_kabidupchk %{?_with_kabidupchk:  1} %{?!_with_kabidupchk:   0}
44a40b
#
44a40b
# Control whether to run an extensive DWARF based kABI check.
44a40b
# Note that this option needs to have baseline setup in SOURCE300.
44a40b
%define with_kabidwchk %{?_without_kabidwchk: 0} %{?!_without_kabidwchk: 1}
44a40b
%define with_kabidw_base %{?_with_kabidw_base: 1} %{?!_with_kabidw_base: 0}
44a40b
#
44a40b
# Control whether to install the vdso directories.
44a40b
%define with_vdso_install %{?_without_vdso_install: 0} %{?!_without_vdso_install: 1}
44a40b
#
44a40b
# should we do C=1 builds with sparse
44a40b
%define with_sparse    %{?_with_sparse:       1} %{?!_with_sparse:       0}
44a40b
#
44a40b
# Cross compile requested?
44a40b
%define with_cross    %{?_with_cross:         1} %{?!_with_cross:        0}
44a40b
#
44a40b
# build a release kernel on rawhide
44a40b
%define with_release   %{?_with_release:      1} %{?!_with_release:      0}
44a40b
44a40b
# verbose build, i.e. no silent rules and V=1
44a40b
%define with_verbose %{?_with_verbose:        1} %{?!_with_verbose:      0}
44a40b
44a40b
#
44a40b
# check for mismatched config options
44a40b
%define with_configchecks %{?_without_configchecks:        0} %{?!_without_configchecks:        1}
44a40b
44a40b
#
44a40b
# gcov support
44a40b
%define with_gcov %{?_with_gcov:1}%{?!_with_gcov:0}
44a40b
44a40b
#
44a40b
# ipa_clone support
44a40b
%define with_ipaclones %{?_without_ipaclones: 0} %{?!_without_ipaclones: 1}
44a40b
44a40b
# Want to build a vanilla kernel build without any non-upstream patches?
44a40b
%define with_vanilla %{?_with_vanilla: 1} %{?!_with_vanilla: 0}
44a40b
44a40b
%if 0%{?fedora}
44a40b
# Kernel headers are being split out into a separate package
44a40b
%define with_headers 0
44a40b
%define with_cross_headers 0
44a40b
# no ipa_clone for now
44a40b
%define with_ipaclones 0
44a40b
# no stablelist
44a40b
%define with_kernel_abi_stablelists 0
44a40b
# Fedora builds these separately
44a40b
%define with_perf 0
44a40b
%define with_tools 0
44a40b
%define with_bpftool 0
44a40b
# selftests turns on bpftool
44a40b
%define with_selftests 0
44a40b
%endif
44a40b
44a40b
%if %{with_verbose}
44a40b
%define make_opts V=1
44a40b
%else
44a40b
%define make_opts -s
44a40b
%endif
44a40b
44a40b
%if %{with toolchain_clang}
44a40b
%global clang_make_opts HOSTCC=clang CC=clang
44a40b
%if %{with clang_lto}
44a40b
%global clang_make_opts %{clang_make_opts} LD=ld.lld HOSTLD=ld.lld AR=llvm-ar NM=llvm-nm HOSTAR=llvm-ar HOSTNM=llvm-nm LLVM_IAS=1
44a40b
%endif
44a40b
%global make_opts %{make_opts} %{clang_make_opts}
44a40b
# clang does not support the -fdump-ipa-clones option
44a40b
%global with_ipaclones 0
44a40b
%endif
44a40b
44a40b
# turn off debug kernel and kabichk for gcov builds
44a40b
%if %{with_gcov}
44a40b
%define with_debug 0
44a40b
%define with_kabichk 0
44a40b
%define with_kabidupchk 0
44a40b
%define with_kabidwchk 0
44a40b
%define with_kabidw_base 0
44a40b
%define with_kernel_abi_stablelists 0
44a40b
%endif
44a40b
44a40b
# turn off kABI DWARF-based check if we're generating the base dataset
44a40b
%if %{with_kabidw_base}
44a40b
%define with_kabidwchk 0
44a40b
%endif
44a40b
44a40b
# kpatch_kcflags are extra compiler flags applied to base kernel
44a40b
# -fdump-ipa-clones is enabled only for base kernels on selected arches
44a40b
%if %{with_ipaclones}
44a40b
%ifarch x86_64 ppc64le
44a40b
%define kpatch_kcflags -fdump-ipa-clones
44a40b
%else
44a40b
%define with_ipaclones 0
44a40b
%endif
44a40b
%endif
44a40b
44a40b
%define make_target bzImage
44a40b
%define image_install_path boot
44a40b
44a40b
%define KVERREL %{version}-%{release}.%{_target_cpu}
44a40b
%define KVERREL_RE %(echo %KVERREL | sed 's/+/[+]/g')
44a40b
%define hdrarch %_target_cpu
44a40b
%define asmarch %_target_cpu
44a40b
44a40b
%if 0%{!?nopatches:1}
44a40b
%define nopatches 0
44a40b
%endif
44a40b
44a40b
%if %{with_vanilla}
44a40b
%define nopatches 1
44a40b
%endif
44a40b
44a40b
%if %{with_release}
44a40b
%define debugbuildsenabled 1
44a40b
%endif
44a40b
44a40b
%if !%{with_debuginfo}
44a40b
%define _enable_debug_packages 0
44a40b
%endif
44a40b
%define debuginfodir /usr/lib/debug
44a40b
# Needed because we override almost everything involving build-ids
44a40b
# and debuginfo generation. Currently we rely on the old alldebug setting.
44a40b
%global _build_id_links alldebug
44a40b
44a40b
# kernel PAE is only built on ARMv7
44a40b
%ifnarch armv7hl
44a40b
%define with_pae 0
44a40b
%endif
44a40b
44a40b
# if requested, only build base kernel
44a40b
%if %{with_baseonly}
44a40b
%define with_pae 0
44a40b
%define with_debug 0
44a40b
%define with_vdso_install 0
44a40b
%define with_perf 0
44a40b
%define with_tools 0
44a40b
%define with_bpftool 0
44a40b
%define with_kernel_abi_stablelists 0
44a40b
%define with_selftests 0
44a40b
%define with_cross 0
44a40b
%define with_cross_headers 0
44a40b
%define with_ipaclones 0
44a40b
%endif
44a40b
44a40b
# if requested, only build pae kernel
44a40b
%if %{with_paeonly}
44a40b
%define with_up 0
44a40b
%define with_debug 0
44a40b
%endif
44a40b
44a40b
# if requested, only build debug kernel
44a40b
%if %{with_dbgonly}
44a40b
%define with_up 0
44a40b
%define with_vdso_install 0
44a40b
%define with_perf 0
44a40b
%define with_tools 0
44a40b
%define with_bpftool 0
44a40b
%define with_kernel_abi_stablelists 0
44a40b
%define with_selftests 0
44a40b
%define with_cross 0
44a40b
%define with_cross_headers 0
44a40b
%define with_ipaclones 0
44a40b
%endif
44a40b
44a40b
# turn off kABI DUP check and DWARF-based check if kABI check is disabled
44a40b
%if !%{with_kabichk}
44a40b
%define with_kabidupchk 0
44a40b
%define with_kabidwchk 0
44a40b
%endif
44a40b
44a40b
%if %{with_vdso_install}
44a40b
%define use_vdso 1
44a40b
%endif
44a40b
44a40b
# selftests require bpftool to be built
44a40b
%if %{with_selftests}
44a40b
%define with_bpftool 1
44a40b
%endif
44a40b
44a40b
%ifnarch noarch
44a40b
%define with_kernel_abi_stablelists 0
44a40b
%endif
44a40b
44a40b
# Overrides for generic default options
44a40b
44a40b
# only package docs noarch
44a40b
%ifnarch noarch
44a40b
%define with_doc 0
44a40b
%define doc_build_fail true
44a40b
%endif
44a40b
44a40b
%if 0%{?fedora}
44a40b
# don't do debug builds on anything but i686 and x86_64
44a40b
%ifnarch i686 x86_64
44a40b
%define with_debug 0
44a40b
%endif
44a40b
%endif
44a40b
44a40b
# don't build noarch kernels or headers (duh)
44a40b
%ifarch noarch
44a40b
%define with_up 0
44a40b
%define with_headers 0
44a40b
%define with_cross_headers 0
44a40b
%define with_tools 0
44a40b
%define with_perf 0
44a40b
%define with_bpftool 0
44a40b
%define with_selftests 0
44a40b
%define with_debug 0
44a40b
%define all_arch_configs kernel-%{version}-*.config
44a40b
%endif
44a40b
44a40b
# sparse blows up on ppc
44a40b
%ifnarch ppc64le
44a40b
%define with_sparse 0
44a40b
%endif
44a40b
44a40b
# zfcpdump mechanism is s390 only
44a40b
%ifnarch s390x
44a40b
%define with_zfcpdump 0
44a40b
%endif
44a40b
44a40b
%if 0%{?fedora}
44a40b
# This is not for Fedora
44a40b
%define with_zfcpdump 0
44a40b
%endif
44a40b
44a40b
# Per-arch tweaks
44a40b
44a40b
%ifarch i686
44a40b
%define asmarch x86
44a40b
%define hdrarch i386
44a40b
%define all_arch_configs kernel-%{version}-i?86*.config
44a40b
%define kernel_image arch/x86/boot/bzImage
44a40b
%endif
44a40b
44a40b
%ifarch x86_64
44a40b
%define asmarch x86
44a40b
%define all_arch_configs kernel-%{version}-x86_64*.config
44a40b
%define kernel_image arch/x86/boot/bzImage
44a40b
%endif
44a40b
44a40b
%ifarch ppc64le
44a40b
%define asmarch powerpc
44a40b
%define hdrarch powerpc
44a40b
%define make_target vmlinux
44a40b
%define kernel_image vmlinux
44a40b
%define kernel_image_elf 1
44a40b
%define use_vdso 0
44a40b
%define all_arch_configs kernel-%{version}-ppc64le*.config
44a40b
%endif
44a40b
44a40b
%ifarch s390x
44a40b
%define asmarch s390
44a40b
%define hdrarch s390
44a40b
%define all_arch_configs kernel-%{version}-s390x.config
44a40b
%define kernel_image arch/s390/boot/bzImage
44a40b
%define vmlinux_decompressor arch/s390/boot/compressed/vmlinux
44a40b
%endif
44a40b
44a40b
%ifarch %{arm}
44a40b
%define all_arch_configs kernel-%{version}-arm*.config
44a40b
%define skip_nonpae_vdso 1
44a40b
%define asmarch arm
44a40b
%define hdrarch arm
44a40b
%define make_target bzImage
44a40b
%define kernel_image arch/arm/boot/zImage
44a40b
# http://lists.infradead.org/pipermail/linux-arm-kernel/2012-March/091404.html
44a40b
%define kernel_mflags KALLSYMS_EXTRA_PASS=1
44a40b
# we only build headers/perf/tools on the base arm arches
44a40b
# just like we used to only build them on i386 for x86
44a40b
%ifnarch armv7hl
44a40b
%define with_headers 0
44a40b
%define with_cross_headers 0
44a40b
%endif
44a40b
# These currently don't compile on armv7
44a40b
%define with_selftests 0
44a40b
%endif
44a40b
44a40b
%ifarch aarch64
44a40b
%define all_arch_configs kernel-%{version}-aarch64*.config
44a40b
%define asmarch arm64
44a40b
%define hdrarch arm64
44a40b
%define make_target Image.gz
44a40b
%define kernel_image arch/arm64/boot/Image.gz
44a40b
%endif
44a40b
44a40b
# Should make listnewconfig fail if there's config options
44a40b
# printed out?
44a40b
%if %{nopatches}
44a40b
%define with_configchecks 0
44a40b
%endif
44a40b
44a40b
# To temporarily exclude an architecture from being built, add it to
44a40b
# %%nobuildarches. Do _NOT_ use the ExclusiveArch: line, because if we
44a40b
# don't build kernel-headers then the new build system will no longer let
44a40b
# us use the previous build of that package -- it'll just be completely AWOL.
44a40b
# Which is a BadThing(tm).
44a40b
44a40b
# We only build kernel-headers on the following...
44a40b
%if 0%{?fedora}
44a40b
%define nobuildarches i386
44a40b
%else
44a40b
%define nobuildarches i386 i686 %{arm}
44a40b
%endif
44a40b
44a40b
%ifarch %nobuildarches
44a40b
# disable BuildKernel commands
44a40b
%define with_up 0
44a40b
%define with_debug 0
44a40b
%define with_pae 0
44a40b
%define with_zfcpdump 0
44a40b
44a40b
%define with_debuginfo 0
44a40b
%define with_perf 0
44a40b
%define with_tools 0
44a40b
%define with_bpftool 0
44a40b
%define with_selftests 0
44a40b
%define _enable_debug_packages 0
44a40b
%endif
44a40b
44a40b
# Architectures we build tools/cpupower on
44a40b
%if 0%{?fedora}
44a40b
%define cpupowerarchs %{ix86} x86_64 ppc64le %{arm} aarch64
44a40b
%else
44a40b
%define cpupowerarchs i686 x86_64 ppc64le aarch64
44a40b
%endif
44a40b
44a40b
%if 0%{?use_vdso}
44a40b
44a40b
%if 0%{?skip_nonpae_vdso}
44a40b
%define _use_vdso 0
44a40b
%else
44a40b
%define _use_vdso 1
44a40b
%endif
44a40b
44a40b
%else
44a40b
%define _use_vdso 0
44a40b
%endif
44a40b
44a40b
# If build of debug packages is disabled, we need to know if we want to create
44a40b
# meta debug packages or not, after we define with_debug for all specific cases
44a40b
# above. So this must be at the end here, after all cases of with_debug or not.
44a40b
%define with_debug_meta 0
44a40b
%if !%{debugbuildsenabled}
44a40b
%if %{with_debug}
44a40b
%define with_debug_meta 1
44a40b
%endif
44a40b
%define with_debug 0
44a40b
%endif
44a40b
44a40b
44a40b
#
44a40b
# Packages that need to be installed before the kernel is, because the %%post
44a40b
# scripts use them.
44a40b
#
44a40b
%define kernel_prereq  coreutils, systemd >= 203-2, /usr/bin/kernel-install
44a40b
%define initrd_prereq  dracut >= 027
44a40b
44a40b
44a40b
Name: kernel
44a40b
License: GPLv2 and Redistributable, no modification permitted
44a40b
URL: https://www.kernel.org/
44a40b
Version: %{rpmversion}
44a40b
Release: %{pkg_release}
44a40b
# DO NOT CHANGE THE 'ExclusiveArch' LINE TO TEMPORARILY EXCLUDE AN ARCHITECTURE BUILD.
44a40b
# SET %%nobuildarches (ABOVE) INSTEAD
44a40b
%if 0%{?fedora}
44a40b
ExclusiveArch: x86_64 s390x %{arm} aarch64 ppc64le
44a40b
%else
44a40b
ExclusiveArch: noarch i386 i686 x86_64 s390x %{arm} aarch64 ppc64le
44a40b
%endif
44a40b
ExclusiveOS: Linux
44a40b
%ifnarch %{nobuildarches}
44a40b
Requires: kernel-core-uname-r = %{KVERREL}
44a40b
Requires: kernel-modules-uname-r = %{KVERREL}
44a40b
%endif
44a40b
44a40b
44a40b
#
44a40b
# List the packages used during the kernel build
44a40b
#
44a40b
BuildRequires: kmod, patch, bash, coreutils, tar, git-core, which
44a40b
BuildRequires: bzip2, xz, findutils, gzip, m4, perl-interpreter, perl-Carp, perl-devel, perl-generators, make, diffutils, gawk
44a40b
BuildRequires: gcc, binutils, redhat-rpm-config, hmaccalc, bison, flex, gcc-c++
44a40b
BuildRequires: net-tools, hostname, bc, elfutils-devel
44a40b
BuildRequires: dwarves
44a40b
BuildRequires: python3-devel
44a40b
BuildRequires: gcc-plugin-devel
44a40b
# glibc-static is required for a consistent build environment (specifically
44a40b
# CONFIG_CC_CAN_LINK_STATIC=y).
44a40b
BuildRequires: glibc-static
44a40b
BuildRequires: kernel-rpm-macros >= 185-9
44a40b
%ifnarch %{nobuildarches} noarch
44a40b
BuildRequires: bpftool
44a40b
%endif
44a40b
%if %{with_headers}
44a40b
BuildRequires: rsync
44a40b
%endif
44a40b
%if %{with_doc}
44a40b
BuildRequires: xmlto, asciidoc, python3-sphinx, python3-sphinx_rtd_theme
44a40b
%endif
44a40b
%if %{with_sparse}
44a40b
BuildRequires: sparse
44a40b
%endif
44a40b
%if %{with_perf}
44a40b
BuildRequires: zlib-devel binutils-devel newt-devel perl(ExtUtils::Embed) bison flex xz-devel
44a40b
BuildRequires: audit-libs-devel
44a40b
BuildRequires: java-devel
44a40b
BuildRequires: libbpf-devel
44a40b
BuildRequires: libbabeltrace-devel
44a40b
BuildRequires: libtraceevent-devel
44a40b
%ifnarch %{arm} s390x
44a40b
BuildRequires: numactl-devel
44a40b
%endif
44a40b
%ifarch aarch64
44a40b
BuildRequires: opencsd-devel >= 1.0.0
44a40b
%endif
44a40b
%endif
44a40b
%if %{with_tools}
44a40b
BuildRequires: gettext ncurses-devel
44a40b
BuildRequires: libcap-devel libcap-ng-devel
44a40b
%ifnarch s390x
44a40b
BuildRequires: pciutils-devel
44a40b
%endif
44a40b
%endif
44a40b
%if %{with_tools} || %{signmodules} || %{signkernel}
44a40b
BuildRequires: openssl-devel
44a40b
%endif
44a40b
%if %{with_bpftool}
44a40b
BuildRequires: python3-docutils
44a40b
BuildRequires: zlib-devel binutils-devel
44a40b
%endif
44a40b
%if %{with_selftests}
44a40b
BuildRequires: clang llvm fuse-devel
44a40b
%ifnarch %{arm}
44a40b
BuildRequires: numactl-devel
44a40b
%endif
44a40b
BuildRequires: libcap-devel libcap-ng-devel rsync libmnl-devel
44a40b
%endif
44a40b
BuildConflicts: rhbuildsys(DiskFree) < 500Mb
44a40b
%if %{with_debuginfo}
44a40b
BuildRequires: rpm-build, elfutils
44a40b
BuildConflicts: rpm < 4.13.0.1-19
44a40b
BuildConflicts: dwarves < 1.13
44a40b
# Most of these should be enabled after more investigation
44a40b
%undefine _include_minidebuginfo
44a40b
%undefine _find_debuginfo_dwz_opts
44a40b
%undefine _unique_build_ids
44a40b
%undefine _unique_debug_names
44a40b
%undefine _unique_debug_srcs
44a40b
%undefine _debugsource_packages
44a40b
%undefine _debuginfo_subpackages
44a40b
%global _find_debuginfo_opts -r
44a40b
%global _missing_build_ids_terminate_build 1
44a40b
%global _no_recompute_build_ids 1
44a40b
%endif
44a40b
%if %{with_kabidwchk} || %{with_kabidw_base}
44a40b
BuildRequires: kabi-dw
44a40b
%endif
44a40b
44a40b
%if %{signkernel}%{signmodules}
44a40b
BuildRequires: openssl
44a40b
%if %{signkernel}
44a40b
BuildRequires: system-sb-certs
44a40b
%ifarch x86_64 aarch64
44a40b
BuildRequires: nss-tools
44a40b
BuildRequires: pesign >= 0.10-4
44a40b
%endif
44a40b
%endif
44a40b
%endif
44a40b
44a40b
%if %{with_cross}
44a40b
BuildRequires: binutils-%{_build_arch}-linux-gnu, gcc-%{_build_arch}-linux-gnu
44a40b
%define cross_opts CROSS_COMPILE=%{_build_arch}-linux-gnu-
44a40b
%define __strip %{_build_arch}-linux-gnu-strip
44a40b
%endif
44a40b
44a40b
# These below are required to build man pages
44a40b
%if %{with_perf}
44a40b
BuildRequires: xmlto
44a40b
%endif
44a40b
%if %{with_perf} || %{with_tools}
44a40b
BuildRequires: asciidoc
44a40b
%endif
44a40b
44a40b
%if %{with toolchain_clang}
44a40b
BuildRequires: clang
44a40b
%endif
44a40b
44a40b
%if %{with clang_lto}
44a40b
BuildRequires: llvm
44a40b
BuildRequires: lld
44a40b
%endif
44a40b
44a40b
# Because this is the kernel, it's hard to get a single upstream URL
44a40b
# to represent the base without needing to do a bunch of patching. This
44a40b
# tarball is generated from a src-git tree. If you want to see the
44a40b
# exact git commit you can run
44a40b
#
44a40b
# xzcat -qq ${TARBALL} | git get-tar-commit-id
dc9f2b
Source0: linux-5.14.0-70.22.1.el9_0.tar.xz
44a40b
44a40b
Source1: Makefile.rhelver
44a40b
44a40b
%if %{signkernel}
44a40b
44a40b
# Name of the packaged file containing signing key
44a40b
%ifarch ppc64le
44a40b
%define signing_key_filename kernel-signing-ppc.cer
44a40b
%endif
44a40b
%ifarch s390x
44a40b
%define signing_key_filename kernel-signing-s390.cer
44a40b
%endif
44a40b
44a40b
%define secureboot_ca_0 %{_datadir}/pki/sb-certs/secureboot-ca-%{_arch}.cer
44a40b
%define secureboot_key_0 %{_datadir}/pki/sb-certs/secureboot-kernel-%{_arch}.cer
44a40b
44a40b
%if 0%{?centos}
44a40b
%define pesign_name_0 centossecureboot201
44a40b
%else
44a40b
%ifarch x86_64 aarch64
44a40b
%define pesign_name_0 redhatsecureboot501
44a40b
%endif
44a40b
%ifarch s390x
44a40b
%define pesign_name_0 redhatsecureboot302
44a40b
%endif
44a40b
%ifarch ppc64le
44a40b
%define pesign_name_0 redhatsecureboot601
44a40b
%endif
44a40b
%endif
44a40b
44a40b
# signkernel
44a40b
%endif
44a40b
44a40b
Source20: mod-denylist.sh
44a40b
Source21: mod-sign.sh
44a40b
Source22: parallel_xz.sh
44a40b
44a40b
%define modsign_cmd %{SOURCE21}
44a40b
44a40b
%if 0%{?include_rhel}
44a40b
Source23: x509.genkey.rhel
44a40b
44a40b
Source24: kernel-aarch64-rhel.config
44a40b
Source25: kernel-aarch64-debug-rhel.config
44a40b
Source26: mod-extra.list.rhel
44a40b
44a40b
Source27: kernel-ppc64le-rhel.config
44a40b
Source28: kernel-ppc64le-debug-rhel.config
44a40b
Source29: kernel-s390x-rhel.config
44a40b
Source30: kernel-s390x-debug-rhel.config
44a40b
Source31: kernel-s390x-zfcpdump-rhel.config
44a40b
Source32: kernel-x86_64-rhel.config
44a40b
Source33: kernel-x86_64-debug-rhel.config
44a40b
44a40b
Source34: filter-x86_64.sh.rhel
44a40b
Source35: filter-armv7hl.sh.rhel
44a40b
Source36: filter-i686.sh.rhel
44a40b
Source37: filter-aarch64.sh.rhel
44a40b
Source38: filter-ppc64le.sh.rhel
44a40b
Source39: filter-s390x.sh.rhel
44a40b
Source40: filter-modules.sh.rhel
44a40b
%endif
44a40b
44a40b
%if 0%{?include_fedora}
44a40b
Source50: x509.genkey.fedora
44a40b
Source51: mod-extra.list.fedora
44a40b
44a40b
Source52: kernel-aarch64-fedora.config
44a40b
Source53: kernel-aarch64-debug-fedora.config
44a40b
Source54: kernel-armv7hl-fedora.config
44a40b
Source55: kernel-armv7hl-debug-fedora.config
44a40b
Source56: kernel-armv7hl-lpae-fedora.config
44a40b
Source57: kernel-armv7hl-lpae-debug-fedora.config
44a40b
Source58: kernel-i686-fedora.config
44a40b
Source59: kernel-i686-debug-fedora.config
44a40b
Source60: kernel-ppc64le-fedora.config
44a40b
Source61: kernel-ppc64le-debug-fedora.config
44a40b
Source62: kernel-s390x-fedora.config
44a40b
Source63: kernel-s390x-debug-fedora.config
44a40b
Source64: kernel-x86_64-fedora.config
44a40b
Source65: kernel-x86_64-debug-fedora.config
44a40b
44a40b
Source67: filter-x86_64.sh.fedora
44a40b
Source68: filter-armv7hl.sh.fedora
44a40b
Source69: filter-i686.sh.fedora
44a40b
Source70: filter-aarch64.sh.fedora
44a40b
Source71: filter-ppc64le.sh.fedora
44a40b
Source72: filter-s390x.sh.fedora
44a40b
Source73: filter-modules.sh.fedora
44a40b
%endif
44a40b
44a40b
Source75: partial-kgcov-snip.config
44a40b
Source80: generate_all_configs.sh
44a40b
Source81: process_configs.sh
44a40b
44a40b
Source82: update_scripts.sh
44a40b
44a40b
Source84: mod-internal.list
44a40b
44a40b
Source100: rheldup3.x509
44a40b
Source101: rhelkpatch1.x509
44a40b
44a40b
Source200: check-kabi
44a40b
44a40b
Source201: Module.kabi_aarch64
44a40b
Source202: Module.kabi_ppc64le
44a40b
Source203: Module.kabi_s390x
44a40b
Source204: Module.kabi_x86_64
44a40b
44a40b
Source210: Module.kabi_dup_aarch64
44a40b
Source211: Module.kabi_dup_ppc64le
44a40b
Source212: Module.kabi_dup_s390x
44a40b
Source213: Module.kabi_dup_x86_64
44a40b
44a40b
Source300: kernel-abi-stablelists-%{rpmversion}-%{pkgrelease}.tar.bz2
44a40b
Source301: kernel-kabi-dw-%{rpmversion}-%{pkgrelease}.tar.bz2
44a40b
44a40b
# Sources for kernel-tools
44a40b
Source2000: cpupower.service
44a40b
Source2001: cpupower.config
44a40b
Source2002: kvm_stat.logrotate
44a40b
44a40b
# Some people enjoy building customized kernels from the dist-git in Fedora and
44a40b
# use this to override configuration options. One day they may all use the
44a40b
# source tree, but in the mean time we carry this to support the legacy workflow
44a40b
Source3000: merge.pl
44a40b
Source3001: kernel-local
44a40b
44a40b
Source4000: README.rst
44a40b
Source4001: rpminspect.yaml
44a40b
Source4002: gating.yaml
44a40b
44a40b
## Patches needed for building this package
44a40b
44a40b
%if !%{nopatches}
44a40b
44a40b
Patch1: patch-%{rpmversion}-redhat.patch
44a40b
%endif
44a40b
44a40b
# empty final patch to facilitate testing of kernel patches
44a40b
Patch999999: linux-kernel-test.patch
44a40b
44a40b
# END OF PATCH DEFINITIONS
44a40b
44a40b
%description
44a40b
The kernel meta package
44a40b
44a40b
#
44a40b
# This macro does requires, provides, conflicts, obsoletes for a kernel package.
44a40b
#	%%kernel_reqprovconf <subpackage>
44a40b
# It uses any kernel_<subpackage>_conflicts and kernel_<subpackage>_obsoletes
44a40b
# macros defined above.
44a40b
#
44a40b
%define kernel_reqprovconf \
44a40b
Provides: kernel = %{rpmversion}-%{pkg_release}\
44a40b
Provides: kernel-%{_target_cpu} = %{rpmversion}-%{pkg_release}%{?1:+%{1}}\
44a40b
Provides: kernel-drm-nouveau = 16\
44a40b
Provides: kernel-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
Requires(pre): %{kernel_prereq}\
44a40b
Requires(pre): %{initrd_prereq}\
44a40b
Requires(pre): ((linux-firmware >= 20150904-56.git6ebf5d57) if linux-firmware)\
44a40b
Recommends: linux-firmware\
44a40b
Requires(preun): systemd >= 200\
44a40b
Conflicts: xfsprogs < 4.3.0-1\
44a40b
Conflicts: xorg-x11-drv-vmmouse < 13.0.99\
44a40b
%{expand:%%{?kernel%{?1:_%{1}}_conflicts:Conflicts: %%{kernel%{?1:_%{1}}_conflicts}}}\
44a40b
%{expand:%%{?kernel%{?1:_%{1}}_obsoletes:Obsoletes: %%{kernel%{?1:_%{1}}_obsoletes}}}\
44a40b
%{expand:%%{?kernel%{?1:_%{1}}_provides:Provides: %%{kernel%{?1:_%{1}}_provides}}}\
44a40b
# We can't let RPM do the dependencies automatic because it'll then pick up\
44a40b
# a correct but undesirable perl dependency from the module headers which\
44a40b
# isn't required for the kernel proper to function\
44a40b
AutoReq: no\
44a40b
AutoProv: yes\
44a40b
%{nil}
44a40b
44a40b
44a40b
%package doc
44a40b
Summary: Various documentation bits found in the kernel source
44a40b
Group: Documentation
44a40b
%description doc
44a40b
This package contains documentation files from the kernel
44a40b
source. Various bits of information about the Linux kernel and the
44a40b
device drivers shipped with it are documented in these files.
44a40b
44a40b
You'll want to install this package if you need a reference to the
44a40b
options that can be passed to Linux kernel modules at load time.
44a40b
44a40b
44a40b
%package headers
44a40b
Summary: Header files for the Linux kernel for use by glibc
44a40b
Obsoletes: glibc-kernheaders < 3.0-46
44a40b
Provides: glibc-kernheaders = 3.0-46
44a40b
%description headers
44a40b
Kernel-headers includes the C header files that specify the interface
44a40b
between the Linux kernel and userspace libraries and programs.  The
44a40b
header files define structures and constants that are needed for
44a40b
building most standard programs and are also needed for rebuilding the
44a40b
glibc package.
44a40b
44a40b
%package cross-headers
44a40b
Summary: Header files for the Linux kernel for use by cross-glibc
44a40b
%description cross-headers
44a40b
Kernel-cross-headers includes the C header files that specify the interface
44a40b
between the Linux kernel and userspace libraries and programs.  The
44a40b
header files define structures and constants that are needed for
44a40b
building most standard programs and are also needed for rebuilding the
44a40b
cross-glibc package.
44a40b
44a40b
44a40b
%package debuginfo-common-%{_target_cpu}
44a40b
Summary: Kernel source files used by %{name}-debuginfo packages
44a40b
Provides: installonlypkg(kernel)
44a40b
%description debuginfo-common-%{_target_cpu}
44a40b
This package is required by %{name}-debuginfo subpackages.
44a40b
It provides the kernel source files common to all builds.
44a40b
44a40b
%if %{with_perf}
44a40b
%package -n perf
44a40b
Summary: Performance monitoring for the Linux kernel
44a40b
Requires: bzip2
44a40b
License: GPLv2
44a40b
%description -n perf
44a40b
This package contains the perf tool, which enables performance monitoring
44a40b
of the Linux kernel.
44a40b
44a40b
%package -n perf-debuginfo
44a40b
Summary: Debug information for package perf
44a40b
Requires: %{name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
44a40b
AutoReqProv: no
44a40b
%description -n perf-debuginfo
44a40b
This package provides debug information for the perf package.
44a40b
44a40b
# Note that this pattern only works right to match the .build-id
44a40b
# symlinks because of the trailing nonmatching alternation and
44a40b
# the leading .*, because of find-debuginfo.sh's buggy handling
44a40b
# of matching the pattern against the symlinks file.
44a40b
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%%{_bindir}/perf(\.debug)?|.*%%{_libexecdir}/perf-core/.*|.*%%{_libdir}/libperf-jvmti.so(\.debug)?|XXX' -o perf-debuginfo.list}
44a40b
44a40b
%package -n python3-perf
44a40b
Summary: Python bindings for apps which will manipulate perf events
44a40b
%description -n python3-perf
44a40b
The python3-perf package contains a module that permits applications
44a40b
written in the Python programming language to use the interface
44a40b
to manipulate perf events.
44a40b
44a40b
%package -n python3-perf-debuginfo
44a40b
Summary: Debug information for package perf python bindings
44a40b
Requires: %{name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
44a40b
AutoReqProv: no
44a40b
%description -n python3-perf-debuginfo
44a40b
This package provides debug information for the perf python bindings.
44a40b
44a40b
# the python_sitearch macro should already be defined from above
44a40b
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%%{python3_sitearch}/perf.*so(\.debug)?|XXX' -o python3-perf-debuginfo.list}
44a40b
44a40b
# with_perf
44a40b
%endif
44a40b
44a40b
%if %{with_tools}
44a40b
%package -n kernel-tools
44a40b
Summary: Assortment of tools for the Linux kernel
44a40b
License: GPLv2
44a40b
%ifarch %{cpupowerarchs}
44a40b
Provides:  cpupowerutils = 1:009-0.6.p1
44a40b
Obsoletes: cpupowerutils < 1:009-0.6.p1
44a40b
Provides:  cpufreq-utils = 1:009-0.6.p1
44a40b
Provides:  cpufrequtils = 1:009-0.6.p1
44a40b
Obsoletes: cpufreq-utils < 1:009-0.6.p1
44a40b
Obsoletes: cpufrequtils < 1:009-0.6.p1
44a40b
Obsoletes: cpuspeed < 1:1.5-16
44a40b
Requires: kernel-tools-libs = %{version}-%{release}
44a40b
%endif
44a40b
%define __requires_exclude ^%{_bindir}/python
44a40b
%description -n kernel-tools
44a40b
This package contains the tools/ directory from the kernel source
44a40b
and the supporting documentation.
44a40b
44a40b
%package -n kernel-tools-libs
44a40b
Summary: Libraries for the kernels-tools
44a40b
License: GPLv2
44a40b
%description -n kernel-tools-libs
44a40b
This package contains the libraries built from the tools/ directory
44a40b
from the kernel source.
44a40b
44a40b
%package -n kernel-tools-libs-devel
44a40b
Summary: Assortment of tools for the Linux kernel
44a40b
License: GPLv2
44a40b
Requires: kernel-tools = %{version}-%{release}
44a40b
%ifarch %{cpupowerarchs}
44a40b
Provides:  cpupowerutils-devel = 1:009-0.6.p1
44a40b
Obsoletes: cpupowerutils-devel < 1:009-0.6.p1
44a40b
%endif
44a40b
Requires: kernel-tools-libs = %{version}-%{release}
44a40b
Provides: kernel-tools-devel
44a40b
%description -n kernel-tools-libs-devel
44a40b
This package contains the development files for the tools/ directory from
44a40b
the kernel source.
44a40b
44a40b
%package -n kernel-tools-debuginfo
44a40b
Summary: Debug information for package kernel-tools
44a40b
Requires: %{name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
44a40b
AutoReqProv: no
44a40b
%description -n kernel-tools-debuginfo
44a40b
This package provides debug information for package kernel-tools.
44a40b
44a40b
# Note that this pattern only works right to match the .build-id
44a40b
# symlinks because of the trailing nonmatching alternation and
44a40b
# the leading .*, because of find-debuginfo.sh's buggy handling
44a40b
# of matching the pattern against the symlinks file.
44a40b
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%%{_bindir}/centrino-decode(\.debug)?|.*%%{_bindir}/powernow-k8-decode(\.debug)?|.*%%{_bindir}/cpupower(\.debug)?|.*%%{_libdir}/libcpupower.*|.*%%{_bindir}/turbostat(\.debug)?|.*%%{_bindir}/x86_energy_perf_policy(\.debug)?|.*%%{_bindir}/tmon(\.debug)?|.*%%{_bindir}/lsgpio(\.debug)?|.*%%{_bindir}/gpio-hammer(\.debug)?|.*%%{_bindir}/gpio-event-mon(\.debug)?|.*%%{_bindir}/gpio-watch(\.debug)?|.*%%{_bindir}/iio_event_monitor(\.debug)?|.*%%{_bindir}/iio_generic_buffer(\.debug)?|.*%%{_bindir}/lsiio(\.debug)?|.*%%{_bindir}/intel-speed-select(\.debug)?|.*%%{_bindir}/page_owner_sort(\.debug)?|.*%%{_bindir}/slabinfo(\.debug)?|XXX' -o kernel-tools-debuginfo.list}
44a40b
44a40b
# with_tools
44a40b
%endif
44a40b
44a40b
%if %{with_bpftool}
44a40b
44a40b
%package -n bpftool
44a40b
Summary: Inspection and simple manipulation of eBPF programs and maps
44a40b
License: GPLv2
44a40b
%description -n bpftool
44a40b
This package contains the bpftool, which allows inspection and simple
44a40b
manipulation of eBPF programs and maps.
44a40b
44a40b
%package -n bpftool-debuginfo
44a40b
Summary: Debug information for package bpftool
44a40b
Group: Development/Debug
44a40b
Requires: %{name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
44a40b
AutoReqProv: no
44a40b
%description -n bpftool-debuginfo
44a40b
This package provides debug information for the bpftool package.
44a40b
44a40b
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%%{_sbindir}/bpftool(\.debug)?|XXX' -o bpftool-debuginfo.list}
44a40b
44a40b
# with_bpftool
44a40b
%endif
44a40b
44a40b
%if %{with_selftests}
44a40b
44a40b
%package selftests-internal
44a40b
Summary: Kernel samples and selftests
44a40b
License: GPLv2
44a40b
Requires: binutils, bpftool, iproute-tc, nmap-ncat, python3, fuse-libs
44a40b
%description selftests-internal
44a40b
Kernel sample programs and selftests.
44a40b
44a40b
# Note that this pattern only works right to match the .build-id
44a40b
# symlinks because of the trailing nonmatching alternation and
44a40b
# the leading .*, because of find-debuginfo.sh's buggy handling
44a40b
# of matching the pattern against the symlinks file.
44a40b
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%%{_libexecdir}/(ksamples|kselftests)/.*|XXX' -o selftests-debuginfo.list}
44a40b
44a40b
# with_selftests
44a40b
%endif
44a40b
44a40b
%if %{with_gcov}
44a40b
%package gcov
44a40b
Summary: gcov graph and source files for coverage data collection.
44a40b
%description gcov
44a40b
kernel-gcov includes the gcov graph and source files for gcov coverage collection.
44a40b
%endif
44a40b
44a40b
%package -n kernel-abi-stablelists
44a40b
Summary: The Red Hat Enterprise Linux kernel ABI symbol stablelists
44a40b
AutoReqProv: no
44a40b
%description -n kernel-abi-stablelists
44a40b
The kABI package contains information pertaining to the Red Hat Enterprise
44a40b
Linux kernel ABI, including lists of kernel symbols that are needed by
44a40b
external Linux kernel modules, and a yum plugin to aid enforcement.
44a40b
44a40b
%if %{with_kabidw_base}
44a40b
%package kernel-kabidw-base-internal
44a40b
Summary: The baseline dataset for kABI verification using DWARF data
44a40b
Group: System Environment/Kernel
44a40b
AutoReqProv: no
44a40b
%description kernel-kabidw-base-internal
44a40b
The package contains data describing the current ABI of the Red Hat Enterprise
44a40b
Linux kernel, suitable for the kabi-dw tool.
44a40b
%endif
44a40b
44a40b
#
44a40b
# This macro creates a kernel-<subpackage>-debuginfo package.
44a40b
#	%%kernel_debuginfo_package <subpackage>
44a40b
#
44a40b
# Explanation of the find_debuginfo_opts: We build multiple kernels (debug
44a40b
# pae etc.) so the regex filters those kernels appropriately. We also
44a40b
# have to package several binaries as part of kernel-devel but getting
44a40b
# unique build-ids is tricky for these userspace binaries. We don't really
44a40b
# care about debugging those so we just filter those out and remove it.
44a40b
%define kernel_debuginfo_package() \
44a40b
%package %{?1:%{1}-}debuginfo\
44a40b
Summary: Debug information for package %{name}%{?1:-%{1}}\
44a40b
Requires: %{name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}\
44a40b
Provides: %{name}%{?1:-%{1}}-debuginfo-%{_target_cpu} = %{version}-%{release}\
44a40b
Provides: installonlypkg(kernel)\
44a40b
AutoReqProv: no\
44a40b
%description %{?1:%{1}-}debuginfo\
44a40b
This package provides debug information for package %{name}%{?1:-%{1}}.\
44a40b
This is required to use SystemTap with %{name}%{?1:-%{1}}-%{KVERREL}.\
44a40b
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*\/usr\/src\/kernels/.*|XXX' -o ignored-debuginfo.list -p '/.*/%%{KVERREL_RE}%{?1:[+]%{1}}/.*|/.*%%{KVERREL_RE}%{?1:\+%{1}}(\.debug)?' -o debuginfo%{?1}.list}\
44a40b
%{nil}
44a40b
44a40b
#
44a40b
# This macro creates a kernel-<subpackage>-devel package.
44a40b
#	%%kernel_devel_package [-m] <subpackage> <pretty-name>
44a40b
#
44a40b
%define kernel_devel_package(m) \
44a40b
%package %{?1:%{1}-}devel\
44a40b
Summary: Development package for building kernel modules to match the %{?2:%{2} }kernel\
44a40b
Provides: kernel%{?1:-%{1}}-devel-%{_target_cpu} = %{version}-%{release}\
44a40b
Provides: kernel-devel-%{_target_cpu} = %{version}-%{release}%{?1:+%{1}}\
44a40b
Provides: kernel-devel-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
Provides: installonlypkg(kernel)\
44a40b
AutoReqProv: no\
44a40b
Requires(pre): findutils\
44a40b
Requires: findutils\
44a40b
Requires: perl-interpreter\
44a40b
Requires: openssl-devel\
44a40b
Requires: elfutils-libelf-devel\
44a40b
Requires: bison\
44a40b
Requires: flex\
44a40b
Requires: make\
44a40b
Requires: gcc\
44a40b
%if %{-m:1}%{!-m:0}\
44a40b
Requires: kernel-devel-uname-r = %{KVERREL}\
44a40b
%endif\
44a40b
%description %{?1:%{1}-}devel\
44a40b
This package provides kernel headers and makefiles sufficient to build modules\
44a40b
against the %{?2:%{2} }kernel package.\
44a40b
%{nil}
44a40b
44a40b
#
44a40b
# This macro creates an empty kernel-<subpackage>-devel-matched package that
44a40b
# requires both the core and devel packages locked on the same version.
44a40b
#	%%kernel_devel_matched_package [-m] <subpackage> <pretty-name>
44a40b
#
44a40b
%define kernel_devel_matched_package(m) \
44a40b
%package %{?1:%{1}-}devel-matched\
44a40b
Summary: Meta package to install matching core and devel packages for a given %{?2:%{2} }kernel\
44a40b
Requires: kernel%{?1:-%{1}}-devel = %{version}-%{release}\
44a40b
Requires: kernel%{?1:-%{1}}-core = %{version}-%{release}\
44a40b
%description %{?1:%{1}-}devel-matched\
44a40b
This meta package is used to install matching core and devel packages for a given %{?2:%{2} }kernel.\
44a40b
%{nil}
44a40b
44a40b
#
44a40b
# kernel-<variant>-ipaclones-internal package
44a40b
#
44a40b
%define kernel_ipaclones_package() \
44a40b
%package %{?1:%{1}-}ipaclones-internal\
44a40b
Summary: *.ipa-clones files generated by -fdump-ipa-clones for kernel%{?1:-%{1}}\
44a40b
Group: System Environment/Kernel\
44a40b
AutoReqProv: no\
44a40b
%description %{?1:%{1}-}ipaclones-internal\
44a40b
This package provides *.ipa-clones files.\
44a40b
%{nil}
44a40b
44a40b
#
44a40b
# This macro creates a kernel-<subpackage>-modules-internal package.
44a40b
#	%%kernel_modules_internal_package <subpackage> <pretty-name>
44a40b
#
44a40b
%define kernel_modules_internal_package() \
44a40b
%package %{?1:%{1}-}modules-internal\
44a40b
Summary: Extra kernel modules to match the %{?2:%{2} }kernel\
44a40b
Group: System Environment/Kernel\
44a40b
Provides: kernel%{?1:-%{1}}-modules-internal-%{_target_cpu} = %{version}-%{release}\
44a40b
Provides: kernel%{?1:-%{1}}-modules-internal-%{_target_cpu} = %{version}-%{release}%{?1:+%{1}}\
44a40b
Provides: kernel%{?1:-%{1}}-modules-internal = %{version}-%{release}%{?1:+%{1}}\
44a40b
Provides: installonlypkg(kernel-module)\
44a40b
Provides: kernel%{?1:-%{1}}-modules-internal-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
Requires: kernel-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
Requires: kernel%{?1:-%{1}}-modules-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
AutoReq: no\
44a40b
AutoProv: yes\
44a40b
%description %{?1:%{1}-}modules-internal\
44a40b
This package provides kernel modules for the %{?2:%{2} }kernel package for Red Hat internal usage.\
44a40b
%{nil}
44a40b
44a40b
#
44a40b
# This macro creates a kernel-<subpackage>-modules-extra package.
44a40b
#	%%kernel_modules_extra_package [-m] <subpackage> <pretty-name>
44a40b
#
44a40b
%define kernel_modules_extra_package(m) \
44a40b
%package %{?1:%{1}-}modules-extra\
44a40b
Summary: Extra kernel modules to match the %{?2:%{2} }kernel\
44a40b
Provides: kernel%{?1:-%{1}}-modules-extra-%{_target_cpu} = %{version}-%{release}\
44a40b
Provides: kernel%{?1:-%{1}}-modules-extra-%{_target_cpu} = %{version}-%{release}%{?1:+%{1}}\
44a40b
Provides: kernel%{?1:-%{1}}-modules-extra = %{version}-%{release}%{?1:+%{1}}\
44a40b
Provides: installonlypkg(kernel-module)\
44a40b
Provides: kernel%{?1:-%{1}}-modules-extra-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
Requires: kernel-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
Requires: kernel%{?1:-%{1}}-modules-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
%if %{-m:1}%{!-m:0}\
44a40b
Requires: kernel-modules-extra-uname-r = %{KVERREL}\
44a40b
%endif\
44a40b
AutoReq: no\
44a40b
AutoProv: yes\
44a40b
%description %{?1:%{1}-}modules-extra\
44a40b
This package provides less commonly used kernel modules for the %{?2:%{2} }kernel package.\
44a40b
%{nil}
44a40b
44a40b
#
44a40b
# This macro creates a kernel-<subpackage>-modules package.
44a40b
#	%%kernel_modules_package [-m] <subpackage> <pretty-name>
44a40b
#
44a40b
%define kernel_modules_package(m) \
44a40b
%package %{?1:%{1}-}modules\
44a40b
Summary: kernel modules to match the %{?2:%{2}-}core kernel\
44a40b
Provides: kernel%{?1:-%{1}}-modules-%{_target_cpu} = %{version}-%{release}\
44a40b
Provides: kernel-modules-%{_target_cpu} = %{version}-%{release}%{?1:+%{1}}\
44a40b
Provides: kernel-modules = %{version}-%{release}%{?1:+%{1}}\
44a40b
Provides: installonlypkg(kernel-module)\
44a40b
Provides: kernel%{?1:-%{1}}-modules-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
Requires: kernel-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
%if %{-m:1}%{!-m:0}\
44a40b
Requires: kernel-modules-uname-r = %{KVERREL}\
44a40b
%endif\
44a40b
AutoReq: no\
44a40b
AutoProv: yes\
44a40b
%description %{?1:%{1}-}modules\
44a40b
This package provides commonly used kernel modules for the %{?2:%{2}-}core kernel package.\
44a40b
%{nil}
44a40b
44a40b
#
44a40b
# this macro creates a kernel-<subpackage> meta package.
44a40b
#	%%kernel_meta_package <subpackage>
44a40b
#
44a40b
%define kernel_meta_package() \
44a40b
%package %{1}\
44a40b
summary: kernel meta-package for the %{1} kernel\
44a40b
Requires: kernel-%{1}-core-uname-r = %{KVERREL}+%{1}\
44a40b
Requires: kernel-%{1}-modules-uname-r = %{KVERREL}+%{1}\
44a40b
Provides: installonlypkg(kernel)\
44a40b
%description %{1}\
44a40b
The meta-package for the %{1} kernel\
44a40b
%{nil}
44a40b
44a40b
#
44a40b
# This macro creates a kernel-<subpackage> and its -devel and -debuginfo too.
44a40b
#	%%define variant_summary The Linux kernel compiled for <configuration>
44a40b
#	%%kernel_variant_package [-n <pretty-name>] [-m] <subpackage>
44a40b
#
44a40b
%define kernel_variant_package(n:m) \
44a40b
%package %{?1:%{1}-}core\
44a40b
Summary: %{variant_summary}\
44a40b
Provides: kernel-%{?1:%{1}-}core-uname-r = %{KVERREL}%{?1:+%{1}}\
44a40b
Provides: installonlypkg(kernel)\
44a40b
%if %{-m:1}%{!-m:0}\
44a40b
Requires: kernel-core-uname-r = %{KVERREL}\
44a40b
%endif\
44a40b
%{expand:%%kernel_reqprovconf}\
44a40b
%if %{?1:1} %{!?1:0} \
44a40b
%{expand:%%kernel_meta_package %{?1:%{1}}}\
44a40b
%endif\
44a40b
%{expand:%%kernel_devel_package %{?1:%{1}} %{!?{-n}:%{1}}%{?{-n}:%{-n*}} %{-m:%{-m}}}\
44a40b
%{expand:%%kernel_devel_matched_package %{?1:%{1}} %{!?{-n}:%{1}}%{?{-n}:%{-n*}} %{-m:%{-m}}}\
44a40b
%{expand:%%kernel_modules_package %{?1:%{1}} %{!?{-n}:%{1}}%{?{-n}:%{-n*}} %{-m:%{-m}}}\
44a40b
%{expand:%%kernel_modules_extra_package %{?1:%{1}} %{!?{-n}:%{1}}%{?{-n}:%{-n*}} %{-m:%{-m}}}\
44a40b
%if %{-m:0}%{!-m:1}\
44a40b
%{expand:%%kernel_modules_internal_package %{?1:%{1}} %{!?{-n}:%{1}}%{?{-n}:%{-n*}}}\
44a40b
%{expand:%%kernel_debuginfo_package %{?1:%{1}}}\
44a40b
%endif\
44a40b
%{nil}
44a40b
44a40b
# Now, each variant package.
44a40b
44a40b
%if %{with_pae}
44a40b
%define variant_summary The Linux kernel compiled for Cortex-A15
44a40b
%kernel_variant_package lpae
44a40b
%description lpae-core
44a40b
This package includes a version of the Linux kernel with support for
44a40b
Cortex-A15 devices with LPAE and HW virtualisation support
44a40b
%endif
44a40b
44a40b
%if %{with_zfcpdump}
44a40b
%define variant_summary The Linux kernel compiled for zfcpdump usage
44a40b
%kernel_variant_package zfcpdump
44a40b
%description zfcpdump-core
44a40b
The kernel package contains the Linux kernel (vmlinuz) for use by the
44a40b
zfcpdump infrastructure.
44a40b
# with_zfcpdump
44a40b
%endif
44a40b
44a40b
%define variant_summary The Linux kernel compiled with extra debugging enabled
44a40b
%if !%{debugbuildsenabled}
44a40b
%kernel_variant_package -m debug
44a40b
%else
44a40b
%kernel_variant_package debug
44a40b
%endif
44a40b
%description debug-core
44a40b
The kernel package contains the Linux kernel (vmlinuz), the core of any
44a40b
Linux operating system.  The kernel handles the basic functions
44a40b
of the operating system:  memory allocation, process allocation, device
44a40b
input and output, etc.
44a40b
44a40b
This variant of the kernel has numerous debugging options enabled.
44a40b
It should only be installed when trying to gather additional information
44a40b
on kernel bugs, as some of these options impact performance noticably.
44a40b
44a40b
# And finally the main -core package
44a40b
44a40b
%define variant_summary The Linux kernel
44a40b
%kernel_variant_package
44a40b
%description core
44a40b
The kernel package contains the Linux kernel (vmlinuz), the core of any
44a40b
Linux operating system.  The kernel handles the basic functions
44a40b
of the operating system: memory allocation, process allocation, device
44a40b
input and output, etc.
44a40b
44a40b
%if %{with_ipaclones}
44a40b
%kernel_ipaclones_package
44a40b
%endif
44a40b
44a40b
%prep
44a40b
# do a few sanity-checks for --with *only builds
44a40b
%if %{with_baseonly}
44a40b
%if !%{with_up}
44a40b
echo "Cannot build --with baseonly, up build is disabled"
44a40b
exit 1
44a40b
%endif
44a40b
%endif
44a40b
44a40b
# more sanity checking; do it quietly
44a40b
if [ "%{patches}" != "%%{patches}" ] ; then
44a40b
  for patch in %{patches} ; do
44a40b
    if [ ! -f $patch ] ; then
44a40b
      echo "ERROR: Patch  ${patch##/*/}  listed in specfile but is missing"
44a40b
      exit 1
44a40b
    fi
44a40b
  done
44a40b
fi 2>/dev/null
44a40b
44a40b
patch_command='patch -p1 -F1 -s'
44a40b
ApplyPatch()
44a40b
{
44a40b
  local patch=$1
44a40b
  shift
44a40b
  if [ ! -f $RPM_SOURCE_DIR/$patch ]; then
44a40b
    exit 1
44a40b
  fi
44a40b
  if ! grep -E "^Patch[0-9]+: $patch\$" %{_specdir}/${RPM_PACKAGE_NAME}.spec ; then
44a40b
    if [ "${patch:0:8}" != "patch-5." ] ; then
44a40b
      echo "ERROR: Patch  $patch  not listed as a source patch in specfile"
44a40b
      exit 1
44a40b
    fi
44a40b
  fi 2>/dev/null
44a40b
  case "$patch" in
44a40b
  *.bz2) bunzip2 < "$RPM_SOURCE_DIR/$patch" | $patch_command ${1+"$@"} ;;
44a40b
  *.gz)  gunzip  < "$RPM_SOURCE_DIR/$patch" | $patch_command ${1+"$@"} ;;
44a40b
  *.xz)  unxz    < "$RPM_SOURCE_DIR/$patch" | $patch_command ${1+"$@"} ;;
44a40b
  *) $patch_command ${1+"$@"} < "$RPM_SOURCE_DIR/$patch" ;;
44a40b
  esac
44a40b
}
44a40b
44a40b
# don't apply patch if it's empty
44a40b
ApplyOptionalPatch()
44a40b
{
44a40b
  local patch=$1
44a40b
  shift
44a40b
  if [ ! -f $RPM_SOURCE_DIR/$patch ]; then
44a40b
    exit 1
44a40b
  fi
44a40b
  local C=$(wc -l $RPM_SOURCE_DIR/$patch | awk '{print $1}')
44a40b
  if [ "$C" -gt 9 ]; then
44a40b
    ApplyPatch $patch ${1+"$@"}
44a40b
  fi
44a40b
}
44a40b
dc9f2b
%setup -q -n kernel-5.14.0-70.22.1.el9_0 -c
dc9f2b
mv linux-5.14.0-70.22.1.el9_0 linux-%{KVERREL}
44a40b
44a40b
cd linux-%{KVERREL}
44a40b
cp -a %{SOURCE1} .
44a40b
44a40b
%if !%{nopatches}
44a40b
44a40b
ApplyOptionalPatch patch-%{rpmversion}-redhat.patch
44a40b
%endif
44a40b
44a40b
ApplyOptionalPatch linux-kernel-test.patch
44a40b
44a40b
# END OF PATCH APPLICATIONS
44a40b
44a40b
# Any further pre-build tree manipulations happen here.
44a40b
44a40b
chmod +x scripts/checkpatch.pl
44a40b
mv COPYING COPYING-%{version}-%{release}
44a40b
44a40b
# This Prevents scripts/setlocalversion from mucking with our version numbers.
44a40b
touch .scmversion
44a40b
44a40b
# Mangle /usr/bin/python shebangs to /usr/bin/python3
44a40b
# Mangle all Python shebangs to be Python 3 explicitly
44a40b
# -p preserves timestamps
44a40b
# -n prevents creating ~backup files
44a40b
# -i specifies the interpreter for the shebang
44a40b
# This fixes errors such as
44a40b
# *** ERROR: ambiguous python shebang in /usr/bin/kvm_stat: #!/usr/bin/python. Change it to python3 (or python2) explicitly.
44a40b
# We patch all sources below for which we got a report/error.
44a40b
pathfix.py -i "%{__python3} %{py3_shbang_opts}" -p -n \
44a40b
	tools/kvm/kvm_stat/kvm_stat \
44a40b
	scripts/show_delta \
44a40b
	scripts/diffconfig \
44a40b
	scripts/bloat-o-meter \
44a40b
	scripts/jobserver-exec \
44a40b
	tools \
44a40b
	Documentation \
44a40b
	scripts/clang-tools
44a40b
44a40b
# only deal with configs if we are going to build for the arch
44a40b
%ifnarch %nobuildarches
44a40b
44a40b
if [ -L configs ]; then
44a40b
	rm -f configs
44a40b
fi
44a40b
mkdir configs
44a40b
cd configs
44a40b
44a40b
# Drop some necessary files from the source dir into the buildroot
44a40b
cp $RPM_SOURCE_DIR/kernel-*.config .
44a40b
cp %{SOURCE80} .
44a40b
# merge.pl
44a40b
cp %{SOURCE3000} .
44a40b
# kernel-local
44a40b
cp %{SOURCE3001} .
44a40b
VERSION=%{version} ./generate_all_configs.sh %{primary_target} %{debugbuildsenabled}
44a40b
44a40b
# Merge in any user-provided local config option changes
44a40b
%ifnarch %nobuildarches
44a40b
for i in %{all_arch_configs}
44a40b
do
44a40b
  mv $i $i.tmp
44a40b
  ./merge.pl %{SOURCE3001} $i.tmp > $i
44a40b
%if %{with_gcov}
44a40b
  echo "Merging with gcov options"
44a40b
  cat %{SOURCE75}
44a40b
  mv $i $i.tmp
44a40b
  ./merge.pl %{SOURCE75} $i.tmp > $i
44a40b
%endif
44a40b
  rm $i.tmp
44a40b
done
44a40b
%endif
44a40b
44a40b
%if %{with clang_lto}
44a40b
for i in *aarch64*.config *x86_64*.config; do
44a40b
  sed -i 's/# CONFIG_LTO_CLANG_THIN is not set/CONFIG_LTO_CLANG_THIN=y/' $i
44a40b
  sed -i 's/CONFIG_LTO_NONE=y/# CONFIG_LTO_NONE is not set/' $i
44a40b
done
44a40b
%endif
44a40b
44a40b
# Add DUP and kpatch certificates to system trusted keys for RHEL
44a40b
%if 0%{?rhel}
44a40b
%if %{signkernel}%{signmodules}
44a40b
openssl x509 -inform der -in %{SOURCE100} -out rheldup3.pem
44a40b
openssl x509 -inform der -in %{SOURCE101} -out rhelkpatch1.pem
44a40b
cat rheldup3.pem rhelkpatch1.pem > ../certs/rhel.pem
44a40b
%if %{signkernel}
44a40b
%ifarch s390x ppc64le
44a40b
openssl x509 -inform der -in %{secureboot_ca_0} -out secureboot.pem
44a40b
cat secureboot.pem >> ../certs/rhel.pem
44a40b
%endif
44a40b
%endif
44a40b
for i in *.config; do
44a40b
  sed -i 's@CONFIG_SYSTEM_TRUSTED_KEYS=""@CONFIG_SYSTEM_TRUSTED_KEYS="certs/rhel.pem"@' $i
44a40b
done
44a40b
%endif
44a40b
%endif
44a40b
dc9f2b
# Adjust FIPS module name for RHEL
dc9f2b
%if 0%{?rhel}
dc9f2b
for i in *.config; do
dc9f2b
  sed -i 's/CONFIG_CRYPTO_FIPS_NAME=.*/CONFIG_CRYPTO_FIPS_NAME="Red Hat Enterprise Linux %{rhel} - Kernel Cryptographic API"/' $i
dc9f2b
done
dc9f2b
%endif
dc9f2b
44a40b
cp %{SOURCE81} .
44a40b
OPTS=""
44a40b
%if %{with_configchecks}
44a40b
	OPTS="$OPTS -w -n -c"
44a40b
%endif
44a40b
%if %{with clang_lto}
44a40b
for opt in %{clang_make_opts}; do
44a40b
  OPTS="$OPTS -m $opt"
44a40b
done
44a40b
%endif
44a40b
./process_configs.sh $OPTS kernel %{rpmversion}
44a40b
44a40b
cp %{SOURCE82} .
44a40b
RPM_SOURCE_DIR=$RPM_SOURCE_DIR ./update_scripts.sh %{primary_target}
44a40b
44a40b
# end of kernel config
44a40b
%endif
44a40b
44a40b
cd ..
44a40b
# # End of Configs stuff
44a40b
44a40b
# get rid of unwanted files resulting from patch fuzz
44a40b
find . \( -name "*.orig" -o -name "*~" \) -delete >/dev/null
44a40b
44a40b
# remove unnecessary SCM files
44a40b
find . -name .gitignore -delete >/dev/null
44a40b
44a40b
cd ..
44a40b
44a40b
###
44a40b
### build
44a40b
###
44a40b
%build
44a40b
44a40b
%if %{with_sparse}
44a40b
%define sparse_mflags	C=1
44a40b
%endif
44a40b
44a40b
cp_vmlinux()
44a40b
{
44a40b
  eu-strip --remove-comment -o "$2" "$1"
44a40b
}
44a40b
44a40b
# Note we need to disable these flags for cross builds because the flags
44a40b
# from redhat-rpm-config assume that host == target so target arch
44a40b
# flags cause issues with the host compiler.
44a40b
%if !%{with_cross}
44a40b
%define build_hostcflags  %{?build_cflags}
44a40b
%define build_hostldflags %{?build_ldflags}
44a40b
%endif
44a40b
44a40b
%define make %{__make} %{?cross_opts} %{?make_opts} HOSTCFLAGS="%{?build_hostcflags}" HOSTLDFLAGS="%{?build_hostldflags}"
44a40b
44a40b
InitBuildVars() {
44a40b
    # Initialize the kernel .config file and create some variables that are
44a40b
    # needed for the actual build process.
44a40b
44a40b
    Variant=$1
44a40b
44a40b
    # Pick the right kernel config file
44a40b
    Config=kernel-%{version}-%{_target_cpu}${Variant:+-${Variant}}.config
44a40b
    DevelDir=/usr/src/kernels/%{KVERREL}${Variant:++${Variant}}
44a40b
44a40b
    KernelVer=%{version}-%{release}.%{_target_cpu}${Variant:++${Variant}}
44a40b
44a40b
    # make sure EXTRAVERSION says what we want it to say
44a40b
    # Trim the release if this is a CI build, since KERNELVERSION is limited to 64 characters
44a40b
    ShortRel=$(perl -e "print \"%{release}\" =~ s/\.pr\.[0-9A-Fa-f]{32}//r")
44a40b
    perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${ShortRel}.%{_target_cpu}${Variant:++${Variant}}/" Makefile
44a40b
44a40b
    # if pre-rc1 devel kernel, must fix up PATCHLEVEL for our versioning scheme
44a40b
    # if we are post rc1 this should match anyway so this won't matter
44a40b
    perl -p -i -e 's/^PATCHLEVEL.*/PATCHLEVEL = %{patchlevel}/' Makefile
44a40b
44a40b
    %{make} %{?_smp_mflags} mrproper
44a40b
    cp configs/$Config .config
44a40b
44a40b
    %if %{signkernel}%{signmodules}
44a40b
    cp $RPM_SOURCE_DIR/x509.genkey certs/.
44a40b
    %endif
44a40b
44a40b
    Arch=`head -1 .config | cut -b 3-`
44a40b
    echo USING ARCH=$Arch
44a40b
44a40b
    KCFLAGS="%{?kcflags}"
44a40b
44a40b
    # add kpatch flags for base kernel
44a40b
    if [ "$Variant" == "" ]; then
44a40b
        KCFLAGS="$KCFLAGS %{?kpatch_kcflags}"
44a40b
    fi
44a40b
}
44a40b
44a40b
BuildKernel() {
44a40b
    MakeTarget=$1
44a40b
    KernelImage=$2
44a40b
    DoVDSO=$3
44a40b
    Variant=$4
44a40b
    InstallName=${5:-vmlinuz}
44a40b
44a40b
    DoModules=1
44a40b
    if [ "$Variant" = "zfcpdump" ]; then
44a40b
	    DoModules=0
44a40b
    fi
44a40b
44a40b
    # When the bootable image is just the ELF kernel, strip it.
44a40b
    # We already copy the unstripped file into the debuginfo package.
44a40b
    if [ "$KernelImage" = vmlinux ]; then
44a40b
      CopyKernel=cp_vmlinux
44a40b
    else
44a40b
      CopyKernel=cp
44a40b
    fi
44a40b
44a40b
    InitBuildVars $Variant
44a40b
44a40b
    echo BUILDING A KERNEL FOR ${Variant} %{_target_cpu}...
44a40b
44a40b
    %{make} ARCH=$Arch olddefconfig >/dev/null
44a40b
44a40b
    # This ensures build-ids are unique to allow parallel debuginfo
44a40b
    perl -p -i -e "s/^CONFIG_BUILD_SALT.*/CONFIG_BUILD_SALT=\"%{KVERREL}\"/" .config
44a40b
    %{make} ARCH=$Arch KCFLAGS="$KCFLAGS" WITH_GCOV="%{?with_gcov}" %{?_smp_mflags} $MakeTarget %{?sparse_mflags} %{?kernel_mflags}
44a40b
    if [ $DoModules -eq 1 ]; then
44a40b
	%{make} ARCH=$Arch KCFLAGS="$KCFLAGS" WITH_GCOV="%{?with_gcov}" %{?_smp_mflags} modules %{?sparse_mflags} || exit 1
44a40b
    fi
44a40b
44a40b
    mkdir -p $RPM_BUILD_ROOT/%{image_install_path}
44a40b
    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer
44a40b
    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/systemtap
44a40b
%if %{with_debuginfo}
44a40b
    mkdir -p $RPM_BUILD_ROOT%{debuginfodir}/%{image_install_path}
44a40b
%endif
44a40b
44a40b
%ifarch %{arm} aarch64
44a40b
    %{make} ARCH=$Arch dtbs INSTALL_DTBS_PATH=$RPM_BUILD_ROOT/%{image_install_path}/dtb-$KernelVer
44a40b
    %{make} ARCH=$Arch dtbs_install INSTALL_DTBS_PATH=$RPM_BUILD_ROOT/%{image_install_path}/dtb-$KernelVer
44a40b
    cp -r $RPM_BUILD_ROOT/%{image_install_path}/dtb-$KernelVer $RPM_BUILD_ROOT/lib/modules/$KernelVer/dtb
44a40b
    find arch/$Arch/boot/dts -name '*.dtb' -type f -delete
44a40b
%endif
44a40b
44a40b
    # Start installing the results
44a40b
    install -m 644 .config $RPM_BUILD_ROOT/boot/config-$KernelVer
44a40b
    install -m 644 .config $RPM_BUILD_ROOT/lib/modules/$KernelVer/config
44a40b
    install -m 644 System.map $RPM_BUILD_ROOT/boot/System.map-$KernelVer
44a40b
    install -m 644 System.map $RPM_BUILD_ROOT/lib/modules/$KernelVer/System.map
44a40b
44a40b
    # We estimate the size of the initramfs because rpm needs to take this size
44a40b
    # into consideration when performing disk space calculations. (See bz #530778)
44a40b
    dd if=/dev/zero of=$RPM_BUILD_ROOT/boot/initramfs-$KernelVer.img bs=1M count=20
44a40b
44a40b
    if [ -f arch/$Arch/boot/zImage.stub ]; then
44a40b
      cp arch/$Arch/boot/zImage.stub $RPM_BUILD_ROOT/%{image_install_path}/zImage.stub-$KernelVer || :
44a40b
      cp arch/$Arch/boot/zImage.stub $RPM_BUILD_ROOT/lib/modules/$KernelVer/zImage.stub-$KernelVer || :
44a40b
    fi
44a40b
44a40b
    %if %{signkernel}
44a40b
    if [ "$KernelImage" = vmlinux ]; then
44a40b
        # We can't strip and sign $KernelImage in place, because
44a40b
        # we need to preserve original vmlinux for debuginfo.
44a40b
        # Use a copy for signing.
44a40b
        $CopyKernel $KernelImage $KernelImage.tosign
44a40b
        KernelImage=$KernelImage.tosign
44a40b
        CopyKernel=cp
44a40b
    fi
44a40b
44a40b
    # Sign the image if we're using EFI
44a40b
    # aarch64 kernels are gziped EFI images
44a40b
    KernelExtension=${KernelImage##*.}
44a40b
    if [ "$KernelExtension" == "gz" ]; then
44a40b
        SignImage=${KernelImage%.*}
44a40b
    else
44a40b
        SignImage=$KernelImage
44a40b
    fi
44a40b
44a40b
    %ifarch x86_64 aarch64
44a40b
    %pesign -s -i $SignImage -o vmlinuz.signed -a %{secureboot_ca_0} -c %{secureboot_key_0} -n %{pesign_name_0}
44a40b
    %endif
44a40b
    %ifarch s390x ppc64le
44a40b
    if [ -x /usr/bin/rpm-sign ]; then
44a40b
	rpm-sign --key "%{pesign_name_0}" --lkmsign $SignImage --output vmlinuz.signed
44a40b
    elif [ "$DoModules" == "1" -a "%{signmodules}" == "1" ]; then
44a40b
	chmod +x scripts/sign-file
44a40b
	./scripts/sign-file -p sha256 certs/signing_key.pem certs/signing_key.x509 $SignImage vmlinuz.signed
44a40b
    else
44a40b
	mv $SignImage vmlinuz.signed
44a40b
    fi
44a40b
    %endif
44a40b
44a40b
    if [ ! -s vmlinuz.signed ]; then
44a40b
        echo "pesigning failed"
44a40b
        exit 1
44a40b
    fi
44a40b
    mv vmlinuz.signed $SignImage
44a40b
    if [ "$KernelExtension" == "gz" ]; then
44a40b
        gzip -f9 $SignImage
44a40b
    fi
44a40b
    # signkernel
44a40b
    %endif
44a40b
44a40b
    $CopyKernel $KernelImage \
44a40b
                $RPM_BUILD_ROOT/%{image_install_path}/$InstallName-$KernelVer
44a40b
    chmod 755 $RPM_BUILD_ROOT/%{image_install_path}/$InstallName-$KernelVer
44a40b
    cp $RPM_BUILD_ROOT/%{image_install_path}/$InstallName-$KernelVer $RPM_BUILD_ROOT/lib/modules/$KernelVer/$InstallName
44a40b
44a40b
    # hmac sign the kernel for FIPS
44a40b
    echo "Creating hmac file: $RPM_BUILD_ROOT/%{image_install_path}/.vmlinuz-$KernelVer.hmac"
44a40b
    ls -l $RPM_BUILD_ROOT/%{image_install_path}/$InstallName-$KernelVer
44a40b
    sha512hmac $RPM_BUILD_ROOT/%{image_install_path}/$InstallName-$KernelVer | sed -e "s,$RPM_BUILD_ROOT,," > $RPM_BUILD_ROOT/%{image_install_path}/.vmlinuz-$KernelVer.hmac;
44a40b
    cp $RPM_BUILD_ROOT/%{image_install_path}/.vmlinuz-$KernelVer.hmac $RPM_BUILD_ROOT/lib/modules/$KernelVer/.vmlinuz.hmac
44a40b
44a40b
    if [ $DoModules -eq 1 ]; then
44a40b
	# Override $(mod-fw) because we don't want it to install any firmware
44a40b
	# we'll get it from the linux-firmware package and we don't want conflicts
44a40b
	%{make} %{?_smp_mflags} ARCH=$Arch INSTALL_MOD_PATH=$RPM_BUILD_ROOT %{?_smp_mflags} modules_install KERNELRELEASE=$KernelVer mod-fw=
44a40b
    fi
44a40b
44a40b
%if %{with_gcov}
44a40b
    # install gcov-needed files to $BUILDROOT/$BUILD/...:
44a40b
    #   gcov_info->filename is absolute path
44a40b
    #   gcno references to sources can use absolute paths (e.g. in out-of-tree builds)
44a40b
    #   sysfs symlink targets (set up at compile time) use absolute paths to BUILD dir
44a40b
    find . \( -name '*.gcno' -o -name '*.[chS]' \) -exec install -D '{}' "$RPM_BUILD_ROOT/$(pwd)/{}" \;
44a40b
%endif
44a40b
44a40b
    # add an a noop %%defattr statement 'cause rpm doesn't like empty file list files
44a40b
    echo '%%defattr(-,-,-)' > ../kernel${Variant:+-${Variant}}-ldsoconf.list
44a40b
    if [ $DoVDSO -ne 0 ]; then
44a40b
        %{make} ARCH=$Arch INSTALL_MOD_PATH=$RPM_BUILD_ROOT vdso_install KERNELRELEASE=$KernelVer
44a40b
        if [ -s ldconfig-kernel.conf ]; then
44a40b
             install -D -m 444 ldconfig-kernel.conf \
44a40b
                $RPM_BUILD_ROOT/etc/ld.so.conf.d/kernel-$KernelVer.conf
44a40b
	     echo /etc/ld.so.conf.d/kernel-$KernelVer.conf >> ../kernel${Variant:+-${Variant}}-ldsoconf.list
44a40b
        fi
44a40b
44a40b
        rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/vdso/.build-id
44a40b
    fi
44a40b
44a40b
    # And save the headers/makefiles etc for building modules against
44a40b
    #
44a40b
    # This all looks scary, but the end result is supposed to be:
44a40b
    # * all arch relevant include/ files
44a40b
    # * all Makefile/Kconfig files
44a40b
    # * all script/ files
44a40b
44a40b
    rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/source
44a40b
    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    (cd $RPM_BUILD_ROOT/lib/modules/$KernelVer ; ln -s build source)
44a40b
    # dirs for additional modules per module-init-tools, kbuild/modules.txt
44a40b
    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/updates
44a40b
    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/weak-updates
44a40b
    # CONFIG_KERNEL_HEADER_TEST generates some extra files in the process of
44a40b
    # testing so just delete
44a40b
    find . -name *.h.s -delete
44a40b
    # first copy everything
44a40b
    cp --parents `find  -type f -name "Makefile*" -o -name "Kconfig*"` $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    if [ ! -e Module.symvers ]; then
44a40b
        touch Module.symvers
44a40b
    fi
44a40b
    cp Module.symvers $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp System.map $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    if [ -s Module.markers ]; then
44a40b
      cp Module.markers $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    fi
44a40b
44a40b
    # create the kABI metadata for use in packaging
44a40b
    # NOTENOTE: the name symvers is used by the rpm backend
44a40b
    # NOTENOTE: to discover and run the /usr/lib/rpm/fileattrs/kabi.attr
44a40b
    # NOTENOTE: script which dynamically adds exported kernel symbol
44a40b
    # NOTENOTE: checksums to the rpm metadata provides list.
44a40b
    # NOTENOTE: if you change the symvers name, update the backend too
44a40b
    echo "**** GENERATING kernel ABI metadata ****"
44a40b
    gzip -c9 < Module.symvers > $RPM_BUILD_ROOT/boot/symvers-$KernelVer.gz
44a40b
    cp $RPM_BUILD_ROOT/boot/symvers-$KernelVer.gz $RPM_BUILD_ROOT/lib/modules/$KernelVer/symvers.gz
44a40b
44a40b
%if %{with_kabichk}
44a40b
    echo "**** kABI checking is enabled in kernel SPEC file. ****"
44a40b
    chmod 0755 $RPM_SOURCE_DIR/check-kabi
44a40b
    if [ -e $RPM_SOURCE_DIR/Module.kabi_%{_target_cpu}$Variant ]; then
44a40b
        cp $RPM_SOURCE_DIR/Module.kabi_%{_target_cpu}$Variant $RPM_BUILD_ROOT/Module.kabi
44a40b
        $RPM_SOURCE_DIR/check-kabi -k $RPM_BUILD_ROOT/Module.kabi -s Module.symvers || exit 1
44a40b
        # for now, don't keep it around.
44a40b
        rm $RPM_BUILD_ROOT/Module.kabi
44a40b
    else
44a40b
        echo "**** NOTE: Cannot find reference Module.kabi file. ****"
44a40b
    fi
44a40b
%endif
44a40b
44a40b
%if %{with_kabidupchk}
44a40b
    echo "**** kABI DUP checking is enabled in kernel SPEC file. ****"
44a40b
    if [ -e $RPM_SOURCE_DIR/Module.kabi_dup_%{_target_cpu}$Variant ]; then
44a40b
        cp $RPM_SOURCE_DIR/Module.kabi_dup_%{_target_cpu}$Variant $RPM_BUILD_ROOT/Module.kabi
44a40b
        $RPM_SOURCE_DIR/check-kabi -k $RPM_BUILD_ROOT/Module.kabi -s Module.symvers || exit 1
44a40b
        # for now, don't keep it around.
44a40b
        rm $RPM_BUILD_ROOT/Module.kabi
44a40b
    else
44a40b
        echo "**** NOTE: Cannot find DUP reference Module.kabi file. ****"
44a40b
    fi
44a40b
%endif
44a40b
44a40b
%if %{with_kabidw_base}
44a40b
    # Don't build kabi base for debug kernels
44a40b
    if [ "$Variant" != "zfcpdump" -a "$Variant" != "debug" ]; then
44a40b
        mkdir -p $RPM_BUILD_ROOT/kabi-dwarf
44a40b
        tar xjvf %{SOURCE301} -C $RPM_BUILD_ROOT/kabi-dwarf
44a40b
44a40b
        mkdir -p $RPM_BUILD_ROOT/kabi-dwarf/stablelists
44a40b
        tar xjvf %{SOURCE300} -C $RPM_BUILD_ROOT/kabi-dwarf/stablelists
44a40b
44a40b
        echo "**** GENERATING DWARF-based kABI baseline dataset ****"
44a40b
        chmod 0755 $RPM_BUILD_ROOT/kabi-dwarf/run_kabi-dw.sh
44a40b
        $RPM_BUILD_ROOT/kabi-dwarf/run_kabi-dw.sh generate \
44a40b
            "$RPM_BUILD_ROOT/kabi-dwarf/stablelists/kabi-current/kabi_stablelist_%{_target_cpu}" \
44a40b
            "$(pwd)" \
44a40b
            "$RPM_BUILD_ROOT/kabidw-base/%{_target_cpu}${Variant:+.${Variant}}" || :
44a40b
44a40b
        rm -rf $RPM_BUILD_ROOT/kabi-dwarf
44a40b
    fi
44a40b
%endif
44a40b
44a40b
%if %{with_kabidwchk}
44a40b
    if [ "$Variant" != "zfcpdump" ]; then
44a40b
        mkdir -p $RPM_BUILD_ROOT/kabi-dwarf
44a40b
        tar xjvf %{SOURCE301} -C $RPM_BUILD_ROOT/kabi-dwarf
44a40b
        if [ -d "$RPM_BUILD_ROOT/kabi-dwarf/base/%{_target_cpu}${Variant:+.${Variant}}" ]; then
44a40b
            mkdir -p $RPM_BUILD_ROOT/kabi-dwarf/stablelists
44a40b
            tar xjvf %{SOURCE300} -C $RPM_BUILD_ROOT/kabi-dwarf/stablelists
44a40b
44a40b
            echo "**** GENERATING DWARF-based kABI dataset ****"
44a40b
            chmod 0755 $RPM_BUILD_ROOT/kabi-dwarf/run_kabi-dw.sh
44a40b
            $RPM_BUILD_ROOT/kabi-dwarf/run_kabi-dw.sh generate \
44a40b
                "$RPM_BUILD_ROOT/kabi-dwarf/stablelists/kabi-current/kabi_stablelist_%{_target_cpu}" \
44a40b
                "$(pwd)" \
44a40b
                "$RPM_BUILD_ROOT/kabi-dwarf/base/%{_target_cpu}${Variant:+.${Variant}}.tmp" || :
44a40b
44a40b
            echo "**** kABI DWARF-based comparison report ****"
44a40b
            $RPM_BUILD_ROOT/kabi-dwarf/run_kabi-dw.sh compare \
44a40b
                "$RPM_BUILD_ROOT/kabi-dwarf/base/%{_target_cpu}${Variant:+.${Variant}}" \
44a40b
                "$RPM_BUILD_ROOT/kabi-dwarf/base/%{_target_cpu}${Variant:+.${Variant}}.tmp" || :
44a40b
            echo "**** End of kABI DWARF-based comparison report ****"
44a40b
        else
44a40b
            echo "**** Baseline dataset for kABI DWARF-BASED comparison report not found ****"
44a40b
        fi
44a40b
44a40b
        rm -rf $RPM_BUILD_ROOT/kabi-dwarf
44a40b
    fi
44a40b
%endif
44a40b
44a40b
    # then drop all but the needed Makefiles/Kconfig files
44a40b
    rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts
44a40b
    rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include
44a40b
    cp .config $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a scripts $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts/tracing
44a40b
    rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts/spdxcheck.py
44a40b
44a40b
    # Files for 'make scripts' to succeed with kernel-devel.
44a40b
    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/security/selinux/include
44a40b
    cp -a --parents security/selinux/include/classmap.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents security/selinux/include/initial_sid_to_string.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/tools/include/tools
44a40b
    cp -a --parents tools/include/tools/be_byteshift.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/include/tools/le_byteshift.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
44a40b
    # Files for 'make prepare' to succeed with kernel-devel.
44a40b
    cp -a --parents tools/include/linux/compiler* $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/include/linux/types.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/build/Build.include $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents tools/build/Build $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents tools/build/fixdep.c $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents tools/objtool/sync-check.sh $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/bpf/resolve_btfids $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
44a40b
    cp --parents security/selinux/include/policycap_names.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents security/selinux/include/policycap.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
44a40b
    cp -a --parents tools/include/asm-generic $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/include/linux $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/include/uapi/asm $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/include/uapi/asm-generic $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/include/uapi/linux $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/include/vdso $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents tools/scripts/utilities.mak $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/lib/subcmd $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents tools/lib/*.c $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents tools/objtool/*.[ch] $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents tools/objtool/Build $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents tools/objtool/include/objtool/*.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/lib/bpf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp --parents tools/lib/bpf/Build $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
44a40b
    if [ -f tools/objtool/objtool ]; then
44a40b
      cp -a tools/objtool/objtool $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/tools/objtool/ || :
44a40b
    fi
44a40b
    if [ -f tools/objtool/fixdep ]; then
44a40b
      cp -a tools/objtool/fixdep $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/tools/objtool/ || :
44a40b
    fi
44a40b
    if [ -d arch/$Arch/scripts ]; then
44a40b
      cp -a arch/$Arch/scripts $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/arch/%{_arch} || :
44a40b
    fi
44a40b
    if [ -f arch/$Arch/*lds ]; then
44a40b
      cp -a arch/$Arch/*lds $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/arch/%{_arch}/ || :
44a40b
    fi
44a40b
    if [ -f arch/%{asmarch}/kernel/module.lds ]; then
44a40b
      cp -a --parents arch/%{asmarch}/kernel/module.lds $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    fi
44a40b
    find $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts \( -iname "*.o" -o -iname "*.cmd" \) -exec rm -f {} +
44a40b
%ifarch ppc64le
44a40b
    cp -a --parents arch/powerpc/lib/crtsavres.[So] $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
%endif
44a40b
    if [ -d arch/%{asmarch}/include ]; then
44a40b
      cp -a --parents arch/%{asmarch}/include $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    fi
44a40b
%ifarch aarch64
44a40b
    # arch/arm64/include/asm/xen references arch/arm
44a40b
    cp -a --parents arch/arm/include/asm/xen $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    # arch/arm64/include/asm/opcodes.h references arch/arm
44a40b
    cp -a --parents arch/arm/include/asm/opcodes.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
%endif
44a40b
    # include the machine specific headers for ARM variants, if available.
44a40b
%ifarch %{arm}
44a40b
    if [ -d arch/%{asmarch}/mach-${Variant}/include ]; then
44a40b
      cp -a --parents arch/%{asmarch}/mach-${Variant}/include $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    fi
44a40b
    # include a few files for 'make prepare'
44a40b
    cp -a --parents arch/arm/tools/gen-mach-types $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/arm/tools/mach-types $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
44a40b
%endif
44a40b
    cp -a include $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include
44a40b
%ifarch i686 x86_64
44a40b
    # files for 'make prepare' to succeed with kernel-devel
44a40b
    cp -a --parents arch/x86/entry/syscalls/syscall_32.tbl $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/entry/syscalls/syscall_64.tbl $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/tools/relocs_32.c $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/tools/relocs_64.c $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/tools/relocs.c $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/tools/relocs_common.c $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/tools/relocs.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/purgatory/purgatory.c $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/purgatory/stack.S $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/purgatory/setup-x86_64.S $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/purgatory/entry64.S $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/boot/string.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/boot/string.c $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents arch/x86/boot/ctype.h $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
44a40b
    cp -a --parents scripts/syscalltbl.sh $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
    cp -a --parents scripts/syscallhdr.sh $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
44a40b
44a40b
    cp -a --parents tools/arch/x86/include/asm $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/arch/x86/include/uapi/asm $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/objtool/arch/x86/lib $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/arch/x86/lib/ $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/arch/x86/tools/gen-insn-attr-x86.awk $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
    cp -a --parents tools/objtool/arch/x86/ $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
44a40b
44a40b
%endif
44a40b
    # Clean up intermediate tools files
44a40b
    find $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/tools \( -iname "*.o" -o -iname "*.cmd" \) -exec rm -f {} +
44a40b
44a40b
    # Make sure the Makefile and version.h have a matching timestamp so that
44a40b
    # external modules can be built
44a40b
    touch -r $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/Makefile $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include/generated/uapi/linux/version.h
44a40b
44a40b
    # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
44a40b
    cp $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/.config $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include/config/auto.conf
44a40b
44a40b
%if %{with_debuginfo}
44a40b
    eu-readelf -n vmlinux | grep "Build ID" | awk '{print $NF}' > vmlinux.id
44a40b
    cp vmlinux.id $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/vmlinux.id
44a40b
44a40b
    #
44a40b
    # save the vmlinux file for kernel debugging into the kernel-debuginfo rpm
44a40b
    #
44a40b
    mkdir -p $RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer
44a40b
    cp vmlinux $RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer
44a40b
    if [ -n "%{vmlinux_decompressor}" ]; then
44a40b
	    eu-readelf -n  %{vmlinux_decompressor} | grep "Build ID" | awk '{print $NF}' > vmlinux.decompressor.id
44a40b
	    # Without build-id the build will fail. But for s390 the build-id
44a40b
	    # wasn't added before 5.11. In case it is missing prefer not
44a40b
	    # packaging the debuginfo over a build failure.
44a40b
	    if [ -s vmlinux.decompressor.id ]; then
44a40b
		    cp vmlinux.decompressor.id $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/vmlinux.decompressor.id
44a40b
		    cp %{vmlinux_decompressor} $RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer/vmlinux.decompressor
44a40b
	    fi
44a40b
    fi
44a40b
%endif
44a40b
44a40b
    find $RPM_BUILD_ROOT/lib/modules/$KernelVer -name "*.ko" -type f >modnames
44a40b
44a40b
    # mark modules executable so that strip-to-file can strip them
44a40b
    xargs --no-run-if-empty chmod u+x < modnames
44a40b
44a40b
    # Generate a list of modules for block and networking.
44a40b
44a40b
    grep -F /drivers/ modnames | xargs --no-run-if-empty nm -upA |
44a40b
    sed -n 's,^.*/\([^/]*\.ko\):  *U \(.*\)$,\1 \2,p' > drivers.undef
44a40b
44a40b
    collect_modules_list()
44a40b
    {
44a40b
      sed -r -n -e "s/^([^ ]+) \\.?($2)\$/\\1/p" drivers.undef |
44a40b
        LC_ALL=C sort -u > $RPM_BUILD_ROOT/lib/modules/$KernelVer/modules.$1
44a40b
      if [ ! -z "$3" ]; then
44a40b
        sed -r -e "/^($3)\$/d" -i $RPM_BUILD_ROOT/lib/modules/$KernelVer/modules.$1
44a40b
      fi
44a40b
    }
44a40b
44a40b
    collect_modules_list networking \
44a40b
      'register_netdev|ieee80211_register_hw|usbnet_probe|phy_driver_register|rt(l_|2x00)(pci|usb)_probe|register_netdevice'
44a40b
    collect_modules_list block \
44a40b
      'ata_scsi_ioctl|scsi_add_host|scsi_add_host_with_dma|blk_alloc_queue|blk_init_queue|register_mtd_blktrans|scsi_esp_register|scsi_register_device_handler|blk_queue_physical_block_size' 'pktcdvd.ko|dm-mod.ko'
44a40b
    collect_modules_list drm \
44a40b
      'drm_open|drm_init'
44a40b
    collect_modules_list modesetting \
44a40b
      'drm_crtc_init'
44a40b
44a40b
    # detect missing or incorrect license tags
44a40b
    ( find $RPM_BUILD_ROOT/lib/modules/$KernelVer -name '*.ko' | xargs /sbin/modinfo -l | \
44a40b
        grep -E -v 'GPL( v2)?$|Dual BSD/GPL$|Dual MPL/GPL$|GPL and additional rights$' ) && exit 1
44a40b
44a40b
    remove_depmod_files()
44a40b
    {
44a40b
        # remove files that will be auto generated by depmod at rpm -i time
44a40b
        pushd $RPM_BUILD_ROOT/lib/modules/$KernelVer/
44a40b
            rm -f modules.{alias,alias.bin,builtin.alias.bin,builtin.bin} \
44a40b
                  modules.{dep,dep.bin,devname,softdep,symbols,symbols.bin}
44a40b
        popd
44a40b
    }
44a40b
44a40b
    remove_depmod_files
44a40b
44a40b
    # Identify modules in the kernel-modules-extras package
44a40b
    %{SOURCE20} $RPM_BUILD_ROOT lib/modules/$KernelVer $RPM_SOURCE_DIR/mod-extra.list
44a40b
    # Identify modules in the kernel-modules-extras package
44a40b
    %{SOURCE20} $RPM_BUILD_ROOT lib/modules/$KernelVer %{SOURCE84} internal
44a40b
44a40b
    #
44a40b
    # Generate the kernel-core and kernel-modules files lists
44a40b
    #
44a40b
44a40b
    # Copy the System.map file for depmod to use, and create a backup of the
44a40b
    # full module tree so we can restore it after we're done filtering
44a40b
    cp System.map $RPM_BUILD_ROOT/.
44a40b
    pushd $RPM_BUILD_ROOT
44a40b
    mkdir restore
44a40b
    cp -r lib/modules/$KernelVer/* restore/.
44a40b
44a40b
    # don't include anything going into kernel-modules-extra in the file lists
44a40b
    xargs rm -rf < mod-extra.list
44a40b
    # don't include anything going int kernel-modules-internal in the file lists
44a40b
    xargs rm -rf < mod-internal.list
44a40b
44a40b
    if [ $DoModules -eq 1 ]; then
44a40b
	# Find all the module files and filter them out into the core and
44a40b
	# modules lists.  This actually removes anything going into -modules
44a40b
	# from the dir.
44a40b
	find lib/modules/$KernelVer/kernel -name *.ko | sort -n > modules.list
44a40b
	cp $RPM_SOURCE_DIR/filter-*.sh .
44a40b
	./filter-modules.sh modules.list %{_target_cpu}
44a40b
	rm filter-*.sh