Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[linux-2.6.git] / scripts / config
bloba65ecbbdd32a90fbadf50aa9622ce555294cf350
1 #!/bin/bash
2 # Manipulate options in a .config file from the command line
4 # If no prefix forced, use the default CONFIG_
5 CONFIG_="${CONFIG_-CONFIG_}"
7 usage() {
8 cat >&2 <<EOL
9 Manipulate options in a .config file from the command line.
10 Usage:
11 config options command ...
12 commands:
13 --enable|-e option Enable option
14 --disable|-d option Disable option
15 --module|-m option Turn option into a module
16 --set-str option string
17 Set option to "string"
18 --set-val option value
19 Set option to value
20 --undefine|-u option Undefine option
21 --state|-s option Print state of option (n,y,m,undef)
23 --enable-after|-E beforeopt option
24 Enable option directly after other option
25 --disable-after|-D beforeopt option
26 Disable option directly after other option
27 --module-after|-M beforeopt option
28 Turn option into module directly after other option
30 commands can be repeated multiple times
32 options:
33 --file config-file .config file to change (default .config)
34 --keep-case|-k Keep next symbols' case (dont' upper-case it)
36 config doesn't check the validity of the .config file. This is done at next
37 make time.
39 By default, config will upper-case the given symbol. Use --keep-case to keep
40 the case of all following symbols unchanged.
42 config uses 'CONFIG_' as the default symbol prefix. Set the environment
43 variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" config ...
44 EOL
45 exit 1
48 checkarg() {
49 ARG="$1"
50 if [ "$ARG" = "" ] ; then
51 usage
53 case "$ARG" in
54 ${CONFIG_}*)
55 ARG="${ARG/${CONFIG_}/}"
57 esac
58 if [ "$MUNGE_CASE" = "yes" ] ; then
59 ARG="`echo $ARG | tr a-z A-Z`"
63 set_var() {
64 local name=$1 new=$2 before=$3
66 name_re="^($name=|# $name is not set)"
67 before_re="^($before=|# $before is not set)"
68 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
69 sed -ri "/$before_re/a $new" "$FN"
70 elif grep -Eq "$name_re" "$FN"; then
71 sed -ri "s:$name_re.*:$new:" "$FN"
72 else
73 echo "$new" >>"$FN"
77 undef_var() {
78 local name=$1
80 sed -ri "/^($name=|# $name is not set)/d" "$FN"
83 if [ "$1" = "--file" ]; then
84 FN="$2"
85 if [ "$FN" = "" ] ; then
86 usage
88 shift 2
89 else
90 FN=.config
93 if [ "$1" = "" ] ; then
94 usage
97 MUNGE_CASE=yes
98 while [ "$1" != "" ] ; do
99 CMD="$1"
100 shift
101 case "$CMD" in
102 --keep-case|-k)
103 MUNGE_CASE=no
104 continue
106 --refresh)
108 --*-after|-E|-D|-M)
109 checkarg "$1"
110 A=$ARG
111 checkarg "$2"
112 B=$ARG
113 shift 2
116 checkarg "$1"
117 shift
119 esac
120 case "$CMD" in
121 --enable|-e)
122 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
125 --disable|-d)
126 set_var "${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
129 --module|-m)
130 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
133 --set-str)
134 # sed swallows one level of escaping, so we need double-escaping
135 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
136 shift
139 --set-val)
140 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
141 shift
143 --undefine|-u)
144 undef_var "${CONFIG_}$ARG"
147 --state|-s)
148 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
149 echo n
150 else
151 V="$(grep "^${CONFIG_}$ARG=" $FN)"
152 if [ $? != 0 ] ; then
153 echo undef
154 else
155 V="${V/#${CONFIG_}$ARG=/}"
156 V="${V/#\"/}"
157 V="${V/%\"/}"
158 V="${V//\\\"/\"}"
159 echo "${V}"
164 --enable-after|-E)
165 set_var "${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
168 --disable-after|-D)
169 set_var "${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
172 --module-after|-M)
173 set_var "${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
176 # undocumented because it ignores --file (fixme)
177 --refresh)
178 yes "" | make oldconfig
182 usage
184 esac
185 done