kbuild: refactor kernel-devel RPM package and linux-headers Deb package
[platform/kernel/linux-starfive.git] / scripts / package / mkspec
1 #!/bin/sh
2 #
3 #       Output a simple RPM spec file.
4 #       This version assumes a minimum of RPM 4.13
5 #
6 #       The only gothic bit here is redefining install_post to avoid
7 #       stripping the symbols from files in the kernel which we want
8 #
9 #       Patched for non-x86 by Opencon (L) 2002 <opencon@rio.skydome.net>
10 #
11
12 # how we were called determines which rpms we build and how we build them
13 if [ "$1" = prebuilt ]; then
14         S=DEL
15 else
16         S=
17
18         mkdir -p rpmbuild/SOURCES
19         cp linux.tar.gz rpmbuild/SOURCES
20         cp "${KCONFIG_CONFIG}" rpmbuild/SOURCES/config
21         "${srctree}/scripts/package/gen-diff-patch" rpmbuild/SOURCES/diff.patch
22 fi
23
24 if grep -q CONFIG_MODULES=y include/config/auto.conf; then
25         M=
26 else
27         M=DEL
28 fi
29
30 __KERNELRELEASE=$(echo $KERNELRELEASE | sed -e "s/-/_/g")
31
32 # We can label the here-doc lines for conditional output to the spec file
33 #
34 # Labels:
35 #  $S: this line is enabled only when building source package
36 #  $M: this line is enabled only when CONFIG_MODULES is enabled
37 sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
38 %define ARCH ${ARCH}
39 %define KERNELRELEASE ${KERNELRELEASE}
40
41 %{!?make: %define make make}
42 %define makeflags %{?_smp_mflags} ARCH=%{ARCH}
43
44         Name: kernel
45         Summary: The Linux Kernel
46         Version: $__KERNELRELEASE
47         Release: $(cat .version 2>/dev/null || echo 1)
48         License: GPL
49         Group: System Environment/Kernel
50         Vendor: The Linux Community
51         URL: https://www.kernel.org
52 $S      Source0: linux.tar.gz
53 $S      Source1: config
54 $S      Source2: diff.patch
55         Provides: kernel-%{KERNELRELEASE}
56 $S      BuildRequires: bc binutils bison dwarves
57 $S      BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
58 $S      BuildRequires: gcc make openssl openssl-devel perl python3 rsync
59
60         # $UTS_MACHINE as a fallback of _arch in case
61         # /usr/lib/rpm/platform/*/macros was not included.
62         %{!?_arch: %define _arch $UTS_MACHINE}
63         %define __spec_install_post /usr/lib/rpm/brp-compress || :
64         %define debug_package %{nil}
65
66         %description
67         The Linux Kernel, the operating system core itself
68
69         %package headers
70         Summary: Header files for the Linux kernel for use by glibc
71         Group: Development/System
72         Obsoletes: kernel-headers
73         Provides: kernel-headers = %{version}
74         %description headers
75         Kernel-headers includes the C header files that specify the interface
76         between the Linux kernel and userspace libraries and programs.  The
77         header files define structures and constants that are needed for
78         building most standard programs and are also needed for rebuilding the
79         glibc package.
80
81 $S$M    %package devel
82 $S$M    Summary: Development package for building kernel modules to match the %{version} kernel
83 $S$M    Group: System Environment/Kernel
84 $S$M    AutoReqProv: no
85 $S$M    %description -n kernel-devel
86 $S$M    This package provides kernel headers and makefiles sufficient to build modules
87 $S$M    against the %{version} kernel package.
88 $S$M
89 $S      %prep
90 $S      %setup -q -n linux
91 $S      cp %{SOURCE1} .config
92 $S      patch -p1 < %{SOURCE2}
93 $S
94 $S      %build
95 $S      %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release}
96 $S
97         %install
98         mkdir -p %{buildroot}/boot
99         %ifarch ia64
100         mkdir -p %{buildroot}/boot/efi
101         cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/efi/vmlinuz-%{KERNELRELEASE}
102         ln -s efi/vmlinuz-%{KERNELRELEASE} %{buildroot}/boot/
103         %else
104         cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-%{KERNELRELEASE}
105         %endif
106 $M      %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install
107         %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
108         cp System.map %{buildroot}/boot/System.map-%{KERNELRELEASE}
109         cp .config %{buildroot}/boot/config-%{KERNELRELEASE}
110 $S$M    rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/build
111 $S$M    rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/source
112 $S$M    %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='\${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
113 $S$M    cd %{buildroot}/lib/modules/%{KERNELRELEASE}
114 $S$M    ln -sf /usr/src/kernels/%{KERNELRELEASE} build
115 $S$M    ln -sf /usr/src/kernels/%{KERNELRELEASE} source
116
117         %clean
118         rm -rf %{buildroot}
119
120         %post
121         if [ -x /sbin/installkernel -a -r /boot/vmlinuz-%{KERNELRELEASE} -a -r /boot/System.map-%{KERNELRELEASE} ]; then
122         cp /boot/vmlinuz-%{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm
123         cp /boot/System.map-%{KERNELRELEASE} /boot/.System.map-%{KERNELRELEASE}-rpm
124         rm -f /boot/vmlinuz-%{KERNELRELEASE} /boot/System.map-%{KERNELRELEASE}
125         /sbin/installkernel %{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm
126         rm -f /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm
127         fi
128
129         %preun
130         if [ -x /sbin/new-kernel-pkg ]; then
131         new-kernel-pkg --remove %{KERNELRELEASE} --rminitrd --initrdfile=/boot/initramfs-%{KERNELRELEASE}.img
132         elif [ -x /usr/bin/kernel-install ]; then
133         kernel-install remove %{KERNELRELEASE}
134         fi
135
136         %postun
137         if [ -x /sbin/update-bootloader ]; then
138         /sbin/update-bootloader --remove %{KERNELRELEASE}
139         fi
140
141         %files
142         %defattr (-, root, root)
143 $M      /lib/modules/%{KERNELRELEASE}
144 $M      %exclude /lib/modules/%{KERNELRELEASE}/build
145 $M      %exclude /lib/modules/%{KERNELRELEASE}/source
146         /boot/*
147
148         %files headers
149         %defattr (-, root, root)
150         /usr/include
151 $S$M
152 $S$M    %files devel
153 $S$M    %defattr (-, root, root)
154 $S$M    /usr/src/kernels/%{KERNELRELEASE}
155 $S$M    /lib/modules/%{KERNELRELEASE}/build
156 $S$M    /lib/modules/%{KERNELRELEASE}/source
157 EOF