memcg: infrastructure to match an allocation to the right cache
[linux-2.6/cjktty.git] / scripts / config
blobee355394f4ef76eeb6d6f74dac00729d8cc942e3
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 shift
105 continue
107 --refresh)
109 --*-after)
110 checkarg "$1"
111 A=$ARG
112 checkarg "$2"
113 B=$ARG
114 shift 2
117 checkarg "$1"
118 shift
120 esac
121 case "$CMD" in
122 --enable|-e)
123 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
126 --disable|-d)
127 set_var "${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
130 --module|-m)
131 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
134 --set-str)
135 # sed swallows one level of escaping, so we need double-escaping
136 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
137 shift
140 --set-val)
141 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
142 shift
144 --undefine|-u)
145 undef_var "${CONFIG_}$ARG"
148 --state|-s)
149 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
150 echo n
151 else
152 V="$(grep "^${CONFIG_}$ARG=" $FN)"
153 if [ $? != 0 ] ; then
154 echo undef
155 else
156 V="${V/#${CONFIG_}$ARG=/}"
157 V="${V/#\"/}"
158 V="${V/%\"/}"
159 V="${V//\\\"/\"}"
160 echo "${V}"
165 --enable-after|-E)
166 set_var "${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
169 --disable-after|-D)
170 set_var "${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
173 --module-after|-M)
174 set_var "${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
177 # undocumented because it ignores --file (fixme)
178 --refresh)
179 yes "" | make oldconfig
183 usage
185 esac
186 done