linuxtorvalds / rpms / kernel

Forked from rpms/kernel 2 years ago
Clone
Justin Vreeland 794d92
#!/bin/bash
Justin Vreeland 794d92
#
Justin Vreeland 794d92
# This script merges together the hierarchy of CONFIG_* files under generic
Justin Vreeland 794d92
# and debug to form the necessary $PACKAGE_NAME<version>-<arch>-<variant>.config
Justin Vreeland 794d92
# files for building RHEL kernels, based on the contents of a control file
Justin Vreeland 794d92
Justin Vreeland 794d92
PACKAGE_NAME="${1:-kernel}" # defines the package name used
Justin Vreeland 794d92
KVERREL="${2:-}"
Justin Vreeland 794d92
SUBARCH="${3:-}" # defines a specific arch
Justin Vreeland 794d92
SCRIPT="$(readlink -f $0)"
Justin Vreeland 794d92
OUTPUT_DIR="$PWD"
Justin Vreeland 794d92
SCRIPT_DIR="$(dirname $SCRIPT)"
Justin Vreeland 794d92
Justin Vreeland 794d92
LANG=en_US.UTF-8
Justin Vreeland 794d92
Justin Vreeland 794d92
# to handle this script being a symlink
Justin Vreeland 794d92
cd $SCRIPT_DIR
Justin Vreeland 794d92
Justin Vreeland 794d92
set errexit
Justin Vreeland 794d92
set nounset
Justin Vreeland 794d92
Justin Vreeland 794d92
cleanup()
Justin Vreeland 794d92
{
Justin Vreeland 794d92
	rm -f config-*
Justin Vreeland 794d92
}
Justin Vreeland 794d92
Justin Vreeland 794d92
die()
Justin Vreeland 794d92
{
Justin Vreeland 794d92
	echo "$1"
Justin Vreeland 794d92
	cleanup
Justin Vreeland 794d92
	exit 1
Justin Vreeland 794d92
}
Justin Vreeland 794d92
Justin Vreeland 794d92
function combine_config_layer()
Justin Vreeland 794d92
{
Justin Vreeland 794d92
	dir=$1
Justin Vreeland 794d92
	file="config-$(echo $dir | sed -e 's|/|-|g')"
Justin Vreeland 794d92
Justin Vreeland 794d92
	if [ $(ls $dir/ | grep -c "^CONFIG_") -eq 0 ]; then
Justin Vreeland 794d92
		touch $file
Justin Vreeland 794d92
		return
Justin Vreeland 794d92
	fi
Justin Vreeland 794d92
Justin Vreeland 794d92
	cat $dir/CONFIG_* > $file
Justin Vreeland 794d92
}
Justin Vreeland 794d92
Justin Vreeland 794d92
function merge_configs()
Justin Vreeland 794d92
{
Justin Vreeland 794d92
	archvar=$1
Justin Vreeland 794d92
	arch=$(echo "$archvar" | cut -f1 -d"-")
Justin Vreeland 794d92
	configs=$2
Justin Vreeland 794d92
	order=$3
Justin Vreeland 794d92
	flavor=$4
Justin Vreeland 794d92
Justin Vreeland 794d92
	name=$OUTPUT_DIR/$PACKAGE_NAME-$archvar-$flavor.config
Justin Vreeland 794d92
	echo -n "Building $name ... "
Justin Vreeland 794d92
	touch config-merging config-merged
Justin Vreeland 794d92
Justin Vreeland 794d92
	# apply based on order
Justin Vreeland 794d92
	skip_if_missing=""
Justin Vreeland 794d92
	for o in $order
Justin Vreeland 794d92
	do
Justin Vreeland 794d92
		for config in $(echo $configs | sed -e 's/:/ /g')
Justin Vreeland 794d92
		do
Justin Vreeland 794d92
			cfile="config-$o-$config"
Justin Vreeland 794d92
Justin Vreeland 794d92
			test -n "$skip_if_missing" && test ! -e $cfile && continue
Justin Vreeland 794d92
Justin Vreeland 794d92
			perl merge.pl $cfile config-merging > config-merged
Justin Vreeland 794d92
			if [ ! $? -eq 0 ]; then
Justin Vreeland 794d92
				die "Failed to merge $cfile"
Justin Vreeland 794d92
			fi
Justin Vreeland 794d92
			mv config-merged config-merging
Justin Vreeland 794d92
		done
Justin Vreeland 794d92
Justin Vreeland 794d92
		# first configs in $order is baseline, all files should be
Justin Vreeland 794d92
		# there.  second pass is overrides and can be missing.
Justin Vreeland 794d92
		skip_if_missing="1"
Justin Vreeland 794d92
	done
Justin Vreeland 794d92
	if [ "x$arch" == "xaarch64" ]; then
Justin Vreeland 794d92
		echo "# arm64" > $name
Justin Vreeland 794d92
	elif [ "x$arch" == "xppc64le" ]; then
Justin Vreeland 794d92
		echo "# powerpc" > $name
Justin Vreeland 794d92
	elif [ "x$arch" == "xs390x" ]; then
Justin Vreeland 794d92
		echo "# s390" > $name
Justin Vreeland 794d92
	elif [ "x$arch" == "xarmv7hl" ]; then
Justin Vreeland 794d92
		echo "# arm" > $name
Justin Vreeland 794d92
	elif [ "x$arch" == "xi686" ]; then
Justin Vreeland 794d92
		echo "# i386" > $name
Justin Vreeland 794d92
	else
Justin Vreeland 794d92
		echo "# $arch" > $name
Justin Vreeland 794d92
	fi
Justin Vreeland 794d92
	sort config-merging >> $name
Justin Vreeland 794d92
	rm -f config-merged config-merging
Justin Vreeland 794d92
	echo "done"
Justin Vreeland 794d92
}
Justin Vreeland 794d92
Justin Vreeland 794d92
function build_flavor()
Justin Vreeland 794d92
{
Justin Vreeland 794d92
	flavor=$1
Justin Vreeland 794d92
	control_file="priority".$flavor
Justin Vreeland 794d92
	while read line
Justin Vreeland 794d92
	do
Justin Vreeland 794d92
		if [ $(echo "$line" | grep -c "^#") -ne 0 ]; then
Justin Vreeland 794d92
			continue
Justin Vreeland 794d92
		elif [ $(echo "$line" | grep -c "^$") -ne 0 ]; then
Justin Vreeland 794d92
			continue
Justin Vreeland 794d92
		elif [ $(echo "$line" | grep -c "^EMPTY") -ne 0 ]; then
Justin Vreeland 794d92
			empty=$(echo "$line" | cut -f2 -d"=")
Justin Vreeland 794d92
			for a in $empty
Justin Vreeland 794d92
			do
Justin Vreeland 794d92
				echo "# EMPTY" > $OUTPUT_DIR/$PACKAGE_NAME-$a-$flavor.config
Justin Vreeland 794d92
Justin Vreeland 794d92
			done
Justin Vreeland 794d92
		elif [ $(echo "$line" | grep -c "^ORDER") -ne 0 ]; then
Justin Vreeland 794d92
			order=$(echo "$line" | cut -f2 -d"=")
Justin Vreeland 794d92
			for o in $order
Justin Vreeland 794d92
			do
Justin Vreeland 794d92
				glist=$(find $o -type d)
Justin Vreeland 794d92
				for d in $glist
Justin Vreeland 794d92
				do
Justin Vreeland 794d92
					combine_config_layer $d
Justin Vreeland 794d92
				done
Justin Vreeland 794d92
			done
Justin Vreeland 794d92
		else
Justin Vreeland 794d92
			arch=$(echo "$line" | cut -f1 -d"=")
Justin Vreeland 794d92
			configs=$(echo "$line" | cut -f2 -d"=")
Justin Vreeland 794d92
Justin Vreeland 794d92
			if [ -n "$SUBARCH" ]; then
Justin Vreeland 794d92
				case $arch in
Justin Vreeland 794d92
					$SUBARCH*)
