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