aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/config
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/config')
-rwxr-xr-xscripts/config60
1 files changed, 44 insertions, 16 deletions
diff --git a/scripts/config b/scripts/config
index 9e984bc96e18..ee355394f4ef 100755
--- a/scripts/config
+++ b/scripts/config
@@ -1,6 +1,9 @@
1#!/bin/bash 1#!/bin/bash
2# Manipulate options in a .config file from the command line 2# Manipulate options in a .config file from the command line
3 3
4# If no prefix forced, use the default CONFIG_
5CONFIG_="${CONFIG_-CONFIG_}"
6
4usage() { 7usage() {
5 cat >&2 <<EOL 8 cat >&2 <<EOL
6Manipulate options in a .config file from the command line. 9Manipulate options in a .config file from the command line.
@@ -14,6 +17,7 @@ commands:
14 Set option to "string" 17 Set option to "string"
15 --set-val option value 18 --set-val option value
16 Set option to value 19 Set option to value
20 --undefine|-u option Undefine option
17 --state|-s option Print state of option (n,y,m,undef) 21 --state|-s option Print state of option (n,y,m,undef)
18 22
19 --enable-after|-E beforeopt option 23 --enable-after|-E beforeopt option
@@ -26,10 +30,17 @@ commands:
26 commands can be repeated multiple times 30 commands can be repeated multiple times
27 31
28options: 32options:
29 --file .config file to change (default .config) 33 --file config-file .config file to change (default .config)
34 --keep-case|-k Keep next symbols' case (dont' upper-case it)
30 35
31config doesn't check the validity of the .config file. This is done at next 36config doesn't check the validity of the .config file. This is done at next
32 make time. 37make time.
38
39By default, config will upper-case the given symbol. Use --keep-case to keep
40the case of all following symbols unchanged.
41
42config uses 'CONFIG_' as the default symbol prefix. Set the environment
43variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" config ...
33EOL 44EOL
34 exit 1 45 exit 1
35} 46}
@@ -40,11 +51,13 @@ checkarg() {
40 usage 51 usage
41 fi 52 fi
42 case "$ARG" in 53 case "$ARG" in
43 CONFIG_*) 54 ${CONFIG_}*)
44 ARG="${ARG/CONFIG_/}" 55 ARG="${ARG/${CONFIG_}/}"
45 ;; 56 ;;
46 esac 57 esac
47 ARG="`echo $ARG | tr a-z A-Z`" 58 if [ "$MUNGE_CASE" = "yes" ] ; then
59 ARG="`echo $ARG | tr a-z A-Z`"
60 fi
48} 61}
49 62
50set_var() { 63set_var() {
@@ -61,6 +74,12 @@ set_var() {
61 fi 74 fi
62} 75}
63 76
77undef_var() {
78 local name=$1
79
80 sed -ri "/^($name=|# $name is not set)/d" "$FN"
81}
82
64if [ "$1" = "--file" ]; then 83if [ "$1" = "--file" ]; then
65 FN="$2" 84 FN="$2"
66 if [ "$FN" = "" ] ; then 85 if [ "$FN" = "" ] ; then
@@ -75,10 +94,16 @@ if [ "$1" = "" ] ; then
75 usage 94 usage
76fi 95fi
77 96
97MUNGE_CASE=yes
78while [ "$1" != "" ] ; do 98while [ "$1" != "" ] ; do
79 CMD="$1" 99 CMD="$1"
80 shift 100 shift
81 case "$CMD" in 101 case "$CMD" in
102 --keep-case|-k)
103 MUNGE_CASE=no
104 shift
105 continue
106 ;;
82 --refresh) 107 --refresh)
83 ;; 108 ;;
84 --*-after) 109 --*-after)
@@ -95,37 +120,40 @@ while [ "$1" != "" ] ; do
95 esac 120 esac
96 case "$CMD" in 121 case "$CMD" in
97 --enable|-e) 122 --enable|-e)
98 set_var "CONFIG_$ARG" "CONFIG_$ARG=y" 123 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
99 ;; 124 ;;
100 125
101 --disable|-d) 126 --disable|-d)
102 set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set" 127 set_var "${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
103 ;; 128 ;;
104 129
105 --module|-m) 130 --module|-m)
106 set_var "CONFIG_$ARG" "CONFIG_$ARG=m" 131 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
107 ;; 132 ;;
108 133
109 --set-str) 134 --set-str)
110 # sed swallows one level of escaping, so we need double-escaping 135 # sed swallows one level of escaping, so we need double-escaping
111 set_var "CONFIG_$ARG" "CONFIG_$ARG=\"${1//\"/\\\\\"}\"" 136 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
112 shift 137 shift
113 ;; 138 ;;
114 139
115 --set-val) 140 --set-val)
116 set_var "CONFIG_$ARG" "CONFIG_$ARG=$1" 141 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
117 shift 142 shift
118 ;; 143 ;;
144 --undefine|-u)
145 undef_var "${CONFIG_}$ARG"
146 ;;
119 147
120 --state|-s) 148 --state|-s)
121 if grep -q "# CONFIG_$ARG is not set" $FN ; then 149 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
122 echo n 150 echo n
123 else 151 else
124 V="$(grep "^CONFIG_$ARG=" $FN)" 152 V="$(grep "^${CONFIG_}$ARG=" $FN)"
125 if [ $? != 0 ] ; then 153 if [ $? != 0 ] ; then
126 echo undef 154 echo undef
127 else 155 else
128 V="${V/#CONFIG_$ARG=/}" 156 V="${V/#${CONFIG_}$ARG=/}"
129 V="${V/#\"/}" 157 V="${V/#\"/}"
130 V="${V/%\"/}" 158 V="${V/%\"/}"
131 V="${V//\\\"/\"}" 159 V="${V//\\\"/\"}"
@@ -135,15 +163,15 @@ while [ "$1" != "" ] ; do
135 ;; 163 ;;
136 164
137 --enable-after|-E) 165 --enable-after|-E)
138 set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A" 166 set_var "${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
139 ;; 167 ;;
140 168
141 --disable-after|-D) 169 --disable-after|-D)
142 set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A" 170 set_var "${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
143 ;; 171 ;;
144 172
145 --module-after|-M) 173 --module-after|-M)
146 set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A" 174 set_var "${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
147 ;; 175 ;;
148 176
149 # undocumented because it ignores --file (fixme) 177 # undocumented because it ignores --file (fixme)