kvm tools, setup: Create private directory
[linux-2.6/next.git] / scripts / config
bloba7c7c4b8e957311196f9b2eabef414ceaa144555
1 #!/bin/bash
2 # Manipulate options in a .config file from the command line
4 usage() {
5 cat >&2 <<EOL
6 Manipulate options in a .config file from the command line.
7 Usage:
8 config options command ...
9 commands:
10 --enable|-e option Enable option
11 --disable|-d option Disable option
12 --module|-m option Turn option into a module
13 --set-str option string
14 Set option to "string"
15 --set-val option value
16 Set option to value
17 --state|-s option Print state of option (n,y,m,undef)
19 --enable-after|-E beforeopt option
20 Enable option directly after other option
21 --disable-after|-D beforeopt option
22 Disable option directly after other option
23 --module-after|-M beforeopt option
24 Turn option into module directly after other option
26 commands can be repeated multiple times
28 options:
29 --file .config file to change (default .config)
31 config doesn't check the validity of the .config file. This is done at next
32 make time.
33 EOL
34 exit 1
37 checkarg() {
38 ARG="$1"
39 if [ "$ARG" = "" ] ; then
40 usage
42 case "$ARG" in
43 CONFIG_*)
44 ARG="${ARG/CONFIG_/}"
46 esac
47 ARG="`echo $ARG | tr a-z A-Z`"
50 set_var() {
51 local name=$1 new=$2 before=$3
53 name_re="^($name=|# $name is not set)"
54 before_re="^($before=|# $before is not set)"
55 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
56 sed -ri "/$before_re/a $new" "$FN"
57 elif grep -Eq "$name_re" "$FN"; then
58 sed -ri "s:$name_re.*:$new:" "$FN"
59 else
60 echo "$new" >>"$FN"
64 if [ "$1" = "--file" ]; then
65 FN="$2"
66 if [ "$FN" = "" ] ; then
67 usage
69 shift 2
70 else
71 FN=.config
74 if [ "$1" = "" ] ; then
75 usage
78 while [ "$1" != "" ] ; do
79 CMD="$1"
80 shift
81 case "$CMD" in
82 --refresh)
84 --*-after)
85 checkarg "$1"
86 A=$ARG
87 checkarg "$2"
88 B=$ARG
89 shift 2
91 -*)
92 checkarg "$1"
93 shift
95 esac
96 case "$CMD" in
97 --enable|-e)
98 set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
101 --disable|-d)
102 set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set"
105 --module|-m)
106 set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
109 --set-str)
110 set_var "CONFIG_$ARG" "CONFIG_$ARG=\"$1\""
111 shift
114 --set-val)
115 set_var "CONFIG_$ARG" "CONFIG_$ARG=$1"
116 shift
119 --state|-s)
120 if grep -q "# CONFIG_$ARG is not set" $FN ; then
121 echo n
122 else
123 V="$(grep "^CONFIG_$ARG=" $FN)"
124 if [ $? != 0 ] ; then
125 echo undef
126 else
127 V="${V/CONFIG_$ARG=/}"
128 V="${V/\"/}"
129 echo "$V"
134 --enable-after|-E)
135 set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A"
138 --disable-after|-D)
139 set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A"
142 --module-after|-M)
143 set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A"
146 # undocumented because it ignores --file (fixme)
147 --refresh)
148 yes "" | make oldconfig
152 usage
154 esac
155 done