File kernel-rt.spec of Package kernel-rt

%define linux 4.4.112
%define preempt rt127

# found this ref with general notes on SUSE kernels
# http://www.suse.de/~agruen/kernel-doc/
# /usr/share/doc/packages/kernel-source/README.SUSE

# some documentation on version numbers
#
# %%linux            Linux kernel base version, e.g. 3.4.32
#
# %%preempt          Preemption patch version, e.g. rt45
#
# %%version	     Linux version number _ rt version number, e.g. 3.4.32_rt45
#
# %%source_rel	     major release, e.g. 1, when release is 1.3
#
# %%localversion     Added to the .config file, major release - variant, 
#                    e.g. 1-preempt_rt. The variant is used to add this 
#                    kernel to the boot menu on SUSE distributions.
#
# %%kernelrelease    Linux version number - rt version - localversion
#                    e.g. 3.4.32-rt45-1-preempt_rt. This is also where
# 		     you find modules under /lib/modules
#
# The file localversion-rt will be added by the preempt_rt patch, and
# contains for example "-rt45" Together with major version, and
# localversion in the .config file, the kernel scripts calculate
# kernelrelease from this file

# Note that include/config/kernel.release in the kernel source dir
# will contain the final release string, easy if you need to determine
# this release string in a module package

# My main motivation to build this kernel series is to use them in our
# simulation facilities, in combination with EtherCat IO hardware. The
# major kernel version (e.g., 3.4 as of feb 2013) is selected to have
# as many available ethercat master drivers as possible

# Hint: to re-create the config for 32 bit arch, when on a 64 bit
# machine, run make oldconfig SUBARCH=i386

# Another Hint: The kernel debug option is deselected to provide a
# possibility to create an nvidia kernel module; nvidia license is
# incompatible with the dump_page symbol generated when kernel debug
# is selected.

# the openSUSE kernel sym "provides" calculation depends on the following:
# * Having a /boot/vmlinux-%%{kernelrelease}.gz file,
#   basically a zipped kernel file. The variant (in this case preempt_rt), is
#   used as prefix for the ksyms
# * Having /lib/modules/%%{kernelrelease}/...*.ko files. The variant/last part
#   of the %%{kernelrelease} is again prefix for the ksyms

# Although SUSE likes to keep the different kernel variant versions
# synchronized with the default kernel version, this is not possible
# for the preempt_rt kernels, because of availability of the
# preempt_rt patch for only select kernel base versions. Therefore
# these kernels run slightly out of sync

%define _buildshell /bin/bash
%define source_rel %(echo %release | cut --delim=. -f 1)
%define localversion -%{source_rel}-rt
%define kernelrelease %{linux}-%{preempt}%{localversion}

Name: kernel-rt
Summary: Kernel and modules for realtime operation
Version: %{linux}_%{preempt}
Release: 1
License: GPL-2.0
Group: System/Kernel
URL: http://rt.wiki.kernel.org/
Source0: linux-%{linux}.tar.xz
Source1: linux-%{linux}-%{preempt}.config
Patch: patch-%{linux}-%{preempt}.patch.xz
Prereq: /sbin/ldconfig
BuildRequires: gcc gcc-c++ coreutils module-init-tools
BuildRequires: bc
Requires: irqbalance
BuildRequires:  makedumpfile
BuildRequires:  fdupes
Requires(pre): coreutils gawk
Requires(post): module-init-tools
Requires(post): /sbin/depmod
Requires(post): mkinitrd
Requires(post): perl-Bootloader
Prereq: fileutils
Prereq: module-init-tools
Prereq: mkinitrd
BuildRoot: %{_tmppath}/%{name}-%{version}-build

%description
This is a kernel package with the PREEMPT_RT patch applied. The 
preempt_rt patch provides preemption for most parts of the kernel, making
this kernel excellent for producing short latency responses, and a bit worse
for overall throughput.

%package headers
Summary: Development headers for the Linux kernel
Group: System/Kernel
Exclusivearch: x86_64

%description headers
Kernel headers for the kernel with PREEMPT_RT patch applied. Includes a 
.config, and should provide all needed files to build external modules

%package firmware
Summary: Firmware files for the PREEMPT_RT kernel
Group: System/Kernel
Enhances: %{name} = %{version}

%description firmware
Firmware files for the kernel with PREEMPT_RT patch applied

%prep
%setup -n linux-%{linux}
%patch -p1

# copy the config, adjust CONFIG_LOCALVERSION, Together with
# localversion-rt, this ensures a unique kernel
# version string, equal to %%kernelversion
sed -e "s@CONFIG_LOCALVERSION=.*\$@CONFIG_LOCALVERSION=\"%{localversion}\"@" \
    %{SOURCE1} > .config

chmod -x scripts/sign-file.c

%build

make oldconfig
make bzImage modules %{?_smp_flags}

%install

rm -rf %buildroot

install -d %buildroot/boot
install -d %buildroot/lib/modules
make modules_install INSTALL_MOD_PATH=%buildroot INSTALL_MOD_STRIP=1
install -m 644 arch/$RPM_ARCH/boot/bzImage \
    %buildroot/boot/vmlinuz-%{kernelrelease}
install -m 644 System.map \
    %buildroot/boot/System.map-%{kernelrelease}
install -m 444 .config \
    %buildroot/boot/config-%{kernelrelease}

find %buildroot/lib/modules/ -name "*.ko" -type f >modnames
xargs --no-run-if-empty chmod u+x < modnames

