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