Justin Vreeland 794d92
						;;
Justin Vreeland 794d92
					*)
Justin Vreeland 794d92
						continue
Justin Vreeland 794d92
				esac
Justin Vreeland 794d92
			fi
Justin Vreeland 794d92
Justin Vreeland 794d92
			merge_configs $arch $configs "$order" $flavor
Justin Vreeland 794d92
		fi
Justin Vreeland 794d92
	done < $control_file
Justin Vreeland 794d92
}
Justin Vreeland 794d92
Justin Vreeland 794d92
while read line
Justin Vreeland 794d92
do
Justin Vreeland 794d92
	build_flavor $line
Justin Vreeland 794d92
done < flavors
Justin Vreeland 794d92
Justin Vreeland 794d92
# A passed in kernel version implies copy to final location
Justin Vreeland 794d92
# otherwise defer to another script
Justin Vreeland 794d92
if test -n "$KVERREL"
Justin Vreeland 794d92
then
Justin Vreeland 794d92
	for i in kernel-*.config
Justin Vreeland 794d92
	do
Justin Vreeland 794d92
		NEW="$(echo $i | sed "s/$PACKAGE_NAME-$SUBARCH/$PACKAGE_NAME-$KVERREL-$SUBARCH/")"
Justin Vreeland 794d92
		mv $i $NEW
Justin Vreeland 794d92
	done
Justin Vreeland 794d92
fi
Justin Vreeland 794d92
Justin Vreeland 794d92
cleanup