| 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 | %define __spec_install_post /usr/lib/rpm/brp-compress || : |
| 6 | %define debug_package %{nil} |
| 7 | |
| 8 | Name: kernel |
| 9 | Summary: The Linux Kernel |
| 10 | Version: %(echo %{KERNELRELEASE} | sed -e 's/-/_/g') |
| 11 | Release: %{pkg_release} |
| 12 | License: GPL |
| 13 | Group: System Environment/Kernel |
| 14 | Vendor: The Linux Community |
| 15 | URL: https://www.kernel.org |
| 16 | Source0: linux.tar.gz |
| 17 | Source1: config |
| 18 | Source2: diff.patch |
| 19 | Provides: kernel-%{KERNELRELEASE} |
| 20 | BuildRequires: bc binutils bison dwarves |
| 21 | BuildRequires: (elfutils-libelf-devel or libelf-devel) flex |
| 22 | BuildRequires: gcc make openssl openssl-devel perl python3 rsync |
| 23 | |
| 24 | %description |
| 25 | The Linux Kernel, the operating system core itself |
| 26 | |
| 27 | %package headers |
| 28 | Summary: Header files for the Linux kernel for use by glibc |
| 29 | Group: Development/System |
| 30 | Obsoletes: kernel-headers |
| 31 | Provides: kernel-headers = %{version} |
| 32 | %description headers |
| 33 | Kernel-headers includes the C header files that specify the interface |
| 34 | between the Linux kernel and userspace libraries and programs. The |
| 35 | header files define structures and constants that are needed for |
| 36 | building most standard programs and are also needed for rebuilding the |
| 37 | glibc package. |
| 38 | |
| 39 | %if %{with_devel} |
| 40 | %package devel |
| 41 | Summary: Development package for building kernel modules to match the %{version} kernel |
| 42 | Group: System Environment/Kernel |
| 43 | AutoReqProv: no |
| 44 | %description -n kernel-devel |
| 45 | This package provides kernel headers and makefiles sufficient to build modules |
| 46 | against the %{version} kernel package. |
| 47 | %endif |
| 48 | |
| 49 | %prep |
| 50 | %setup -q -n linux |
| 51 | cp %{SOURCE1} .config |
| 52 | patch -p1 < %{SOURCE2} |
| 53 | |
| 54 | %build |
| 55 | %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release} |
| 56 | |
| 57 | %install |
| 58 | mkdir -p %{buildroot}/lib/modules/%{KERNELRELEASE} |
| 59 | cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEASE}/vmlinuz |
| 60 | %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install |
| 61 | %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install |
| 62 | cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE} |
| 63 | cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config |
| 64 | ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build |
| 65 | %if %{with_devel} |
| 66 | %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}' |
| 67 | %endif |
| 68 | |
| 69 | %clean |
| 70 | rm -rf %{buildroot} |
| 71 | |
| 72 | %post |
| 73 | if [ -x /usr/bin/kernel-install ]; then |
| 74 | /usr/bin/kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz |
| 75 | fi |
| 76 | for file in vmlinuz System.map config; do |
| 77 | if ! cmp --silent "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"; then |
| 78 | cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}" |
| 79 | fi |
| 80 | done |
| 81 | |
| 82 | %preun |
| 83 | if [ -x /sbin/new-kernel-pkg ]; then |
| 84 | new-kernel-pkg --remove %{KERNELRELEASE} --rminitrd --initrdfile=/boot/initramfs-%{KERNELRELEASE}.img |
| 85 | elif [ -x /usr/bin/kernel-install ]; then |
| 86 | kernel-install remove %{KERNELRELEASE} |
| 87 | fi |
| 88 | |
| 89 | %postun |
| 90 | if [ -x /sbin/update-bootloader ]; then |
| 91 | /sbin/update-bootloader --remove %{KERNELRELEASE} |
| 92 | fi |
| 93 | |
| 94 | %files |
| 95 | %defattr (-, root, root) |
| 96 | /lib/modules/%{KERNELRELEASE} |
| 97 | %exclude /lib/modules/%{KERNELRELEASE}/build |
| 98 | |
| 99 | %files headers |
| 100 | %defattr (-, root, root) |
| 101 | /usr/include |
| 102 | |
| 103 | %if %{with_devel} |
| 104 | %files devel |
| 105 | %defattr (-, root, root) |
| 106 | /usr/src/kernels/%{KERNELRELEASE} |
| 107 | /lib/modules/%{KERNELRELEASE}/build |
| 108 | %endif |