xref: /linux/scripts/package/kernel.spec (revision 956b9cbd7f156c8672dac94a00de3c6a0939c692)
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}
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%global _find_debuginfo_opts -r
71%global _missing_build_ids_terminate_build 1
72%global _no_recompute_build_ids 1
73%{debug_package}
74
75# later, we make all modules executable so that find-debuginfo.sh strips
76# them up. but they don't actually need to be executable, so remove the
77# executable bit, taking care to do it _after_ find-debuginfo.sh has run
78%define __spec_install_post \
79	%{?__debug_package:%{__debug_install_post}} \
80	%{__arch_install_post} \
81	%{__os_install_post} \
82	find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \\\
83		| xargs --no-run-if-empty chmod u-x
84%else
85%define __spec_install_post /usr/lib/rpm/brp-compress || :
86%endif
87# some (but not all) versions of rpmbuild emit %%debug_package with
88# %%install. since we've already emitted it manually, that would cause
89# a package redefinition error. ensure that doesn't happen
90%define debug_package %{nil}
91
92%prep
93%setup -q -n linux
94cp %{SOURCE1} .config
95patch -p1 < %{SOURCE2}
96
97%build
98%{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release}
99
100%install
101mkdir -p %{buildroot}/lib/modules/%{KERNELRELEASE}
102cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEASE}/vmlinuz
103# DEPMOD=true makes depmod no-op. We do not package depmod-generated files.
104%{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} %{?install_mod_strip:INSTALL_MOD_STRIP=1} DEPMOD=true modules_install
105%{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
106cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE}
107cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config
108if %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='test -d ${srctree}/arch/${SRCARCH}/boot/dts' 2>/dev/null; then
109	%{make} %{makeflags} INSTALL_DTBS_PATH=%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb dtbs_install
110fi
111ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build
112%if %{with_devel}
113%{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
114%endif
115
116{
117	echo "/lib/modules/%{KERNELRELEASE}"
118
119	for x in alias alias.bin builtin.alias.bin builtin.bin dep dep.bin \
120				devname softdep symbols symbols.bin weakdep; do
121		echo "%ghost /lib/modules/%{KERNELRELEASE}/modules.${x}"
122	done
123
124	for x in System.map config vmlinuz; do
125		echo "%ghost /boot/${x}-%{KERNELRELEASE}"
126	done
127
128	if [ -d "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" ];then
129		find "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" -printf "%%%ghost /boot/dtb-%{KERNELRELEASE}/%%P\n"
130	fi
131
132	echo "%exclude /lib/modules/%{KERNELRELEASE}/build"
133} > %{buildroot}/kernel.list
134
135%if 0%{with_debuginfo_manual}%{with_debuginfo_rpm} > 0
136# copying vmlinux directly to the debug directory means it will not get
137# stripped (but its source paths will still be collected + fixed up)
138mkdir -p %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE}
139cp vmlinux %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE}
140%endif
141
142%if %{with_debuginfo_rpm}
143# make modules executable so that find-debuginfo.sh strips them. this
144# will be undone later in %%__spec_install_post
145find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \
146	| xargs --no-run-if-empty chmod u+x
147%endif
148
149%if %{with_debuginfo_manual}
150echo /usr/lib/debug/lib/modules/%{KERNELRELEASE}/vmlinux > %{buildroot}/debuginfo.list
151while read -r mod; do
152	mod="${mod%.o}.ko"
153	dbg="%{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE}/kernel/${mod}"
154	buildid=$("${READELF:-readelf}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p')
155	link="%{buildroot}/usr/lib/debug/.build-id/${buildid}.debug"
156
157	mkdir -p "${dbg%/*}" "${link%/*}"
158	"${OBJCOPY:-objcopy}" --only-keep-debug "${mod}" "${dbg}"
159	ln -sf --relative "${dbg}" "${link}"
160
161	echo "${dbg#%{buildroot}}" >> %{buildroot}/debuginfo.list
162	echo "${link#%{buildroot}}" >> %{buildroot}/debuginfo.list
163done < modules.order
164%endif
165
166%clean
167rm -rf %{buildroot}
168%if %{with_debuginfo_rpm}
169rm -f debugfiles.list debuglinks.list debugsourcefiles.list debugsources.list \
170	elfbins.list
171%endif
172
173%post
174if [ -x /usr/bin/kernel-install ]; then
175	/usr/bin/kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz
176fi
177for file in vmlinuz System.map config; do
178	if ! cmp --silent "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"; then
179		cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"
180	fi
181done
182if [ -d "/lib/modules/%{KERNELRELEASE}/dtb" ] && \
183   ! diff -rq "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}" >/dev/null 2>&1; then
184	rm -rf "/boot/dtb-%{KERNELRELEASE}"
185	cp -r "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}"
186fi
187if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then
188	/usr/sbin/depmod %{KERNELRELEASE}
189fi
190
191%preun
192if [ -x /usr/bin/kernel-install ]; then
193kernel-install remove %{KERNELRELEASE}
194fi
195
196%files -f %{buildroot}/kernel.list
197%defattr (-, root, root)
198%exclude /kernel.list
199
200%files headers
201%defattr (-, root, root)
202/usr/include
203
204%if %{with_devel}
205%files devel
206%defattr (-, root, root)
207/usr/src/kernels/%{KERNELRELEASE}
208/lib/modules/%{KERNELRELEASE}/build
209%endif
210
211%if %{with_debuginfo_manual}
212%files -f %{buildroot}/debuginfo.list debuginfo
213%defattr (-, root, root)
214%exclude /debuginfo.list
215%endif
216