xref: /linux/scripts/package/kernel.spec (revision 2845f512232de9e436b9e3b5529e906e62414013)
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
8Name: kernel
9Summary: The Linux Kernel
10Version: %(echo %{KERNELRELEASE} | sed -e 's/-/_/g')
11Release: %{pkg_release}
12License: GPL
13Group: System Environment/Kernel
14Vendor: The Linux Community
15URL: https://www.kernel.org
16Source0: linux.tar.gz
17Source1: config
18Source2: diff.patch
19Provides: kernel-%{KERNELRELEASE}
20BuildRequires: bc binutils bison dwarves
21BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
22BuildRequires: gcc make openssl openssl-devel perl python3 rsync
23
24%description
25The Linux Kernel, the operating system core itself
26
27%package headers
28Summary: Header files for the Linux kernel for use by glibc
29Group: Development/System
30Obsoletes: kernel-headers
31Provides: kernel-headers = %{version}
32%description headers
33Kernel-headers includes the C header files that specify the interface
34between the Linux kernel and userspace libraries and programs.  The
35header files define structures and constants that are needed for
36building most standard programs and are also needed for rebuilding the
37glibc package.
38
39%if %{with_devel}
40%package devel
41Summary: Development package for building kernel modules to match the %{version} kernel
42Group: System Environment/Kernel
43AutoReqProv: no
44%description -n kernel-devel
45This package provides kernel headers and makefiles sufficient to build modules
46against the %{version} kernel package.
47%endif
48
49%prep
50%setup -q -n linux
51cp %{SOURCE1} .config
52patch -p1 < %{SOURCE2}
53
54%build
55%{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release}
56
57%install
58mkdir -p %{buildroot}/lib/modules/%{KERNELRELEASE}
59cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEASE}/vmlinuz
60# DEPMOD=true makes depmod no-op. We do not package depmod-generated files.
61%{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} DEPMOD=true modules_install
62%{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
63cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE}
64cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config
65if %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='test -d ${srctree}/arch/${SRCARCH}/boot/dts' 2>/dev/null; then
66	%{make} %{makeflags} INSTALL_DTBS_PATH=%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb dtbs_install
67fi
68ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build
69%if %{with_devel}
70%{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
71%endif
72
73{
74	echo "/lib/modules/%{KERNELRELEASE}"
75
76	for x in alias alias.bin builtin.alias.bin builtin.bin dep dep.bin \
77					devname softdep symbols symbols.bin; do
78		echo "%ghost /lib/modules/%{KERNELRELEASE}/modules.${x}"
79	done
80
81	for x in System.map config vmlinuz; do
82		echo "%ghost /boot/${x}-%{KERNELRELEASE}"
83	done
84
85	if [ -d "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" ];then
86		echo "/lib/modules/%{KERNELRELEASE}/dtb"
87		find "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" -printf "%%%ghost /boot/dtb-%{KERNELRELEASE}/%%P\n"
88	fi
89
90	echo "%exclude /lib/modules/%{KERNELRELEASE}/build"
91} > %{buildroot}/kernel.list
92
93%clean
94rm -rf %{buildroot}
95
96%post
97if [ -x /usr/bin/kernel-install ]; then
98	/usr/bin/kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz
99fi
100for file in vmlinuz System.map config; do
101	if ! cmp --silent "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"; then
102		cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"
103	fi
104done
105if [ -d "/lib/modules/%{KERNELRELEASE}/dtb" ] && \
106   ! diff -rq "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}" >/dev/null 2>&1; then
107	rm -rf "/boot/dtb-%{KERNELRELEASE}"
108	cp -r "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}"
109fi
110if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then
111	/usr/sbin/depmod %{KERNELRELEASE}
112fi
113
114%preun
115if [ -x /usr/bin/kernel-install ]; then
116kernel-install remove %{KERNELRELEASE}
117fi
118
119%files -f %{buildroot}/kernel.list
120%defattr (-, root, root)
121%exclude /kernel.list
122
123%files headers
124%defattr (-, root, root)
125/usr/include
126
127%if %{with_devel}
128%files devel
129%defattr (-, root, root)
130/usr/src/kernels/%{KERNELRELEASE}
131/lib/modules/%{KERNELRELEASE}/build
132%endif
133