dingjian / rpms / kernel-rt

Forked from rpms/kernel-rt 4 years ago
Clone

Blame SOURCES/process_configs.sh

fa4e14
#!/bin/bash
fa4e14
#
fa4e14
# This script takes the merged config files and processes them through oldconfig
fa4e14
# and listnewconfig
fa4e14
#
fa4e14
fa4e14
usage()
fa4e14
{
fa4e14
	echo "process_configs.sh [ -n|-c|-t ] package_name kernel_version"
fa4e14
	echo "     -n: error on unset config options"
fa4e14
	echo "     -c: error on mismatched config options"
fa4e14
	echo "     -t: test run, do not overwrite original config"
fa4e14
	echo "     -w: error on misconfigured config options"
fa4e14
	exit 1
fa4e14
}
fa4e14
fa4e14
die()
fa4e14
{
fa4e14
	echo "$1"
fa4e14
	exit 1
fa4e14
}
fa4e14
fa4e14
# stupid function to find top of tree to do kernel make configs
fa4e14
switch_to_toplevel()
fa4e14
{
fa4e14
	path="$(pwd)"
fa4e14
	while test -n "$path"
fa4e14
	do
fa4e14
		test -d $path/firmware && \
fa4e14
			test -e $path/MAINTAINERS && \
fa4e14
			test -d $path/drivers && \
fa4e14
			break
fa4e14
fa4e14
		path="$(dirname $path)"
fa4e14
	done
fa4e14
fa4e14
	test -n "$path"  || die "Can't find toplevel"
fa4e14
	echo "$path"
fa4e14
}
fa4e14
fa4e14
checkoptions()
fa4e14
{
fa4e14
	/usr/bin/awk '
fa4e14
fa4e14
		/is not set/ {
fa4e14
			split ($0, a, "#");
fa4e14
			split(a[2], b);
fa4e14
			if (NR==FNR) {
fa4e14
				configs[b[1]]="is not set";
fa4e14
			} else {
fa4e14
				if (configs[b[1]] != "" && configs[b[1]] != "is not set")
fa4e14
					 print "Found # "b[1] " is not set, after generation, had " b[1] " " configs[b[1]] " in Source tree";
fa4e14
			}
fa4e14
		}
fa4e14
fa4e14
		/=/     {
fa4e14
			split ($0, a, "=");
fa4e14
			if (NR==FNR) {
fa4e14
				configs[a[1]]=a[2];
fa4e14
			} else {
fa4e14
				if (configs[a[1]] != "" && configs[a[1]] != a[2])
fa4e14
					 print "Found "a[1]"="a[2]" after generation, had " a[1]"="configs[a[1]]" in Source tree";
fa4e14
			}
fa4e14
		}
fa4e14
	' $1 $2 > .mismatches
fa4e14
fa4e14
	if test -s .mismatches
fa4e14
	then
fa4e14
		echo "Error: Mismatches found in configuration files"
fa4e14
		cat .mismatches
fa4e14
		exit 1
fa4e14
	fi
fa4e14
}
fa4e14
fa4e14
function process_configs()
fa4e14
{
fa4e14
	# assume we are in $source_tree/configs, need to get to top level
fa4e14
	pushd $(switch_to_toplevel) &>/dev/null
fa4e14
fa4e14
	for cfg in $SCRIPT_DIR/${PACKAGE_NAME}${KVERREL}${SUBARCH}*.config
fa4e14
	do
fa4e14
		arch=$(head -1 $cfg | cut -b 3-)
fa4e14
		cfgtmp="${cfg}.tmp"
fa4e14
		cfgorig="${cfg}.orig"
fa4e14
		cat $cfg > $cfgorig
fa4e14
fa4e14
		echo -n "Processing $cfg ... "
fa4e14
fa4e14
		make ARCH=$arch KCONFIG_CONFIG=$cfgorig listnewconfig >& .listnewconfig
fa4e14
		grep -E 'CONFIG_' .listnewconfig > .newoptions
fa4e14
		if test -n "$NEWOPTIONS" && test -s .newoptions
fa4e14
		then
fa4e14
			echo "Found unset config items, please set them to an appropriate value"
fa4e14
			cat .newoptions
fa4e14
			rm .newoptions
fa4e14
			exit 1
fa4e14
		fi
fa4e14
		rm .newoptions
fa4e14
fa4e14
		grep -E 'config.*warning' .listnewconfig > .warnings
fa4e14
		if test -n "$CHECKWARNINGS" && test -s .warnings
fa4e14
		then
fa4e14
			echo "Found misconfigured config items, please set them to an appropriate value"
fa4e14
			cat .warnings
fa4e14
			rm .warnings
fa4e14
			exit 1
fa4e14
		fi
fa4e14
		rm .warnings
fa4e14
fa4e14
		rm .listnewconfig
fa4e14
fa4e14
		make ARCH=$arch KCONFIG_CONFIG=$cfgorig oldnoconfig > /dev/null || exit 1
fa4e14
		echo "# $arch" > ${cfgtmp}
fa4e14
		cat "${cfgorig}" >> ${cfgtmp}
fa4e14
		if test -n "$CHECKOPTIONS"
fa4e14
		then
fa4e14
			checkoptions $cfg $cfgtmp
fa4e14
		fi
fa4e14
		# if test run, don't overwrite original
fa4e14
		if test -n "$TESTRUN"
fa4e14
		then
fa4e14
			rm ${cfgtmp}
fa4e14
		else
fa4e14
			mv ${cfgtmp} ${cfg}
fa4e14
		fi
fa4e14
		rm ${cfgorig}
fa4e14
		echo "done"
fa4e14
	done
fa4e14
	rm "$SCRIPT_DIR"/*.config*.old
fa4e14
	popd > /dev/null
fa4e14
fa4e14
	echo "Processed config files are in $SCRIPT_DIR"
fa4e14
}
fa4e14
fa4e14
NEWOPTIONS=""
fa4e14
CHECKOPTIONS=""
fa4e14
CHECKWARNINGS=""
fa4e14
TESTRUN=""
fa4e14
fa4e14
while [[ $# -gt 0 ]]
fa4e14
do
fa4e14
	key="$1"
fa4e14
	case $key in
fa4e14
		-h)
fa4e14
			usage
fa4e14
			;;
fa4e14
		-n)
fa4e14
			NEWOPTIONS="x"
fa4e14
			;;
fa4e14
		-c)
fa4e14
			CHECKOPTIONS="x"
fa4e14
			;;
fa4e14
		-t)
fa4e14
			TESTRUN="x"
fa4e14
			;;
fa4e14
		-w)
fa4e14
			CHECKWARNINGS="x"
fa4e14
			;;
fa4e14
		*)
fa4e14
			break;;
fa4e14
	esac
fa4e14
	shift
fa4e14
done
fa4e14
fa4e14
PACKAGE_NAME="${1:-kernel}" # defines the package name used
fa4e14
KVERREL="$(test -n "$2" && echo "-$2" || echo "")"
fa4e14
SUBARCH="$(test -n "$3" && echo "-$3" || echo "")"
fa4e14
SCRIPT="$(readlink -f $0)"
fa4e14
OUTPUT_DIR="$PWD"
fa4e14
SCRIPT_DIR="$(dirname $SCRIPT)"
fa4e14
fa4e14
# to handle this script being a symlink
fa4e14
cd $SCRIPT_DIR
fa4e14
fa4e14
process_configs