1#!/bin/sh 2# 3# sh configinit.sh config-spec-file [ build output dir ] 4# 5# Create a .config file from the spec file. Run from the kernel source tree. 6# Exits with 0 if all went well, with 1 if all went well but the config 7# did not match, and some other number for other failures. 8# 9# The first argument is the .config specification file, which contains 10# desired settings, for example, "CONFIG_NO_HZ=y". For best results, 11# this should be a full pathname. 12# 13# The second argument is a optional path to a build output directory, 14# for example, "O=/tmp/foo". If this argument is omitted, the .config 15# file will be generated directly in the current directory. 16 17T=/tmp/configinit.sh.$$ 18trap 'rm -rf $T' 0 19mkdir $T 20 21# Capture config spec file. 22 23c=$1 24buildloc=$2 25builddir= 26if test -n $buildloc 27then 28 if echo $buildloc | grep -q '^O=' 29 then 30 builddir=`echo $buildloc | sed -e 's/^O=//'` 31 if test ! -d $builddir 32 then 33 mkdir $builddir 34 fi 35 else 36 echo Bad build directory: \"$builddir\" 37 exit 2 38 fi 39fi 40 41sed -e 's/^\(CONFIG[0-9A-Z_]*\)=.*$/grep -v "^# \1" |/' < $c > $T/u.sh 42sed -e 's/^\(CONFIG[0-9A-Z_]*=\).*$/grep -v \1 |/' < $c >> $T/u.sh 43grep '^grep' < $T/u.sh > $T/upd.sh 44echo "cat - $c" >> $T/upd.sh 45make mrproper 46make $buildloc distclean > $builddir/Make.distclean 2>&1 47make $buildloc defconfig > $builddir/Make.defconfig.out 2>&1 48mv $builddir/.config $builddir/.config.sav 49sh $T/upd.sh < $builddir/.config.sav > $builddir/.config 50cp $builddir/.config $builddir/.config.new 51yes '' | make $buildloc oldconfig > $builddir/Make.modconfig.out 2>&1 52 53# verify new config matches specification. 54 55sed -e 's/"//g' < $c > $T/c 56sed -e 's/"//g' < $builddir/.config > $T/.config 57sed -e 's/\(.*\)=n/# \1 is not set/' -e 's/^#CHECK#//' < $c | 58awk ' 59 { 60 print "if grep -q \"" $0 "\" < '"$T/.config"'"; 61 print "then"; 62 print "\t:"; 63 print "else"; 64 if ($1 == "#") { 65 print "\tif grep -q \"" $2 "\" < '"$T/.config"'"; 66 print "\tthen"; 67 print "\t\techo \":" $2 ": improperly set\""; 68 print "\telse"; 69 print "\t\t:"; 70 print "\tfi"; 71 } else { 72 print "\techo \":" $0 ": improperly set\""; 73 } 74 print "fi"; 75 }' | sh > $T/diagnostics 76if test -s $T/diagnostics 77then 78 cat $T/diagnostics 79 exit 1 80fi 81exit 0 82