hitmoon / rpms / kernel

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