kbuild: fix mkspec to cleanup RPM_BUILD_ROOT
[linux-2.6] / scripts / config
1 #!/bin/bash
2 # Manipulate options in a .config file from the command line
3
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)
14
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
21
22         commands can be repeated multiple times
23
24 options:
25         --file .config file to change (default .config)
26
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
33 }
34
35 checkarg() {
36         ARG="$1"
37         if [ "$ARG" = "" ] ; then
38                 usage
39         fi
40         case "$ARG" in
41         CONFIG_*)
42                 ARG="${ARG/CONFIG_/}"
43                 ;;
44         esac
45         ARG="`echo $ARG | tr a-z A-Z`"
46 }
47
48 replace() {
49         sed -i -e "$@" $FN
50 }
51
52 if [ "$1" = "--file" ]; then
53         FN="$2"
54         if [ "$FN" = "" ] ; then
55                 usage
56         fi
57         shift
58         shift
59 else
60         FN=.config
61 fi
62
63 if [ "$1" = "" ] ; then
64         usage
65 fi
66
67 while [ "$1" != "" ] ; do
68         CMD="$1"
69         shift
70         case "$CMD" in
71         --enable|-e)
72                 checkarg "$1"
73                 replace "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
74                 shift
75                 ;;
76
77         --disable|-d)
78                 checkarg "$1"
79                 replace "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
80                 shift
81                 ;;
82
83         --module|-m)
84                 checkarg "$1"
85                 replace "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
86                         -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
87                 shift
88                 ;;
89
90         --state|-s)
91                 checkarg "$1"
92                 if grep -q "# CONFIG_$ARG is not set" $FN ; then
93                         echo n
94                 else
95                         V="$(grep "^CONFIG_$ARG=" $FN)"
96                         if [ $? != 0 ] ; then
97                                 echo undef
98                         else
99                                 V="${V/CONFIG_$ARG=/}"
100                                 V="${V/\"/}"
101                                 echo "$V"
102                         fi
103                 fi
104                 shift
105                 ;;
106
107         --enable-after|-E)
108                 checkarg "$1"
109                 A=$ARG
110                 checkarg "$2"
111                 B=$ARG
112                 replace "/CONFIG_$A=[my]/aCONFIG_$B=y" \
113                         -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=y" \
114                         -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
115                 shift
116                 shift
117                 ;;
118
119         --disable-after|-D)
120                 checkarg "$1"
121                 A=$ARG
122                 checkarg "$2"
123                 B=$ARG
124                 replace "/CONFIG_$A=[my]/a# CONFIG_$B is not set" \
125                 -e "/# CONFIG_$ARG is not set/a/# CONFIG_$ARG is not set" \
126                 -e "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
127                 shift
128                 shift
129                 ;;
130
131         --module-after|-M)
132                 checkarg "$1"
133                 A=$ARG
134                 checkarg "$2"
135                 B=$ARG
136                 replace "/CONFIG_$A=[my]/aCONFIG_$B=m" \
137                         -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=m" \
138                         -e "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
139                         -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
140                 shift
141                 shift
142                 ;;
143
144         # undocumented because it ignores --file (fixme)
145         --refresh)
146                 yes "" | make oldconfig
147                 ;;
148
149         *)
150                 usage
151                 ;;
152         esac
153 done
154