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