Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
[linux-2.6/sactl.git] / scripts / config
blob68b9761cdc38aac39700fbd99b4c563d6c1ca3d6
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 --state|-s option Print state of option (n,y,m,undef)
15 --enable-after|-E beforeopt option
16 Enable option directly after other option
17 --disable-after|-D beforeopt option
18 Disable option directly after other option
19 --module-after|-M beforeopt option
20 Turn option into module directly after other option
22 commands can be repeated multiple times
24 options:
25 --file .config file to change (default .config)
27 config doesn't check the validity of the .config file. This is done at next
28 make time.
29 The options need to be already in the file before they can be changed,
30 but sometimes you can cheat with the --*-after options.
31 EOL
32 exit 1
35 checkarg() {
36 ARG="$1"
37 if [ "$ARG" = "" ] ; then
38 usage
40 case "$ARG" in
41 CONFIG_*)
42 ARG="${ARG/CONFIG_/}"
44 esac
45 ARG="`echo $ARG | tr a-z A-Z`"
48 replace() {
49 sed -i -e "$@" $FN
52 if [ "$1" = "--file" ]; then
53 FN="$2"
54 if [ "$FN" = "" ] ; then
55 usage
57 shift
58 shift
59 else
60 FN=.config
63 while [ "$1" != "" ] ; do
64 CMD="$1"
65 shift
66 case "$CMD" in
67 --enable|-e)
68 checkarg "$1"
69 replace "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
70 shift
73 --disable|-d)
74 checkarg "$1"
75 replace "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
76 shift
79 --module|-m)
80 checkarg "$1"
81 replace "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
82 -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
83 shift
86 --state|-s)
87 checkarg "$1"
88 if grep -q "# CONFIG_$ARG is not set" $FN ; then
89 echo n
90 else
91 V="$(grep "^CONFIG_$ARG=" $FN)"
92 if [ $? != 0 ] ; then
93 echo undef
94 else
95 V="${V/CONFIG_$ARG=/}"
96 V="${V/\"/}"
97 echo "$V"
100 shift
103 --enable-after|-E)
104 checkarg "$1"
105 A=$ARG
106 checkarg "$2"
107 B=$ARG
108 replace "/CONFIG_$A=[my]/aCONFIG_$B=y" \
109 -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=y" \
110 -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
111 shift
112 shift
115 --disable-after|-D)
116 checkarg "$1"
117 A=$ARG
118 checkarg "$2"
119 B=$ARG
120 replace "/CONFIG_$A=[my]/a# CONFIG_$B is not set" \
121 -e "/# CONFIG_$ARG is not set/a/# CONFIG_$ARG is not set" \
122 -e "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
123 shift
124 shift
127 --module-after|-M)
128 checkarg "$1"
129 A=$ARG
130 checkarg "$2"
131 B=$ARG
132 replace "/CONFIG_$A=[my]/aCONFIG_$B=m" \
133 -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=m" \
134 -e "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
135 -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
136 shift
137 shift
140 # undocumented because it ignores --file (fixme)
141 --refresh)
142 yes "" | make oldconfig
146 usage
148 esac
149 done