18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci#
38c2ecf20Sopenharmony_ci#	Output a simple RPM spec file.
48c2ecf20Sopenharmony_ci#	This version assumes a minimum of RPM 4.0.3.
58c2ecf20Sopenharmony_ci#
68c2ecf20Sopenharmony_ci#	The only gothic bit here is redefining install_post to avoid
78c2ecf20Sopenharmony_ci#	stripping the symbols from files in the kernel which we want
88c2ecf20Sopenharmony_ci#
98c2ecf20Sopenharmony_ci#	Patched for non-x86 by Opencon (L) 2002 <opencon@rio.skydome.net>
108c2ecf20Sopenharmony_ci#
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci# how we were called determines which rpms we build and how we build them
138c2ecf20Sopenharmony_ciif [ "$1" = prebuilt ]; then
148c2ecf20Sopenharmony_ci	S=DEL
158c2ecf20Sopenharmony_ci	MAKE="$MAKE -f $srctree/Makefile"
168c2ecf20Sopenharmony_cielse
178c2ecf20Sopenharmony_ci	S=
188c2ecf20Sopenharmony_cifi
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciif grep -q CONFIG_MODULES=y .config; then
218c2ecf20Sopenharmony_ci	M=
228c2ecf20Sopenharmony_cielse
238c2ecf20Sopenharmony_ci	M=DEL
248c2ecf20Sopenharmony_cifi
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciif grep -q CONFIG_DRM=y .config; then
278c2ecf20Sopenharmony_ci	PROVIDES=kernel-drm
288c2ecf20Sopenharmony_cifi
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciPROVIDES="$PROVIDES kernel-$KERNELRELEASE"
318c2ecf20Sopenharmony_ci__KERNELRELEASE=$(echo $KERNELRELEASE | sed -e "s/-/_/g")
328c2ecf20Sopenharmony_ciEXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \
338c2ecf20Sopenharmony_ci--exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation \
348c2ecf20Sopenharmony_ci--exclude=.config.old --exclude=.missing-syscalls.d --exclude=*.s"
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci# We can label the here-doc lines for conditional output to the spec file
378c2ecf20Sopenharmony_ci#
388c2ecf20Sopenharmony_ci# Labels:
398c2ecf20Sopenharmony_ci#  $S: this line is enabled only when building source package
408c2ecf20Sopenharmony_ci#  $M: this line is enabled only when CONFIG_MODULES is enabled
418c2ecf20Sopenharmony_cised -e '/^DEL/d' -e 's/^\t*//' <<EOF
428c2ecf20Sopenharmony_ci	Name: kernel
438c2ecf20Sopenharmony_ci	Summary: The Linux Kernel
448c2ecf20Sopenharmony_ci	Version: $__KERNELRELEASE
458c2ecf20Sopenharmony_ci	Release: $(cat .version 2>/dev/null || echo 1)
468c2ecf20Sopenharmony_ci	License: GPL
478c2ecf20Sopenharmony_ci	Group: System Environment/Kernel
488c2ecf20Sopenharmony_ci	Vendor: The Linux Community
498c2ecf20Sopenharmony_ci	URL: https://www.kernel.org
508c2ecf20Sopenharmony_ci$S	Source: kernel-$__KERNELRELEASE.tar.gz
518c2ecf20Sopenharmony_ci	Provides: $PROVIDES
528c2ecf20Sopenharmony_ci	%define __spec_install_post /usr/lib/rpm/brp-compress || :
538c2ecf20Sopenharmony_ci	%define debug_package %{nil}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	%description
568c2ecf20Sopenharmony_ci	The Linux Kernel, the operating system core itself
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	%package headers
598c2ecf20Sopenharmony_ci	Summary: Header files for the Linux kernel for use by glibc
608c2ecf20Sopenharmony_ci	Group: Development/System
618c2ecf20Sopenharmony_ci	Obsoletes: kernel-headers
628c2ecf20Sopenharmony_ci	Provides: kernel-headers = %{version}
638c2ecf20Sopenharmony_ci	%description headers
648c2ecf20Sopenharmony_ci	Kernel-headers includes the C header files that specify the interface
658c2ecf20Sopenharmony_ci	between the Linux kernel and userspace libraries and programs.  The
668c2ecf20Sopenharmony_ci	header files define structures and constants that are needed for
678c2ecf20Sopenharmony_ci	building most standard programs and are also needed for rebuilding the
688c2ecf20Sopenharmony_ci	glibc package.
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci$S$M	%package devel
718c2ecf20Sopenharmony_ci$S$M	Summary: Development package for building kernel modules to match the $__KERNELRELEASE kernel
728c2ecf20Sopenharmony_ci$S$M	Group: System Environment/Kernel
738c2ecf20Sopenharmony_ci$S$M	AutoReqProv: no
748c2ecf20Sopenharmony_ci$S$M	%description -n kernel-devel
758c2ecf20Sopenharmony_ci$S$M	This package provides kernel headers and makefiles sufficient to build modules
768c2ecf20Sopenharmony_ci$S$M	against the $__KERNELRELEASE kernel package.
778c2ecf20Sopenharmony_ci$S$M
788c2ecf20Sopenharmony_ci$S	%prep
798c2ecf20Sopenharmony_ci$S	%setup -q
808c2ecf20Sopenharmony_ci$S
818c2ecf20Sopenharmony_ci$S	%build
828c2ecf20Sopenharmony_ci$S	$MAKE %{?_smp_mflags} KBUILD_BUILD_VERSION=%{release}
838c2ecf20Sopenharmony_ci$S
848c2ecf20Sopenharmony_ci	%install
858c2ecf20Sopenharmony_ci	mkdir -p %{buildroot}/boot
868c2ecf20Sopenharmony_ci	%ifarch ia64
878c2ecf20Sopenharmony_ci	mkdir -p %{buildroot}/boot/efi
888c2ecf20Sopenharmony_ci	cp \$($MAKE -s image_name) %{buildroot}/boot/efi/vmlinuz-$KERNELRELEASE
898c2ecf20Sopenharmony_ci	ln -s efi/vmlinuz-$KERNELRELEASE %{buildroot}/boot/
908c2ecf20Sopenharmony_ci	%else
918c2ecf20Sopenharmony_ci	cp \$($MAKE -s image_name) %{buildroot}/boot/vmlinuz-$KERNELRELEASE
928c2ecf20Sopenharmony_ci	%endif
938c2ecf20Sopenharmony_ci$M	$MAKE %{?_smp_mflags} INSTALL_MOD_PATH=%{buildroot} modules_install
948c2ecf20Sopenharmony_ci	$MAKE %{?_smp_mflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
958c2ecf20Sopenharmony_ci	cp System.map %{buildroot}/boot/System.map-$KERNELRELEASE
968c2ecf20Sopenharmony_ci	cp .config %{buildroot}/boot/config-$KERNELRELEASE
978c2ecf20Sopenharmony_ci	bzip2 -9 --keep vmlinux
988c2ecf20Sopenharmony_ci	mv vmlinux.bz2 %{buildroot}/boot/vmlinux-$KERNELRELEASE.bz2
998c2ecf20Sopenharmony_ci$S$M	rm -f %{buildroot}/lib/modules/$KERNELRELEASE/build
1008c2ecf20Sopenharmony_ci$S$M	rm -f %{buildroot}/lib/modules/$KERNELRELEASE/source
1018c2ecf20Sopenharmony_ci$S$M	mkdir -p %{buildroot}/usr/src/kernels/$KERNELRELEASE
1028c2ecf20Sopenharmony_ci$S$M	tar cf - $EXCLUDES . | tar xf - -C %{buildroot}/usr/src/kernels/$KERNELRELEASE
1038c2ecf20Sopenharmony_ci$S$M	cd %{buildroot}/lib/modules/$KERNELRELEASE
1048c2ecf20Sopenharmony_ci$S$M	ln -sf /usr/src/kernels/$KERNELRELEASE build
1058c2ecf20Sopenharmony_ci$S$M	ln -sf /usr/src/kernels/$KERNELRELEASE source
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	%clean
1088c2ecf20Sopenharmony_ci	rm -rf %{buildroot}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	%post
1118c2ecf20Sopenharmony_ci	if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then
1128c2ecf20Sopenharmony_ci	cp /boot/vmlinuz-$KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm
1138c2ecf20Sopenharmony_ci	cp /boot/System.map-$KERNELRELEASE /boot/.System.map-$KERNELRELEASE-rpm
1148c2ecf20Sopenharmony_ci	rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE
1158c2ecf20Sopenharmony_ci	/sbin/installkernel $KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm
1168c2ecf20Sopenharmony_ci	rm -f /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm
1178c2ecf20Sopenharmony_ci	fi
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	%preun
1208c2ecf20Sopenharmony_ci	if [ -x /sbin/new-kernel-pkg ]; then
1218c2ecf20Sopenharmony_ci	new-kernel-pkg --remove $KERNELRELEASE --rminitrd --initrdfile=/boot/initramfs-$KERNELRELEASE.img
1228c2ecf20Sopenharmony_ci	elif [ -x /usr/bin/kernel-install ]; then
1238c2ecf20Sopenharmony_ci	kernel-install remove $KERNELRELEASE
1248c2ecf20Sopenharmony_ci	fi
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	%postun
1278c2ecf20Sopenharmony_ci	if [ -x /sbin/update-bootloader ]; then
1288c2ecf20Sopenharmony_ci	/sbin/update-bootloader --remove $KERNELRELEASE
1298c2ecf20Sopenharmony_ci	fi
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	%files
1328c2ecf20Sopenharmony_ci	%defattr (-, root, root)
1338c2ecf20Sopenharmony_ci$M	/lib/modules/$KERNELRELEASE
1348c2ecf20Sopenharmony_ci$M	%exclude /lib/modules/$KERNELRELEASE/build
1358c2ecf20Sopenharmony_ci$M	%exclude /lib/modules/$KERNELRELEASE/source
1368c2ecf20Sopenharmony_ci	/boot/*
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	%files headers
1398c2ecf20Sopenharmony_ci	%defattr (-, root, root)
1408c2ecf20Sopenharmony_ci	/usr/include
1418c2ecf20Sopenharmony_ci$S$M
1428c2ecf20Sopenharmony_ci$S$M	%files devel
1438c2ecf20Sopenharmony_ci$S$M	%defattr (-, root, root)
1448c2ecf20Sopenharmony_ci$S$M	/usr/src/kernels/$KERNELRELEASE
1458c2ecf20Sopenharmony_ci$S$M	/lib/modules/$KERNELRELEASE/build
1468c2ecf20Sopenharmony_ci$S$M	/lib/modules/$KERNELRELEASE/source
1478c2ecf20Sopenharmony_ciEOF
148