linuxtorvalds / rpms / kernel

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