potatogim / rpms / kernel

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