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 17echo configinit.sh $* 18 19T=/tmp/configinit.sh.$$ 20trap 'rm -rf $T' 0 21mkdir $T 22 23# Capture config spec file. 24 25c=$1 26buildloc=$2 27builddir= 28if test -n $buildloc 29then 30 if echo $buildloc | grep -q '^O=' 31 then 32 builddir=`echo $buildloc | sed -e 's/^O=//'` 33 if test ! -d $builddir 34 then 35 mkdir $builddir 36 fi 37 else 38 echo Bad build directory: \"$builddir\" 39 exit 2 40 fi 41fi 42 43sed -e 's/^\(CONFIG[0-9A-Z_]*\)=.*$/grep -v "^# \1" |/' < $c > $T/u.sh 44sed -e 's/^\(CONFIG[0-9A-Z_]*=\).*$/grep -v \1 |/' < $c >> $T/u.sh 45grep '^grep' < $T/u.sh > $T/upd.sh 46echo "cat - $c" >> $T/upd.sh 47make mrproper 48make $buildloc distclean > $builddir/Make.distclean 2>&1 49make $buildloc defconfig > $builddir/Make.defconfig.out 2>&1 50mv $builddir/.config $builddir/.config.sav 51sh $T/upd.sh < $builddir/.config.sav > $builddir/.config 52cp $builddir/.config $builddir/.config.new 53yes '' | make $buildloc oldconfig > $builddir/Make.modconfig.out 2>&1 54 55# verify new config matches specification. 56 57sed -e 's/"//g' < $c > $T/c 58sed -e 's/"//g' < $builddir/.config > $T/.config 59sed -e 's/\(.*\)=n/# \1 is not set/' -e 's/^#CHECK#//' < $c | 60awk ' 61 { 62 print "if grep -q \"" $0 "\" < '"$T/.config"'"; 63 print "then"; 64 print "\t:"; 65 print "else"; 66 if ($1 == "#") { 67 print "\tif grep -q \"" $2 "\" < '"$T/.config"'"; 68 print "\tthen"; 69 print "\t\techo \":" $2 ": improperly set\""; 70 print "\telse"; 71 print "\t\t:"; 72 print "\tfi"; 73 } else { 74 print "\techo \":" $0 ": improperly set\""; 75 } 76 print "fi"; 77 }' | sh > $T/diagnostics 78if test -s $T/diagnostics 79then 80 cat $T/diagnostics 81 exit 1 82fi 83exit 0 84