cat Module.symvers | gzip -9 >%buildroot/boot/symvers-%{kernelrelease}.gz

# build and source currently point to the build directory here. Not good
rm -f %buildroot/lib/modules/%{kernelrelease}/build
rm -f %buildroot/lib/modules/%{kernelrelease}/source
ln -sf /usr/src/linux-%{version} %buildroot/lib/modules/%{kernelrelease}/build
ln -sf build %buildroot/lib/modules/%{kernelrelease}/source 

# make directories for external modules
mkdir -p %buildroot/lib/modules/%{kernelrelease}/extra
mkdir -p %buildroot/lib/modules/%{kernelrelease}/updates

# directory with necessary sources for building additional modules
install -d %buildroot/usr/src/linux-%{version}
# copy kernel headers
tar cvf - include | (cd %buildroot/usr/src/linux-%{version} && tar xf -)
# and the scripts directory
tar cvf - scripts | (cd %buildroot/usr/src/linux-%{version} && tar xf -)
# and all makefile and Kconfig files, with parents. The main Makefile
# has these as targets
cp --parents `find . -type f -name "Makefile*" -o -name "Kconfig*"` \
     %buildroot/usr/src/linux-%{version}
# copy the x86 architecture headers (add others, if you want more archs)
tar cvf - arch/x86/include | \
    (cd %buildroot/usr/src/linux-%{version} && tar xf -)

cp Module.symvers %buildroot/usr/src/linux-%{version}
cp System.map %buildroot/usr/src/linux-%{version}
cp .config %buildroot/usr/src/linux-%{version}
cp localversion-rt %buildroot/usr/src/linux-%{version}

# Make sure the Makefile and generated files have a matching timestamp so that
# external modules can be built
GENF=`find  %buildroot/usr/src/linux-%{version}/include/generated -name *.h`
for G in $GENF %buildroot/usr/src/linux-%{version}/.config; do
    touch -r %buildroot/usr/src/linux-%{version}/Makefile $G
done

# remove various types of junk
for i in .gitignore .install ..install.cmd; do
    find %buildroot/usr/src/linux-%{version} -name "$i" -exec rm {} \;
done

# de-duplicate files
%if 0%{?suse_version}
%fdupes -s %buildroot/usr/src/linux-%{version}
%else
fdupes -s %buildroot/usr/src/linux-%{version}
%endif

# move firmware files to version specific dir
FFILES=$(ls -C %buildroot/lib/firmware)
install -d %buildroot/lib/firmware/%{kernelrelease}
(cd %buildroot/lib/firmware && mv $FFILES %{kernelrelease})

# remove modules.dep, will be created in post script
rm %buildroot/lib/modules/*/modules.dep

# vmlinux for dependency calculation
cp vmlinux %buildroot/boot/vmlinux-%{kernelrelease}
gzip -n -9 %buildroot/boot/vmlinux-%{kernelrelease}
chmod a-x %buildroot/boot/vmlinux-%{kernelrelease}.gz


%postun
# remove the initrd file
rm -f /boot/initrd-%{kernelrelease}

# remove entry from bootloader
if [ -x /usr/lib/bootloader/bootloader_entry ]; then
   /usr/lib/bootloader/bootloader_entry remove \
   					preempt \
   					%{kernelrelease} \
   					vmlinuz-%{kernelrelease} \
   					initrd-%{kernelrelease} \
   					no-default
else
   echo "Manually remove %{kernelrelease} entry from bootloader"
fi

%post
export PBL_SKIP_BOOT_TEST=1
/sbin/depmod -a -F /boot/System.map-%{kernelrelease} %{kernelrelease}

if [ -f /etc/fstab -a ! -e /.buildenv -a -x /sbin/mkinitrd ] ; then
   tmp_dir=/dev/shm /sbin/mkinitrd -k /boot/vmlinuz-%{kernelrelease} \
   		  -M /boot/System.map-%{kernelrelease} \
   		  -i /boot/initrd-%{kernelrelease}
else
   echo "Cannot find mkinitrd"
fi

if [ -x /usr/lib/bootloader/bootloader_entry ]; then
   /usr/lib/bootloader/bootloader_entry add \
   					preempt \
   					%{kernelrelease} \
   					vmlinuz-%{kernelrelease} \
   					initrd-%{kernelrelease} \
   					no-default
else
   echo "Manually add %{kernelrelease} entry to bootloader"
fi

%clean
[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
%doc README
%dir /lib/modules/%{kernelrelease}
/lib/modules/%{kernelrelease}/modules.*
/lib/modules/%{kernelrelease}/kernel
/lib/modules/%{kernelrelease}/extra
/lib/modules/%{kernelrelease}/updates
/boot/System.map-%{kernelrelease}
/boot/config-%{kernelrelease}
/boot/vmlinuz-%{kernelrelease}
/boot/symvers-%{kernelrelease}.gz
/boot/vmlinux-%{kernelrelease}.gz

%files firmware
%defattr(-,root,root,-)
/lib/firmware/%{kernelrelease}

%files headers
%defattr(-,root,root,-)
/usr/src/linux-%{version}
/lib/modules/%{kernelrelease}/build
/lib/modules/%{kernelrelease}/source

%changelog
* Fri Feb  6 2009 Rene van Paassen <Rene.vanPaassen@gmail.com> 2.6.26.8_rt15-2
- removed latency and mutex debug options

* Wed Feb  4 2009 Rene van Paassen <Rene.vanPaassen@gmail.com> 2.6.26.8_rt15-1
- initial version

openSUSE Build Service is sponsored by