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_}"
10 # We use an uncommon delimiter for sed substitutions
11 SED_DELIM=$(echo -en "\001")
15 Manipulate options in a .config file from the command line.
17 $myname options command ...
19 --enable|-e option Enable option
20 --disable|-d option Disable option
21 --module|-m option Turn option into a module
22 --set-str option string
23 Set option to "string"
24 --set-val option value
26 --undefine|-u option Undefine option
27 --state|-s option Print state of option (n,y,m,undef)
29 --enable-after|-E beforeopt option
30 Enable option directly after other option
31 --disable-after|-D beforeopt option
32 Disable option directly after other option
33 --module-after|-M beforeopt option
34 Turn option into module directly after other option
36 commands can be repeated multiple times
39 --file config-file .config file to change (default .config)
40 --keep-case|-k Keep next symbols' case (dont' upper-case it)
42 $myname doesn't check the validity of the .config file. This is done at next
45 By default, $myname will upper-case the given symbol. Use --keep-case to keep
46 the case of all following symbols unchanged.
48 $myname uses 'CONFIG_' as the default symbol prefix. Set the environment
49 variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" $myname ...
56 if [ "$ARG" = "" ] ; then
61 ARG="${ARG/${CONFIG_}/}"
64 if [ "$MUNGE_CASE" = "yes" ] ; then
65 ARG="`echo $ARG | tr a-z A-Z`"
73 local tmpfile="$infile.swp"
75 # sed append cmd: 'a\' + newline + text + newline
76 cmd="$(printf "a\\%b$insert" "\n")"
78 sed -e "/$anchor/$cmd" "$infile" >"$tmpfile"
79 # replace original file with the edited one
80 mv "$tmpfile" "$infile"
87 local tmpfile="$infile.swp"
89 sed -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmpfile"
90 # replace original file with the edited one
91 mv "$tmpfile" "$infile"
97 local tmpfile="$infile.swp"
99 sed -e "/$text/d" "$infile" >"$tmpfile"
100 # replace original file with the edited one
101 mv "$tmpfile" "$infile"
105 local name=$1 new=$2 before=$3
107 name_re="^($name=|# $name is not set)"
108 before_re="^($before=|# $before is not set)"
109 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
110 txt_append "^$before=" "$new" "$FN"
111 txt_append "^# $before is not set" "$new" "$FN"
112 elif grep -Eq "$name_re" "$FN"; then
113 txt_subst "^$name=.*" "$new" "$FN"
114 txt_subst "^# $name is not set" "$new" "$FN"
123 txt_delete "^$name=" "$FN"
124 txt_delete "^# $name is not set" "$FN"
127 if [ "$1" = "--file" ]; then
129 if [ "$FN" = "" ] ; then
137 if [ "$1" = "" ] ; then
142 while [ "$1" != "" ] ; do
166 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
170 set_var "${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
174 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
178 # sed swallows one level of escaping, so we need double-escaping
179 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
184 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
188 undef_var "${CONFIG_}$ARG"
192 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
195 V="$(grep "^${CONFIG_}$ARG=" $FN)"
196 if [ $? != 0 ] ; then
199 V="${V/#${CONFIG_}$ARG=/}"
209 set_var "${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
213 set_var "${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
217 set_var "${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
220 # undocumented because it ignores --file (fixme)
222 yes "" | make oldconfig