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