2 # Manipulate options in a .config file from the command line
6 # If no prefix forced, use the default CONFIG_
7 CONFIG_
="${CONFIG_-CONFIG_}"
9 # We use an uncommon delimiter for sed substitutions
10 SED_DELIM
=$
(echo -en "\001")
14 Manipulate options in a .config file from the command line.
16 $myname options command ...
18 --enable|-e option Enable option
19 --disable|-d option Disable option
20 --module|-m option Turn option into a module
21 --set-str option string
22 Set option to "string"
23 --set-val option value
25 --undefine|-u option Undefine option
26 --state|-s option Print state of option (n,y,m,undef)
28 --enable-after|-E beforeopt option
29 Enable option directly after other option
30 --disable-after|-D beforeopt option
31 Disable option directly after other option
32 --module-after|-M beforeopt option
33 Turn option into module directly after other option
35 commands can be repeated multiple times
38 --file config-file .config file to change (default .config)
39 --keep-case|-k Keep next symbols' case (dont' upper-case it)
41 $myname doesn't check the validity of the .config file. This is done at next
44 By default, $myname will upper-case the given symbol. Use --keep-case to keep
45 the case of all following symbols unchanged.
47 $myname uses 'CONFIG_' as the default symbol prefix. Set the environment
48 variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" $myname ...
55 if [ "$ARG" = "" ] ; then
60 ARG
="${ARG/${CONFIG_}/}"
63 if [ "$MUNGE_CASE" = "yes" ] ; then
64 ARG
="`echo $ARG | tr a-z A-Z`"
72 local tmpfile
="$infile.swp"
74 # sed append cmd: 'a\' + newline + text + newline
75 cmd
="$(printf "a
\\%b
$insert" "\n")"
77 sed -e "/$anchor/$cmd" "$infile" >"$tmpfile"
78 # replace original file with the edited one
79 mv "$tmpfile" "$infile"
86 local tmpfile
="$infile.swp"
88 sed -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmpfile"
89 # replace original file with the edited one
90 mv "$tmpfile" "$infile"
96 local tmpfile
="$infile.swp"
98 sed -e "/$text/d" "$infile" >"$tmpfile"
99 # replace original file with the edited one
100 mv "$tmpfile" "$infile"
104 local name
=$1 new
=$2 before
=$3
106 name_re
="^($name=|# $name is not set)"
107 before_re
="^($before=|# $before is not set)"
108 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
109 txt_append
"^$before=" "$new" "$FN"
110 txt_append
"^# $before is not set" "$new" "$FN"
111 elif grep -Eq "$name_re" "$FN"; then
112 txt_subst
"^$name=.*" "$new" "$FN"
113 txt_subst
"^# $name is not set" "$new" "$FN"
122 txt_delete
"^$name=" "$FN"
123 txt_delete
"^# $name is not set" "$FN"
126 if [ "$1" = "--file" ]; then
128 if [ "$FN" = "" ] ; then
136 if [ "$1" = "" ] ; then
141 while [ "$1" != "" ] ; do
165 set_var
"${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
169 set_var
"${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
173 set_var
"${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
177 # sed swallows one level of escaping, so we need double-escaping
178 set_var
"${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
183 set_var
"${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
187 undef_var
"${CONFIG_}$ARG"
191 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
194 V
="$(grep "^
${CONFIG_}$ARG=" $FN)"
195 if [ $?
!= 0 ] ; then
198 V
="${V/#${CONFIG_}$ARG=/}"
208 set_var
"${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
212 set_var
"${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
216 set_var
"${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
219 # undocumented because it ignores --file (fixme)
221 yes "" |
make oldconfig