1f09d599e9d95412fd08dc6f6ce0d2949709f215
[platform/adaptation/renesas_rcar/renesas_kernel.git] / tools / testing / selftests / rcutorture / bin / configinit.sh
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
17 echo configinit.sh $*
18
19 T=/tmp/configinit.sh.$$
20 trap 'rm -rf $T' 0
21 mkdir $T
22
23 # Capture config spec file.
24
25 c=$1
26 buildloc=$2
27 builddir=
28 if test -n $buildloc
29 then
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
41 fi
42
43 sed -e 's/^\(CONFIG[0-9A-Z_]*\)=.*$/grep -v "^# \1" |/' < $c > $T/u.sh
44 sed -e 's/^\(CONFIG[0-9A-Z_]*=\).*$/grep -v \1 |/' < $c >> $T/u.sh
45 grep '^grep' < $T/u.sh > $T/upd.sh
46 echo "cat - $c" >> $T/upd.sh
47 make mrproper
48 make $buildloc distclean > $builddir/Make.distclean 2>&1
49 make $buildloc defconfig > $builddir/Make.defconfig.out 2>&1
50 mv $builddir/.config $builddir/.config.sav
51 sh $T/upd.sh < $builddir/.config.sav > $builddir/.config
52 cp $builddir/.config $builddir/.config.new
53 yes '' | make $buildloc oldconfig > $builddir/Make.modconfig.out 2>&1
54
55 # verify new config matches specification.
56
57 sed -e 's/"//g' < $c > $T/c
58 sed -e 's/"//g' < $builddir/.config > $T/.config
59 sed -e 's/\(.*\)=n/# \1 is not set/' -e 's/^#CHECK#//' < $c |
60 awk     '
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
78 if test -s $T/diagnostics
79 then
80         cat $T/diagnostics
81         exit 1
82 fi
83 exit 0