#!/bin/sh # # (c) 2007 Marc Andre Tanner # feel free to use, copy modify, and/or distribute # this software for any purpose you wish. ARCH="i386" CONFIG="defconfig" KERNEL_SRC="." OUTPUT="/dev/stdout" TMP="/tmp/config.tmp.$$" error(){ echo "$1" > /dev/stderr exit 1 } debug(){ echo "$1" > /dev/null } usage(){ echo "Usage: `basename $0:` [-a arch] [-i] [-k kernel-source] [config]" } help(){ usage cat > /dev/stdout <<- EOF -a kernel architecture (name of directory under arch/) -i edit config file in place, don't print to stdout -k directory containing the unpacked kernel source config kernel configuration file if ommited .config is used EOF } parse_args(){ [ -z "$1" ] && usage && exit 1 until [ -z "$1" ]; do case "$1" in -a) shift ([ -z "$1" ] || [ ! -d "$KERNEL_SRC/arch/$1" ]) && \ error "$1 doesn't seem to be a valid architecture." ARCH="$1" ;; -i) OUTPUT="$TMP" ;; -k) shift ([ -z "$1" ] || [ ! -d "$1" ] || [ ! -e "$1/init/main.c" ]) && \ error "$1 is not a valid kernel source directory." KERNEL_SRC="$1" ;; -h|--help) help exit 0 ;; *) CONFIG="$1" esac shift done } # $1 => config file, $2 => kernel source dir explain(){ # get all Kconfig files from the kernel source based on the selected architecture local files=`find "$2" -name 'Kconfig*' -a \( \( -wholename './arch/*' -a ! -wholename "./arch/$ARCH/*" \) -prune -o -print \)` cat "$1" | while read line; do debug "Line : $line" echo $line #([ -z "$line" ] || `echo "$line" | grep -q '#'`) && continue # skip empty line and comments if [ ! -z "$line" ] && ! `echo "$line" | grep -q '#'`; then # remove CONFIG_ prefix local symbol=`echo $line | sed 's/CONFIG_\(.*\)=.*/\1/'` debug "Symbol: $symbol" # search the file which defines the config option local file=`grep -l "config $symbol$" $files` debug "File : $file" if [ ! -z "$file" ]; then # extract the config option definition local info=`sed -n "/config $symbol$/,/^[a-z]/p" $file` # check if there is a help text for this config option if [ ! -z "$info" ] && `echo "$info" | grep -q 'help'`; then # remove first and last line, prefix with # echo "$info" | sed -n '2,$p' | sed -n '$!p' | sed 's/^/#/' fi fi fi done } parse_args $* explain $CONFIG $KERNEL_SRC > $OUTPUT [ "$OUTPUT" != "/dev/stdout" ] && mv "$OUTPUT" "$CONFIG" exit 0