| 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 | |
| 6 | Name: kernel |
| 7 | Summary: The Linux Kernel |
| 8 | Version: %(echo %{KERNELRELEASE} | sed -e 's/-/_/g') |
| 9 | Release: %{pkg_release}%{?dist} |
| 10 | License: GPL |
| 11 | Group: System Environment/Kernel |
| 12 | Vendor: The Linux Community |
| 13 | URL: https://www.kernel.org |
| 14 | Source0: linux.tar.gz |
| 15 | Source1: config |
| 16 | Source2: diff.patch |
| 17 | Provides: kernel-%{KERNELRELEASE} |
| 18 | BuildRequires: bc binutils bison dwarves |
| 19 | BuildRequires: (elfutils-devel or libdw-devel) |
| 20 | BuildRequires: (elfutils-libelf-devel or libelf-devel) flex |
| 21 | BuildRequires: gcc make openssl openssl-devel perl python3 rsync |
| 22 | |
| 23 | %description |
| 24 | The Linux Kernel, the operating system core itself |
| 25 | |
| 26 | %package headers |
| 27 | Summary: Header files for the Linux kernel for use by glibc |
| 28 | Group: Development/System |
| 29 | Obsoletes: kernel-headers < %{version} |
| 30 | Provides: kernel-headers = %{version} |
| 31 | %description headers |
| 32 | Kernel-headers includes the C header files that specify the interface |
| 33 | between the Linux kernel and userspace libraries and programs. The |
| 34 | header files define structures and constants that are needed for |
| 35 | building most standard programs and are also needed for rebuilding the |
| 36 | glibc package. |
| 37 | |
| 38 | %if %{with_devel} |
| 39 | %package devel |
| 40 | Summary: Development package for building kernel modules to match the %{version} kernel |
| 41 | Group: System Environment/Kernel |
| 42 | AutoReqProv: no |
| 43 | %description -n kernel-devel |
| 44 | This package provides kernel headers and makefiles sufficient to build modules |
| 45 | against the %{version} kernel package. |
| 46 | %endif |
| 47 | |
| 48 | %if %{with_debuginfo_manual} |
| 49 | %package debuginfo |
| 50 | Summary: Debug information package for the Linux kernel |
| 51 | Group: Development/Debug |
| 52 | AutoReq: 0 |
| 53 | AutoProv: 1 |
| 54 | %description debuginfo |
| 55 | This 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 |
| 105 | cp %{SOURCE1} .config |
| 106 | patch -p1 < %{SOURCE2} |
| 107 | |
| 108 | %build |
| 109 | %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release} |
| 110 | |
| 111 | %install |
| 112 | mkdir -p %{buildroot}/lib/modules/%{KERNELRELEASE} |
| 113 | cp $(%{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 |
| 117 | cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE} |
| 118 | cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config |
| 119 | if %{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 |
| 121 | fi |
| 122 | ln -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) |
| 149 | mkdir -p %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE} |
| 150 | cp 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 |
| 156 | find %{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} |
| 161 | echo /usr/lib/debug/lib/modules/%{KERNELRELEASE}/vmlinux > %{buildroot}/debuginfo.list |
| 162 | while 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 |
| 174 | done < modules.order |
| 175 | %endif |
| 176 | |
| 177 | %clean |
| 178 | rm -rf %{buildroot} |
| 179 | %if %{with_debuginfo_rpm} |
| 180 | rm -f debugfiles.list debuglinks.list debugsourcefiles.list debugsources.list \ |
| 181 | elfbins.list |
| 182 | %endif |
| 183 | |
| 184 | %post |
| 185 | if [ -x /usr/bin/kernel-install ]; then |
| 186 | /usr/bin/kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz |
| 187 | fi |
| 188 | for 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 |
| 192 | done |
| 193 | if [ -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}" |
| 197 | fi |
| 198 | if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then |
| 199 | /usr/sbin/depmod %{KERNELRELEASE} |
| 200 | fi |
| 201 | |
| 202 | %preun |
| 203 | if [ -x /usr/bin/kernel-install ]; then |
| 204 | kernel-install remove %{KERNELRELEASE} |
| 205 | fi |
| 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 |