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