2 # SPDX-License-Identifier: GPL-2.0
3 # Manipulate options in a .config file from the command line
7 # If no prefix forced, use the default CONFIG_
8 CONFIG_
="${CONFIG_-CONFIG_}"
12 Manipulate options in a .config file from the command line.
14 $myname options command ...
16 --enable|-e option Enable option
17 --disable|-d option Disable option
18 --module|-m option Turn option into a module
19 --set-str option string
20 Set option to "string"
21 --set-val option value
23 --undefine|-u option Undefine option
24 --state|-s option Print state of option (n,y,m,undef)
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
33 commands can be repeated multiple times
36 --file config-file .config file to change (default .config)
37 --keep-case|-k Keep next symbols' case (dont' upper-case it)
39 $myname doesn't check the validity of the .config file. This is done at next
42 By default, $myname will upper-case the given symbol. Use --keep-case to keep
43 the case of all following symbols unchanged.
45 $myname uses 'CONFIG_' as the default symbol prefix. Set the environment
46 variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" $myname ...
53 if [ "$ARG" = "" ] ; then
58 ARG
="${ARG/${CONFIG_}/}"
61 if [ "$MUNGE_CASE" = "yes" ] ; then
62 ARG
="`echo $ARG | tr a-z A-Z`"
70 local tmpfile
="$infile.swp"
72 # sed append cmd: 'a\' + newline + text + newline
73 cmd
="$(printf "a
\\%b
$insert" "\n")"
75 sed -e "/$anchor/$cmd" "$infile" >"$tmpfile"
76 # replace original file with the edited one
77 mv "$tmpfile" "$infile"
84 local tmpfile
="$infile.swp"
86 sed -e "s:$before:$after:" "$infile" >"$tmpfile"
87 # replace original file with the edited one
88 mv "$tmpfile" "$infile"
94 local tmpfile
="$infile.swp"
96 sed -e "/$text/d" "$infile" >"$tmpfile"
97 # replace original file with the edited one
98 mv "$tmpfile" "$infile"
102 local name
=$1 new
=$2 before
=$3
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
107 txt_append
"^$before=" "$new" "$FN"
108 txt_append
"^# $before is not set" "$new" "$FN"
109 elif grep -Eq "$name_re" "$FN"; then
110 txt_subst
"^$name=.*" "$new" "$FN"
111 txt_subst
"^# $name is not set" "$new" "$FN"
120 txt_delete
"^$name=" "$FN"
121 txt_delete
"^# $name is not set" "$FN"
124 if [ "$1" = "--file" ]; then
126 if [ "$FN" = "" ] ; then
134 if [ "$1" = "" ] ; then
139 while [ "$1" != "" ] ; do
163 set_var
"${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
167 set_var
"${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
171 set_var
"${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
175 # sed swallows one level of escaping, so we need double-escaping
176 set_var
"${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
181 set_var
"${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
185 undef_var
"${CONFIG_}$ARG"
189 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
192 V
="$(grep "^
${CONFIG_}$ARG=" $FN)"
193 if [ $?
!= 0 ] ; then
196 V
="${V/#${CONFIG_}$ARG=/}"
206 set_var
"${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
210 set_var
"${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
214 set_var
"${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
217 # undocumented because it ignores --file (fixme)
219 yes "" |
make oldconfig