2 # Manipulate options in a .config file from the command line
6 # If no prefix forced, use the default BR2_
7 BR2_PREFIX="${BR2_PREFIX-BR2_}"
11 Manipulate options in a .config file from the command line.
13 $myname options command ...
15 --enable|-e option Enable option
16 --disable|-d option Disable option
17 --set-str option string
18 Set option to "string"
19 --set-val option value
21 --undefine|-u option Undefine option
22 --state|-s option Print state of option (n,y,m,undef)
24 --enable-after|-E beforeopt option
25 Enable option directly after other option
26 --disable-after|-D beforeopt option
27 Disable option directly after other option
29 commands can be repeated multiple times
32 --file config-file .config file to change (default .config)
33 --keep-case|-k Keep next symbols' case (dont' upper-case it)
34 --package|-p Operate on package (set prefix to BR2_PACKAGE_)
36 $myname doesn't check the validity of the .config file. This is done at next
39 By default, $myname will upper-case the given symbol. Use --keep-case to keep
40 the case of all following symbols unchanged.
42 $myname uses 'BR2_' as the default symbol prefix. Set the environment
43 variable BR2_PREFIX to the prefix to use. Eg.: BR2_PREFIX="FOO_" $myname ...
50 if [ "$ARG" = "" ] ; then
53 if [ "$MUNGE_CASE" = "yes" ] ; then
54 ARG="`echo $ARG | tr a-z- A-Z_`"
58 ARG="${ARG/${BR2_PREFIX}/}"
67 local tmpfile="$infile.swp"
69 # sed append cmd: 'a\' + newline + text + newline
70 cmd="$(printf "a\\%b$insert" "\n")"
72 sed -i -e "/$anchor/$cmd" "$infile"
79 local tmpfile="$infile.swp"
81 sed -i -e "s:$before:$after:" "$infile"
87 local tmpfile="$infile.swp"
89 sed -i -e "/$text/d" "$infile"
93 local name=$1 new=$2 before=$3
95 name_re="^($name=|# $name is not set)"
96 before_re="^($before=|# $before is not set)"
97 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
98 txt_append "^$before=" "$new" "$FN"
99 txt_append "^# $before is not set" "$new" "$FN"
100 elif grep -Eq "$name_re" "$FN"; then
101 txt_subst "^$name=.*" "$new" "$FN"
102 txt_subst "^# $name is not set" "$new" "$FN"
111 txt_delete "^$name=" "$FN"
112 txt_delete "^# $name is not set" "$FN"
115 if [ "$1" = "--file" ]; then
117 if [ "$FN" = "" ] ; then
125 if [ "$1" = "" ] ; then
130 while [ "$1" != "" ] ; do
139 BR2_PREFIX="BR2_PACKAGE_"
156 set_var "${BR2_PREFIX}$ARG" "${BR2_PREFIX}$ARG=y"
160 set_var "${BR2_PREFIX}$ARG" "# ${BR2_PREFIX}$ARG is not set"
164 # sed swallows one level of escaping, so we need double-escaping
165 set_var "${BR2_PREFIX}$ARG" "${BR2_PREFIX}$ARG=\"${1//\"/\\\\\"}\""
170 set_var "${BR2_PREFIX}$ARG" "${BR2_PREFIX}$ARG=$1"
174 undef_var "${BR2_PREFIX}$ARG"
178 if grep -q "# ${BR2_PREFIX}$ARG is not set" $FN ; then
181 V="$(grep "^${BR2_PREFIX}$ARG=" $FN)"
182 if [ $? != 0 ] ; then
185 V="${V/#${BR2_PREFIX}$ARG=/}"
195 set_var "${BR2_PREFIX}$B" "${BR2_PREFIX}$B=y" "${BR2_PREFIX}$A"
199 set_var "${BR2_PREFIX}$B" "# ${BR2_PREFIX}$B is not set" "${BR2_PREFIX}$A"