linuxtorvalds / rpms / kernel

Forked from rpms/kernel 2 years ago
Clone
Justin Vreeland 794d92
#!/bin/bash
Justin Vreeland 794d92
#
Justin Vreeland 794d92
# This script is aimed at generating the headers from the kernel sources.
Justin Vreeland 794d92
# You should have a checkout of kernel-headers inside the kernel directory 'fedpkg clone kernel-headers'
Justin Vreeland 794d92
# You will need to prep the kernel sources with 'make prep' or 'fedpkg prep' before running this script
Justin Vreeland 794d92
#
Justin Vreeland 794d92
# Author: Herton R. Krzesinski <herton@redhat.com>
Justin Vreeland 794d92
# Author: Justin M. Forbes <jforbes@redhat.com>
Justin Vreeland 794d92
Justin Vreeland 794d92
set -e
Justin Vreeland 794d92
Justin Vreeland 794d92
# Location of kernel-headers checkout
Justin Vreeland 794d92
CURRENTDIR=`pwd`
Justin Vreeland 794d92
PKGLOC='kernel-headers'
Justin Vreeland 794d92
Justin Vreeland 794d92
if [ ! -f $PKGLOC/kernel-headers.spec ]; then
Justin Vreeland 794d92
	echo "Missing checkout of kernel-headers in $PKGLOC"
Justin Vreeland 794d92
	exit 1
Justin Vreeland 794d92
fi
Justin Vreeland 794d92
Justin Vreeland 794d92
# Kernel version information taken from kernel.spec and change to prepared sources directory
Justin Vreeland 794d92
MAJORVER='5'
Justin Vreeland 794d92
RELEASED=`grep "%global released_kernel" kernel.spec| cut -d ' ' -f 3`
Justin Vreeland 794d92
BASERELEASE=`cat kernel.spec | grep "%global baserelease" | cut -d ' ' -f 3`
Justin Vreeland 794d92
BASE=`grep "%define base_sublevel" kernel.spec| cut -d ' ' -f 3`
Justin Vreeland 794d92
STABLE=`grep "%define stable_update" kernel.spec| cut -d ' ' -f 3`
Justin Vreeland 794d92
RC=`grep "%global rcrev" kernel.spec| cut -d ' ' -f 3`
Justin Vreeland 794d92
GITREV=`grep "%define gitrev" kernel.spec| cut -d ' ' -f 3`
Justin Vreeland 794d92
BUILDID=`grep "^%define buildid" kernel.spec| cut -d ' ' -f 3`
Justin Vreeland 794d92
if [ $RELEASED -eq 0 ]; then
Justin Vreeland 794d92
	cd kernel-$MAJORVER.$BASE.fc??
Justin Vreeland 794d92
	NEWBASE=$(($BASE+1))
Justin Vreeland 794d92
	KVER=$MAJORVER.$NEWBASE.0-0.rc$RC.git$GITREV
Justin Vreeland 794d92
	cd linux-$MAJORVER.$NEWBASE.0-0.rc$RC.git$GITREV.$BASERELEASE$BUILDID.fc*/
Justin Vreeland 794d92
else
Justin Vreeland 794d92
	cd kernel-$MAJORVER.$BASE.fc??/linux-$MAJORVER.$BASE.$STABLE-$BASERELEASE$BUILDID.fc*/
Justin Vreeland 794d92
	KVER=$MAJORVER.$BASE.$STABLE
Justin Vreeland 794d92
fi
Justin Vreeland 794d92
Justin Vreeland 794d92
# ARCH_LIST below has the default list of supported architectures
Justin Vreeland 794d92
# (the architectures names may be different from rpm, you list here the
Justin Vreeland 794d92
# names of arch/<arch> directories in the kernel sources)
Justin Vreeland 794d92
ARCH_LIST="arm arm64 powerpc riscv s390 x86"
Justin Vreeland 794d92
Justin Vreeland 794d92
headers_dir=$(mktemp -d)
Justin Vreeland 794d92
trap 'rm -rf "$headers_dir"' SIGHUP SIGINT SIGTERM EXIT
Justin Vreeland 794d92
Justin Vreeland 794d92
archs=${ARCH_LIST:-$(ls arch)}
Justin Vreeland 794d92
echo $archs
Justin Vreeland 794d92
Justin Vreeland 794d92
# Upstream rmeoved the headers_install_all target so do it manually
Justin Vreeland 794d92
for arch in $archs; do
Justin Vreeland 794d92
	mkdir $headers_dir/arch-$arch
Justin Vreeland 794d92
	make ARCH=$arch INSTALL_HDR_PATH=$headers_dir/arch-$arch KBUILD_HEADERS=install headers_install
Justin Vreeland 794d92
done
Justin Vreeland 794d92
find $headers_dir \
Justin Vreeland 794d92
	\( -name .install -o -name .check -o \
Justin Vreeland 794d92
	-name ..install.cmd -o -name ..check.cmd \) | xargs rm -f
Justin Vreeland 794d92
Justin Vreeland 794d92
TARBALL=$CURRENTDIR/$PKGLOC/kernel-headers-$KVER.tar.xz
Justin Vreeland 794d92
pushd $headers_dir
Justin Vreeland 794d92
	tar -Jcf $TARBALL *
Justin Vreeland 794d92
popd
Justin Vreeland 794d92
Justin Vreeland 794d92
echo wrote $TARBALL
Justin Vreeland 794d92
Justin Vreeland 794d92
# Update kernel-headers.spec
Justin Vreeland 794d92
cd $CURRENTDIR/$PKGLOC/
Justin Vreeland 794d92
Justin Vreeland 794d92
BASE=$BASE perl -p -i -e 's|%define base_sublevel.*|%define base_sublevel $ENV{'BASE'}|' kernel-headers.spec
Justin Vreeland 794d92
BASERELEASE=$(($BASERELEASE-1))
Justin Vreeland 794d92
BASERELEASE=$BASERELEASE perl -p -i -e 's|%global baserelease.*|%global baserelease $ENV{'BASERELEASE'}|' kernel-headers.spec
Justin Vreeland 794d92
Justin Vreeland 794d92
if [ $RELEASED -eq 0 ]; then
Justin Vreeland 794d92
	[ -n "$BUILDID" ] && sed -i -e 's/^# define buildid .local/%define buildid '$BUILDID'/' kernel-headers.spec
Justin Vreeland 794d92
	RC=$RC perl -p -i -e 's|%global rcrev.*|%global rcrev $ENV{'RC'}|' kernel-headers.spec
Justin Vreeland 794d92
	GITREV=$GITREV perl -p -i -e 's|%define gitrev.*|%define gitrev $ENV{'GITREV'}|' kernel-headers.spec
Justin Vreeland 794d92
	rpmdev-bumpspec -c "Linux v$MAJORVER.$NEWBASE-rc$RC.git$GITREV" kernel-headers.spec
Justin Vreeland 794d92
else
Justin Vreeland 794d92
	STABLE=$STABLE perl -p -i -e 's|%define stable_update.*|%define stable_update $ENV{'STABLE'}|' kernel-headers.spec
Justin Vreeland 794d92
	rpmdev-bumpspec -c "Linux v$MAJORVER.$BASE.$STABLE" kernel-headers.spec
Justin Vreeland 794d92
fi
Justin Vreeland 794d92
echo "Modified $CURRENTDIR/$PKGLOC/kernel-headers.spec"
Justin Vreeland 794d92
echo "Don't forget to upload the sources"