File kernel-default-image.spec of Package kernel-default-image
#
# spec file for package kernel-default-image
#
# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
# needssslcertforbuild
%bcond_with extra
%bcond_with optional
%bcond_with all
%bcond_with usb
%bcond_with virt
%bcond_with net
%bcond_with block
%bcond_with usb
%bcond_with fs
%bcond_with crypto
%bcond_with misc
# To be defined by user
%global build_flavor default
# variant includes dash: %%define variant -azure
%global variant %{nil}
%global subpackage image
%global extradescription This package contains only the kernel image
%global modversion %{rpm_kver}
# Reasonable defaults that might be overriden if needed
%global kernel_package_name kernel-%build_flavor
%global package_name %kernel_package_name-%subpackage
%global url %(rpm -q --qf '%%{URL}' %kernel_package_name)
%global group %(rpm -q --qf '%%{GROUP}' %kernel_package_name)
%global orig_summary %(rpm -q --qf '%%{SUMMARY}' %kernel_package_name)
%global rpm_kver %(rpm -q --qf '%%{VERSION}' %kernel_package_name)
%global rpm_krel %(rpm -q --qf '%%{RELEASE}' %kernel_package_name)
%global scriptdir /usr/lib/rpm/kernel
%global certs %(rpm -ql %kernel_package_name | sed -En 's,.*/(.*)[.]crt,\\1,p')%{nil}
# Module list (copied from kernel-default-base for now)
%global misc_modules button edd i6300esb efivarfs qemu_fw_cfg hid-generic iscsi_ibft
%global virtio_modules virtio virtio_.* virtio-.*
%global xen_modules xenblk xennet xen-.*
%global vmware_modules vmxnet3 vmw_.*
%global hyperv_modules hid-hyperv hv_balloon hv_utils \
hv_vmbus hyperv-keyboard hv_netvsc hv_storvsc scsi_transport_fc hyperv_fb
%global net_drivers 8390 ne2k-pci tulip e100 e1000 e1000e 8139cp 8139too
%global scsi_modules scsi_transport_iscsi sd_mod sg sr_mod st scsi_mod
%global block_drivers loop dm-mod libata libahci ahci ata_piix mptsas mptspi \
BusLogic sym53c8xx am53c974 rbd brd
%global usb_modules usb-common usbcore ehci-hcd ehci-pci ohci-hcd ohci-pci uhci-hcd \
xhci-hcd xhci-pci typec typec_ucsi ucsi_acpi typec ums-alauda ums-cypress ums-datafab \
ums-eneub6250 ums-freecom ums-isd200 ums-jumpshot ums-karma ums-onetouch \
ums-realtek ums-sddr09 ums-sddr55 ums-usbat usb-storage usbhid
%global filesystems autofs4 btrfs ext4 fuse vfat isofs jbd2 mbcache nfsv2 \
nfsv3 nfsv4 overlay xfs nls_cp437 nls_iso8859-1 nls_utf8 ceph cifs squashfs nfsd
%global networking \
af_packet arptable_filter arp_tables arpt_mangle bpfilter bridge br_netfilter \
cls_bpf ebt_.* ebtable_.* ebtables ip6table_.* ip6_tables ip6t_.* ip_.* ipt_.* iptable_.* \
nf_.* nfnetlink.* nft_.* openvswitch sch_ingress tun veth xfrm.*_tunnel xfrm_.* \
x_tables xt_.* tcp_diag vport-.* vxlan vport-.* wireguard
%global crypto_modules \
%(rpm -ql %{kernel_package_name} | grep -E 'kernel/crypto/|kernel/arch/.*/crypto/' | xargs basename -a | cut -d. -f1)
%global xmodules %usb_modules %net_drivers %scsi_modules %block_drivers \
%hyperv_modules %virtio_modules %vmware_modules %xen_modules \
%networking %filesystems %misc_modules %crypto_modules
# show me how to do this with line splitting
%global modules %{?with_all:.*}%{!?with_all:%{?with_virt:%virtio_modules %xen_modules %vmware_modules %hyperv_modules}}%{!?with_all:%{?with_net:%net_drivers %networking}}%{!?with_all:%{?with_block:%scsi_modules %block_drivers}}%{!?with_all:%{?with_usb:%usb_modules}}%{!?with_all:%{?with_fs:%filesystems}}%{!?with_all:%{?with_crypto:%crypto_modules}}%{!?with_all:%{?with_misc:%misc_modules}}
%ifarch %ix86 x86_64
%global image vmlinuz
%endif
%ifarch ppc ppc64 ppc64le
%global image vmlinux
%endif
%ifarch s390 s390x
%global image image
%endif
%ifarch %arm
%global image zImage
%endif
%ifarch aarch64 riscv64
%global image Image
%endif
%global uname_r %(rpm -ql %kernel_package_name | sed -En '/modules.dep$/{s,^.*/([^/]*)/.*,\\1,p;q;}')
%include /usr/lib/rpm/kernel/kernel-spec-macros
Name: %package_name
BuildRequires: %kernel_package_name
%if 0%{?with_extra}
BuildRequires: %{kernel_package_name}-extra
%endif
%if 0%{?with_optional}
BuildRequires: %{kernel_package_name}-optional
%endif
BuildRequires: %kernel_package_name-devel
BuildRequires: coreutils
BuildRequires: findutils
BuildRequires: grep
BuildRequires: kernel-subpackage-macros
Summary: %orig_summary - kernel image
License: GPL-2.0-only
Group: %group
URL: %url
Source0: kernel-subpackage-build
Source1: macros.modular-kernel
Source2: all-modules
Source3: find-supplements.ksyms
# override path REs from /usr/lib/rpm/fileattrs/{kernel,kmp}.attr
%global __kernel_path ^/boot/vmlinu[xz].*$
%global __kmp_path ^/lib/modules/[^/]*/(kernel|updates|extra)/.*\.ko(\.gz|\.xz|\.zst)?
%global __kmp_supplements %SOURCE3
# on SLE limit to architectures that actually have a kernel :-)
%if 0%{?sle_version}
ExclusiveArch: aarch64 armv7hl ppc64le s390x x86_64
%endif
Version: %rpm_kver
Release: %rpm_krel.<RELEASE>
%include %SOURCE1
# Force bzip2 instead of lzma compression to
# 1) allow install on older dist versions, and
# 2) decrease build times (bsc#962356)
# %%define _binary_payload w9.bzdio
# Do not recompute the build-id of vmlinux in find-debuginfo.sh (bsc#964063)
%undefine _unique_build_ids
%define _no_recompute_build_ids 1
# prevent usr/lib/debug/boot/vmlinux-4.12.14-11.10-default-4.12.14-11.10.ppc64le.debug
%undefine _unique_debug_names
%global kernel_requires %(rpm -q --queryformat '[%%{REQUIREFLAGS:deptype},%%{REQUIRENEVRS}\\n]' %kernel_package_name | grep -vE 'rpmlib,|interp,' | grep -E 'manual,' | sed -e 's/.*,//' | tr '\\n' ' ')
%global kernel_requires_pre %(rpm -q --queryformat '[%%{REQUIREFLAGS:deptype},%%{REQUIRENEVRS}\\n]' %kernel_package_name | grep -vE 'rpmlib,|interp,' | grep -E 'pre,' | sed -e 's/.*,//' | tr '\\n' ' ')
%global kernel_requires_preun %(rpm -q --queryformat '[%%{REQUIREFLAGS:deptype},%%{REQUIRENEVRS}\\n]' %kernel_package_name | grep -vE 'rpmlib,|interp,' | grep -E 'preun,' | sed -e 's/.*,//' | tr '\\n' ' ')
%global kernel_requires_post %(rpm -q --queryformat '[%%{REQUIREFLAGS:deptype},%%{REQUIRENEVRS}\\n]' %kernel_package_name | grep -vE 'rpmlib,|interp,' | grep -E 'post,' | sed -e 's/.*,//' | tr '\\n' ' ')
%global kernel_requires_postun %(rpm -q --queryformat '[%%{REQUIREFLAGS:deptype},%%{REQUIRENEVRS}\\n]' %kernel_package_name | grep -vE 'rpmlib,|interp,' | grep -E 'postun,' | sed -e 's/.*,//' | tr '\\n' ' ')
%global kernel_base_provides %(rpm -q --queryformat '[%%{PROVIDENEVRS}\\n]' %kernel_package_name | sed -E 's/^%kernel_package_name(-srchash| =)/%name\\1/g' | grep -vE '^(ksym|kmod|firmware)[(]' | tr '\\n' ' )')
%global kernel_base_obsoletes %(rpm -q --queryformat '[%%{OBSOLETENEVRS}\\n]' %kernel_package_name | sed -E 's/^%kernel_package_name(-srchash| =)/%name\\1/g' | grep -vE '^(ksym|kmod|firmware)[(]' | tr '\\n' ' )')
%global kernel_base_conflicts %(rpm -q --queryformat '[%%{CONFLICTNEVRS}\\n]' %kernel_package_name | grep -vE '^(ksym|kmod|firmware)[(]' | tr '\\n' ' )')
%global kernel_base_recommends %(rpm -q --queryformat '[%%{RECOMMENDNEVRS}\\n]' %kernel_package_name | grep -v '^kernel-firmware' | grep -vE '^(ksym|kmod|firmware)[(]' | tr '\\n' ' )')
%if ! %(expr 1 - 1)
%if "%{kernel_requires}" != ""
Requires: %kernel_requires
%endif
%if "%{kernel_requires_pre}" != ""
Requires(pre): %kernel_requires_pre
%endif
%if "%{kernel_requires_preun}" != ""
Requires(preun):%kernel_requires_preun
%endif
%if "%{kernel_requires_post}" != ""
Requires(post): %kernel_requires_post
%endif
%if "%{kernel_requires_postun}" != ""
Requires(postun):%kernel_requires_postun
%endif
%endif
%if "%{kernel_base_provides}" != ""
Provides: %{kernel_base_provides}
%endif
%if "%{kernel_base_obsoletes}" != ""
Obsoletes: %{kernel_base_obsoletes}
%endif
%if "%{kernel_base_conflicts}" != ""
Conflicts: %{kernel_base_conflicts}
%endif
%if "%{kernel_base_recommends}" != ""
Recommends: %{kernel_base_recommends}
%endif
# This should give Conflicts: %%kernel_package_name = %%source_rel as old
# kernel-default-base did. Together with the %%obsolete_rebuilds translated
# from %%kernel_package_name to %%name we should be set for obsoletes against
# kernel rebuilds.
Conflicts: %(rpm -q --queryformat '[%%{PROVIDENEVRS}\n]' %kernel_package_name | grep '^%kernel_package_name =' | sort -V | head -n 1)
# To protect against obsolete rebuilds of self we need a provide equivalent to
# %%source_rel on this package version, and do obsolete of lower upload numbers
# and lower rebuild numbers of %%name built against same kernel.
# The %%source-rel is calculated from the subpackage version here.
Provides: %name = %version-%source_rel
%obsolete_rebuilds_subpackage %name
%description
%(rpm -q --qf '%%{DESCRIPTION}' %kernel_package_name)
%extradescription
This is a subpackage of %kernel_package_name. Development files are in
%kernel_package_name-devel, sources in kernel-source%variant, and
debug information in %kernel_package_name-debuginfo.
%package rebuild
Summary: Empty package to ensure rebuilding %name in OBS
Group: Other
Requires: %kernel_package_name = %rpm_kver-%rpm_krel
%description rebuild
This is empty package that ensures %name is rebuilt every time
%kernel_package_name is rebuilt in OBS.
There is no reason to install this package.
%files rebuild
# This line expands the list of modules plus dependencies
%prep
chmod a+x %SOURCE0 %SOURCE3
%build
%install
%global all_modules %(echo "%{modules}" | /bin/bash %{SOURCE2} %{uname_r})
echo === MODULES: "%{modules}" ===
echo === ALL MODULES: "%{all_modules}" ===
SCRIPTDIR=%scriptdir \
%SOURCE0 %kernel_package_name %rpm_kver-%rpm_krel %package_name-%version-%release >/dev/null 2>&1
echo "%{all_modules}" | xargs -r /sbin/modinfo -F filename | cpio -pd $RPM_BUILD_ROOT
%if 0%{?usrmerged}
ln -s usr/lib $RPM_BUILD_ROOT/lib
%get_moderr moderr
rm $RPM_BUILD_ROOT/lib
%else
%get_moderr moderr
%endif
if [ "$moderr" ] ; then
echo Picked modules have errors:
echo $moderr
exit 1
fi
# This line expands the list of subpackages (one per module)
%module_subpackages -f %{build_flavor} -v %{modversion} -k %{uname_r} %{all_modules}
%pre -f prein.sh
%post -f postin.sh
%preun -f preun.sh
%postun -f postun.sh
%posttrans -f posttrans.sh
%files -f subpackage.flist
%changelog