1# _arch is undefined if /usr/lib/rpm/platform/*/macros was not included. 2%{!?_arch: %define _arch dummy} 3%{!?make: %define make make} 4%define makeflags %{?_smp_mflags} ARCH=%{ARCH} 5 6Name: kernel 7Summary: The Linux Kernel 8Version: %(echo %{KERNELRELEASE} | sed -e 's/-/_/g') 9Release: %{pkg_release}%{?dist} 10License: GPL 11Group: System Environment/Kernel 12Vendor: The Linux Community 13URL: https://www.kernel.org 14Source0: linux.tar.gz 15Source1: config 16Source2: diff.patch 17Provides: kernel-%{KERNELRELEASE} 18BuildRequires: bc binutils bison dwarves 19BuildRequires: (elfutils-devel or libdw-devel) 20BuildRequires: (elfutils-libelf-devel or libelf-devel) flex 21BuildRequires: gcc make openssl openssl-devel perl python3 rsync 22 23%description 24The Linux Kernel, the operating system core itself 25 26%package headers 27Summary: Header files for the Linux kernel for use by glibc 28Group: Development/System 29Obsoletes: kernel-headers < %{version} 30Provides: kernel-headers = %{version} 31%description headers 32Kernel-headers includes the C header files that specify the interface 33between the Linux kernel and userspace libraries and programs. The 34header files define structures and constants that are needed for 35building most standard programs and are also needed for rebuilding the 36glibc package. 37 38%if %{with_devel} 39%package devel 40Summary: Development package for building kernel modules to match the %{version} kernel 41Group: System Environment/Kernel 42AutoReqProv: no 43%description -n kernel-devel 44This package provides kernel headers and makefiles sufficient to build modules 45against the %{version} kernel package. 46%endif 47 48%if %{with_debuginfo_manual} 49%package debuginfo 50Summary: Debug information package for the Linux kernel 51Group: Development/Debug 52AutoReq: 0 53AutoProv: 1 54%description debuginfo 55This package provides debug information for the kernel image and modules from the 56%{version} package. 57%define install_mod_strip 1 58%endif 59 60%if %{with_debuginfo_rpm} 61# list of debuginfo-related options taken from distribution kernel.spec 62# files 63%undefine _include_minidebuginfo 64%undefine _find_debuginfo_dwz_opts 65%undefine _unique_build_ids 66%undefine _unique_debug_names 67%undefine _unique_debug_srcs 68%undefine _debugsource_packages 69%undefine _debuginfo_subpackages 70 71# Preserve .BTF and .BTF.base sections in kernel modules during debuginfo 72# stripping. find-debuginfo.sh uses eu-strip which removes non-allocated ELF 73# sections like .BTF by default. .BTF.base is required for BTF distillation 74# support; without it, module BTF validation fails. 75%global with_keep_section %(%{__find_debuginfo} --help 2>&1 | grep -c keep-section) 76%if %{with_keep_section} 77%global _find_debuginfo_opts -r --keep-section .BTF --keep-section .BTF.base 78%else 79%global _find_debuginfo_opts -r 80%endif 81 82%global _missing_build_ids_terminate_build 1 83%global _no_recompute_build_ids 1 84%{debug_package} 85 86# later, we make all modules executable so that find-debuginfo.sh strips 87# them up. but they don't actually need to be executable, so remove the 88# executable bit, taking care to do it _after_ find-debuginfo.sh has run 89%define __spec_install_post \ 90 %{?__debug_package:%{__debug_install_post}} \ 91 %{__arch_install_post} \ 92 %{__os_install_post} \ 93 find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \\\ 94 | xargs --no-run-if-empty chmod u-x 95%else 96%define __spec_install_post /usr/lib/rpm/brp-compress || : 97%endif 98# some (but not all) versions of rpmbuild emit %%debug_package with 99# %%install. since we've already emitted it manually, that would cause 100# a package redefinition error. ensure that doesn't happen 101%define debug_package %{nil} 102 103%prep 104%setup -q -n linux 105cp %{SOURCE1} .config 106patch -p1 < %{SOURCE2} 107 108%build 109%{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release} 110 111%install 112mkdir -p %{buildroot}/lib/modules/%{KERNELRELEASE} 113cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEASE}/vmlinuz 114# DEPMOD=true makes depmod no-op. We do not package depmod-generated files. 115%{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} %{?install_mod_strip:INSTALL_MOD_STRIP=1} DEPMOD=true modules_install 116%{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install 117cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE} 118cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config 119if %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='test -d ${srctree}/arch/${SRCARCH}/boot/dts' 2>/dev/null; then 120 %{make} %{makeflags} INSTALL_DTBS_PATH=%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb dtbs_install 121fi 122ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build 123%if %{with_devel} 124%{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}' 125%endif 126 127{ 128 echo "/lib/modules/%{KERNELRELEASE}" 129 130 for x in alias alias.bin builtin.alias.bin builtin.bin dep dep.bin \ 131 devname softdep symbols symbols.bin weakdep; do 132 echo "%ghost /lib/modules/%{KERNELRELEASE}/modules.${x}" 133 done 134 135 for x in System.map config vmlinuz; do 136 echo "%ghost /boot/${x}-%{KERNELRELEASE}" 137 done 138 139 if [ -d "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" ];then 140 find "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" -printf "%%%ghost /boot/dtb-%{KERNELRELEASE}/%%P\n" 141 fi 142 143 echo "%exclude /lib/modules/%{KERNELRELEASE}/build" 144} > %{buildroot}/kernel.list 145 146%if 0%{with_debuginfo_manual}%{with_debuginfo_rpm} > 0 147# copying vmlinux directly to the debug directory means it will not get 148# stripped (but its source paths will still be collected + fixed up) 149mkdir -p %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE} 150cp vmlinux %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE} 151%endif 152 153%if %{with_debuginfo_rpm} 154# make modules executable so that find-debuginfo.sh strips them. this 155# will be undone later in %%__spec_install_post 156find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \ 157 | xargs --no-run-if-empty chmod u+x 158%endif 159 160%if %{with_debuginfo_manual} 161echo /usr/lib/debug/lib/modules/%{KERNELRELEASE}/vmlinux > %{buildroot}/debuginfo.list 162while read -r mod; do 163 mod="${mod%.o}.ko" 164 dbg="%{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE}/kernel/${mod}" 165 buildid=$("${READELF:-readelf}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p') 166 link="%{buildroot}/usr/lib/debug/.build-id/${buildid}.debug" 167 168 mkdir -p "${dbg%/*}" "${link%/*}" 169 "${OBJCOPY:-objcopy}" --only-keep-debug "${mod}" "${dbg}" 170 ln -sf --relative "${dbg}" "${link}" 171 172 echo "${dbg#%{buildroot}}" >> %{buildroot}/debuginfo.list 173 echo "${link#%{buildroot}}" >> %{buildroot}/debuginfo.list 174done < modules.order 175%endif 176 177%clean 178rm -rf %{buildroot} 179%if %{with_debuginfo_rpm} 180rm -f debugfiles.list debuglinks.list debugsourcefiles.list debugsources.list \ 181 elfbins.list 182%endif 183 184%post 185if [ -x /usr/bin/kernel-install ]; then 186 /usr/bin/kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz 187fi 188for file in vmlinuz System.map config; do 189 if ! cmp --silent "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"; then 190 cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}" 191 fi 192done 193if [ -d "/lib/modules/%{KERNELRELEASE}/dtb" ] && \ 194 ! diff -rq "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}" >/dev/null 2>&1; then 195 rm -rf "/boot/dtb-%{KERNELRELEASE}" 196 cp -r "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}" 197fi 198if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then 199 /usr/sbin/depmod %{KERNELRELEASE} 200fi 201 202%preun 203if [ -x /usr/bin/kernel-install ]; then 204kernel-install remove %{KERNELRELEASE} 205fi 206 207%files -f %{buildroot}/kernel.list 208%defattr (-, root, root) 209%exclude /kernel.list 210 211%files headers 212%defattr (-, root, root) 213/usr/include 214 215%if %{with_devel} 216%files devel 217%defattr (-, root, root) 218/usr/src/kernels/%{KERNELRELEASE} 219/lib/modules/%{KERNELRELEASE}/build 220%endif 221 222%if %{with_debuginfo_manual} 223%files -f %{buildroot}/debuginfo.list debuginfo 224%defattr (-, root, root) 225%exclude /debuginfo.list 226%endif 227