Blame SOURCES/process_configs.sh

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