Merge tag 'kbuild-v6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy...
[sfrench/cifs-2.6.git] / scripts / package / kernel.spec
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 if %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='test -d ${srctree}/arch/${SRCARCH}/boot/dts' 2>/dev/null; then
65         %{make} %{makeflags} INSTALL_DTBS_PATH=%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb dtbs_install
66 fi
67 ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build
68 %if %{with_devel}
69 %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
70 %endif
71
72 {
73         for x in System.map config kernel modules.builtin \
74                         modules.builtin.modinfo modules.order vmlinuz; do
75                 echo "/lib/modules/%{KERNELRELEASE}/${x}"
76         done
77
78         for x in alias alias.bin builtin.alias.bin builtin.bin dep dep.bin \
79                                         devname softdep symbols symbols.bin; do
80                 echo "%ghost /lib/modules/%{KERNELRELEASE}/modules.${x}"
81         done
82
83         for x in System.map config vmlinuz; do
84                 echo "%ghost /boot/${x}-%{KERNELRELEASE}"
85         done
86
87         if [ -d "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" ];then
88                 echo "/lib/modules/%{KERNELRELEASE}/dtb"
89                 find "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" -printf "%%%ghost /boot/dtb-%{KERNELRELEASE}/%%P\n"
90         fi
91
92         echo "%exclude /lib/modules/%{KERNELRELEASE}/build"
93 } > %{buildroot}/kernel.list
94
95 %clean
96 rm -rf %{buildroot}
97
98 %post
99 if [ -x /usr/bin/kernel-install ]; then
100         /usr/bin/kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz
101 fi
102 for file in vmlinuz System.map config; do
103         if ! cmp --silent "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"; then
104                 cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"
105         fi
106 done
107 if [ -d "/lib/modules/%{KERNELRELEASE}/dtb" ] && \
108    ! diff -rq "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}" >/dev/null 2>&1; then
109         rm -rf "/boot/dtb-%{KERNELRELEASE}"
110         cp -r "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}"
111 fi
112 if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then
113         /usr/sbin/depmod %{KERNELRELEASE}
114 fi
115
116 %preun
117 if [ -x /usr/bin/kernel-install ]; then
118 kernel-install remove %{KERNELRELEASE}
119 fi
120
121 %files -f %{buildroot}/kernel.list
122 %defattr (-, root, root)
123 %exclude /kernel.list
124
125 %files headers
126 %defattr (-, root, root)
127 /usr/include
128
129 %if %{with_devel}
130 %files devel
131 %defattr (-, root, root)
132 /usr/src/kernels/%{KERNELRELEASE}
133 /lib/modules/%{KERNELRELEASE}/build
134 %endif