hiromitsuhanada / rpms / kernel-rt

Forked from rpms/kernel-rt 4 years ago
Clone

Blame SOURCES/process_configs.sh

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