22%{! ?_arch: %define _arch dummy}
33%{! ?make: %define make make}
44%define makeflags %{?_smp_mflags } ARCH= %{ARCH }
5- %define __spec_install_post /usr/lib/rpm/brp-compress || :
6- %define debug_package %{nil }
75
86Name: kernel
97Summary: The Linux Kernel
@@ -47,13 +45,49 @@ This package provides kernel headers and makefiles sufficient to build modules
4745against the %{version } kernel package.
4846%endif
4947
50- %if %{with_debuginfo }
48+ %if %{with_debuginfo_manual }
5149%package debuginfo
5250Summary: Debug information package for the Linux kernel
51+ Group: Development/Debug
52+ AutoReq: 0
53+ AutoProv: 1
5354%description debuginfo
5455This package provides debug information for the kernel image and modules from the
5556%{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 || :
5686%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 }
5791
5892%prep
5993%setup -q -n linux
@@ -67,7 +101,7 @@ patch -p1 < %{SOURCE2}
67101mkdir -p %{buildroot }/lib/modules/%{KERNELRELEASE }
68102cp $( %{make} %{makeflags} -s image_name) %{buildroot }/lib/modules/%{KERNELRELEASE }/vmlinuz
69103# DEPMOD=true makes depmod no-op. We do not package depmod-generated files.
70- %{make } %{makeflags } INSTALL_MOD_PATH=%{buildroot } INSTALL_MOD_STRIP=1 DEPMOD=true modules_install
104+ %{make } %{makeflags } INSTALL_MOD_PATH=%{buildroot } %{ ? install_mod_strip: INSTALL_MOD_STRIP=1} DEPMOD=true modules_install
71105%{make } %{makeflags } INSTALL_HDR_PATH=%{buildroot }/usr headers_install
72106cp System.map %{buildroot }/lib/modules/%{KERNELRELEASE }
73107cp .config %{buildroot }/lib/modules/%{KERNELRELEASE }/config
@@ -98,22 +132,30 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA
98132 echo "%exclude /lib/modules/%{KERNELRELEASE }/build"
99133} > %{buildroot }/kernel.list
100134
101- %if %{ with_debuginfo }
135+ %if 0%{ with_debuginfo_manual }%{ with_debuginfo_rpm } > 0
102136# copying vmlinux directly to the debug directory means it will not get
103137# stripped (but its source paths will still be collected + fixed up)
104138mkdir -p %{buildroot }/usr/lib/debug/lib/modules/%{KERNELRELEASE }
105139cp vmlinux %{buildroot }/usr/lib/debug/lib/modules/%{KERNELRELEASE }
140+ %endif
106141
107- echo /usr/lib/debug/lib/modules/%{KERNELRELEASE }/vmlinux > %{buildroot }/debuginfo.list
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
145+ find %{buildroot }/lib/modules/%{KERNELRELEASE } -name "*.ko" -type f \
146+ | xargs --no-run-if-empty chmod u+x
147+ %endif
108148
149+ %if %{with_debuginfo_manual }
150+ echo /usr/lib/debug/lib/modules/%{KERNELRELEASE }/vmlinux > %{buildroot }/debuginfo.list
109151while read -r mod; do
110152 mod= "${mod%.o}.ko"
111153 dbg= "%{buildroot }/usr/lib/debug/lib/modules/%{KERNELRELEASE }/kernel/${mod}"
112- buildid= $("${READELF}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p')
154+ buildid= $("${READELF:-readelf }" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p')
113155 link= "%{buildroot }/usr/lib/debug/.build-id/${buildid}.debug"
114156
115157 mkdir -p "${dbg%/*}" "${link%/*}"
116- "${OBJCOPY}" --only-keep-debug "${mod}" "${dbg}"
158+ "${OBJCOPY:-objcopy }" --only-keep-debug "${mod}" "${dbg}"
117159 ln -sf --relative "${dbg}" "${link}"
118160
119161 echo "${dbg#%{buildroot}}" >> %{buildroot}/debuginfo.list
@@ -123,6 +165,10 @@ done < modules.order
123165
124166%clean
125167rm -rf %{buildroot }
168+ %if %{with_debuginfo_rpm }
169+ rm -f debugfiles.list debuglinks.list debugsourcefiles.list debugsources.list \
170+ elfbins.list
171+ %endif
126172
127173%post
128174if [ -x /usr/bin/kernel-install ]; then
162208/lib/modules/%{KERNELRELEASE }/build
163209%endif
164210
165- %if %{with_debuginfo }
211+ %if %{with_debuginfo_manual }
166212%files -f %{buildroot }/debuginfo.list debuginfo
167213%defattr (-, root, root)
168214%exclude /debuginfo.list
0 commit comments