]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - scripts/config
kconfig: switch to "long long" for sanity
[thirdparty/kernel/linux.git] / scripts / config
CommitLineData
8e54701e
AK
1#!/bin/bash
2# Manipulate options in a .config file from the command line
3
73877785
CC
4myname=${0##*/}
5
f5ef2f7b
YM
6# If no prefix forced, use the default CONFIG_
7CONFIG_="${CONFIG_-CONFIG_}"
8
8e54701e
AK
9usage() {
10 cat >&2 <<EOL
11Manipulate options in a .config file from the command line.
12Usage:
73877785 13$myname options command ...
8e54701e
AK
14commands:
15 --enable|-e option Enable option
16 --disable|-d option Disable option
1f990cf9 17 --module|-m option Turn option into a module
f0a6332c
JA
18 --set-str option string
19 Set option to "string"
20 --set-val option value
21 Set option to value
d5bfb6b3 22 --undefine|-u option Undefine option
1f990cf9 23 --state|-s option Print state of option (n,y,m,undef)
8e54701e
AK
24
25 --enable-after|-E beforeopt option
26 Enable option directly after other option
27 --disable-after|-D beforeopt option
28 Disable option directly after other option
29 --module-after|-M beforeopt option
30 Turn option into module directly after other option
31
32 commands can be repeated multiple times
33
34options:
4edc7e32
YM
35 --file config-file .config file to change (default .config)
36 --keep-case|-k Keep next symbols' case (dont' upper-case it)
8e54701e 37
73877785 38$myname doesn't check the validity of the .config file. This is done at next
4edc7e32
YM
39make time.
40
73877785 41By default, $myname will upper-case the given symbol. Use --keep-case to keep
4edc7e32 42the case of all following symbols unchanged.
f5ef2f7b 43
73877785
CC
44$myname uses 'CONFIG_' as the default symbol prefix. Set the environment
45variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" $myname ...
8e54701e
AK
46EOL
47 exit 1
48}
49
50checkarg() {
51 ARG="$1"
52 if [ "$ARG" = "" ] ; then
53 usage
54 fi
55 case "$ARG" in
f5ef2f7b
YM
56 ${CONFIG_}*)
57 ARG="${ARG/${CONFIG_}/}"
8e54701e
AK
58 ;;
59 esac
4edc7e32
YM
60 if [ "$MUNGE_CASE" = "yes" ] ; then
61 ARG="`echo $ARG | tr a-z A-Z`"
62 fi
8e54701e
AK
63}
64
56643222
MM
65set_var() {
66 local name=$1 new=$2 before=$3
67
68 name_re="^($name=|# $name is not set)"
69 before_re="^($before=|# $before is not set)"
70 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
71 sed -ri "/$before_re/a $new" "$FN"
72 elif grep -Eq "$name_re" "$FN"; then
73 sed -ri "s:$name_re.*:$new:" "$FN"
74 else
75 echo "$new" >>"$FN"
76 fi
8e54701e
AK
77}
78
d5bfb6b3
YM
79undef_var() {
80 local name=$1
81
82 sed -ri "/^($name=|# $name is not set)/d" "$FN"
83}
84
8e54701e
AK
85if [ "$1" = "--file" ]; then
86 FN="$2"
87 if [ "$FN" = "" ] ; then
88 usage
89 fi
47312d2c 90 shift 2
8e54701e
AK
91else
92 FN=.config
93fi
94
2302e873
AK
95if [ "$1" = "" ] ; then
96 usage
97fi
98
4edc7e32 99MUNGE_CASE=yes
8e54701e
AK
100while [ "$1" != "" ] ; do
101 CMD="$1"
102 shift
103 case "$CMD" in
4edc7e32
YM
104 --keep-case|-k)
105 MUNGE_CASE=no
4edc7e32
YM
106 continue
107 ;;
47312d2c
MM
108 --refresh)
109 ;;
57a9c760 110 --*-after|-E|-D|-M)
47312d2c
MM
111 checkarg "$1"
112 A=$ARG
113 checkarg "$2"
114 B=$ARG
115 shift 2
116 ;;
45f53cc9 117 -*)
8e54701e 118 checkarg "$1"
8e54701e
AK
119 shift
120 ;;
47312d2c
MM
121 esac
122 case "$CMD" in
123 --enable|-e)
f5ef2f7b 124 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
47312d2c 125 ;;
8e54701e
AK
126
127 --disable|-d)
f5ef2f7b 128 set_var "${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
8e54701e
AK
129 ;;
130
131 --module|-m)
f5ef2f7b 132 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
8e54701e
AK
133 ;;
134
1f990cf9 135 --set-str)
d6686da8 136 # sed swallows one level of escaping, so we need double-escaping
f5ef2f7b 137 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
1f990cf9
MM
138 shift
139 ;;
140
f0a6332c 141 --set-val)
f5ef2f7b 142 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
f0a6332c
JA
143 shift
144 ;;
d5bfb6b3
YM
145 --undefine|-u)
146 undef_var "${CONFIG_}$ARG"
147 ;;
f0a6332c 148
8e54701e 149 --state|-s)
f5ef2f7b 150 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
8e54701e
AK
151 echo n
152 else
f5ef2f7b 153 V="$(grep "^${CONFIG_}$ARG=" $FN)"
8e54701e
AK
154 if [ $? != 0 ] ; then
155 echo undef
156 else
f5ef2f7b 157 V="${V/#${CONFIG_}$ARG=/}"
d6686da8
YM
158 V="${V/#\"/}"
159 V="${V/%\"/}"
1925a276 160 V="${V//\\\"/\"}"
d6686da8 161 echo "${V}"
8e54701e
AK
162 fi
163 fi
8e54701e
AK
164 ;;
165
166 --enable-after|-E)
f5ef2f7b 167 set_var "${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
8e54701e
AK
168 ;;
169
170 --disable-after|-D)
f5ef2f7b 171 set_var "${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
8e54701e
AK
172 ;;
173
174 --module-after|-M)
f5ef2f7b 175 set_var "${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
8e54701e
AK
176 ;;
177
178 # undocumented because it ignores --file (fixme)
179 --refresh)
180 yes "" | make oldconfig
181 ;;
182
183 *)
184 usage
185 ;;
186 esac
187done
188