Commit 1f990cf94559e0a7363d56aade1d5dc6c515b60b
Committed by
Sam Ravnborg
1 parent
47312d2cfd
Exists in
master
and in
20 other branches
kbuild: add generic --set-str option to scripts/config
Signed-off-by: Michal Marek <mmarek@suse.cz> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Showing 1 changed file with 9 additions and 2 deletions Inline Diff
scripts/config
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 | usage() { | 4 | usage() { |
5 | cat >&2 <<EOL | 5 | cat >&2 <<EOL |
6 | Manipulate options in a .config file from the command line. | 6 | Manipulate options in a .config file from the command line. |
7 | Usage: | 7 | Usage: |
8 | config options command ... | 8 | config options command ... |
9 | commands: | 9 | commands: |
10 | --enable|-e option Enable option | 10 | --enable|-e option Enable option |
11 | --disable|-d option Disable option | 11 | --disable|-d option Disable option |
12 | --module|-m option Turn option into a module | 12 | --module|-m option Turn option into a module |
13 | --state|-s option Print state of option (n,y,m,undef) | 13 | --set-str option value |
14 | Set option to "value" | ||
15 | --state|-s option Print state of option (n,y,m,undef) | ||
14 | 16 | ||
15 | --enable-after|-E beforeopt option | 17 | --enable-after|-E beforeopt option |
16 | Enable option directly after other option | 18 | Enable option directly after other option |
17 | --disable-after|-D beforeopt option | 19 | --disable-after|-D beforeopt option |
18 | Disable option directly after other option | 20 | Disable option directly after other option |
19 | --module-after|-M beforeopt option | 21 | --module-after|-M beforeopt option |
20 | Turn option into module directly after other option | 22 | Turn option into module directly after other option |
21 | 23 | ||
22 | commands can be repeated multiple times | 24 | commands can be repeated multiple times |
23 | 25 | ||
24 | options: | 26 | options: |
25 | --file .config file to change (default .config) | 27 | --file .config file to change (default .config) |
26 | 28 | ||
27 | config doesn't check the validity of the .config file. This is done at next | 29 | config doesn't check the validity of the .config file. This is done at next |
28 | make time. | 30 | make time. |
29 | EOL | 31 | EOL |
30 | exit 1 | 32 | exit 1 |
31 | } | 33 | } |
32 | 34 | ||
33 | checkarg() { | 35 | checkarg() { |
34 | ARG="$1" | 36 | ARG="$1" |
35 | if [ "$ARG" = "" ] ; then | 37 | if [ "$ARG" = "" ] ; then |
36 | usage | 38 | usage |
37 | fi | 39 | fi |
38 | case "$ARG" in | 40 | case "$ARG" in |
39 | CONFIG_*) | 41 | CONFIG_*) |
40 | ARG="${ARG/CONFIG_/}" | 42 | ARG="${ARG/CONFIG_/}" |
41 | ;; | 43 | ;; |
42 | esac | 44 | esac |
43 | ARG="`echo $ARG | tr a-z A-Z`" | 45 | ARG="`echo $ARG | tr a-z A-Z`" |
44 | } | 46 | } |
45 | 47 | ||
46 | set_var() { | 48 | set_var() { |
47 | local name=$1 new=$2 before=$3 | 49 | local name=$1 new=$2 before=$3 |
48 | 50 | ||
49 | name_re="^($name=|# $name is not set)" | 51 | name_re="^($name=|# $name is not set)" |
50 | before_re="^($before=|# $before is not set)" | 52 | before_re="^($before=|# $before is not set)" |
51 | if test -n "$before" && grep -Eq "$before_re" "$FN"; then | 53 | if test -n "$before" && grep -Eq "$before_re" "$FN"; then |
52 | sed -ri "/$before_re/a $new" "$FN" | 54 | sed -ri "/$before_re/a $new" "$FN" |
53 | elif grep -Eq "$name_re" "$FN"; then | 55 | elif grep -Eq "$name_re" "$FN"; then |
54 | sed -ri "s:$name_re.*:$new:" "$FN" | 56 | sed -ri "s:$name_re.*:$new:" "$FN" |
55 | else | 57 | else |
56 | echo "$new" >>"$FN" | 58 | echo "$new" >>"$FN" |
57 | fi | 59 | fi |
58 | } | 60 | } |
59 | 61 | ||
60 | if [ "$1" = "--file" ]; then | 62 | if [ "$1" = "--file" ]; then |
61 | FN="$2" | 63 | FN="$2" |
62 | if [ "$FN" = "" ] ; then | 64 | if [ "$FN" = "" ] ; then |
63 | usage | 65 | usage |
64 | fi | 66 | fi |
65 | shift 2 | 67 | shift 2 |
66 | else | 68 | else |
67 | FN=.config | 69 | FN=.config |
68 | fi | 70 | fi |
69 | 71 | ||
70 | if [ "$1" = "" ] ; then | 72 | if [ "$1" = "" ] ; then |
71 | usage | 73 | usage |
72 | fi | 74 | fi |
73 | 75 | ||
74 | while [ "$1" != "" ] ; do | 76 | while [ "$1" != "" ] ; do |
75 | CMD="$1" | 77 | CMD="$1" |
76 | shift | 78 | shift |
77 | case "$CMD" in | 79 | case "$CMD" in |
78 | --refresh) | 80 | --refresh) |
79 | ;; | 81 | ;; |
80 | --*-after) | 82 | --*-after) |
81 | checkarg "$1" | 83 | checkarg "$1" |
82 | A=$ARG | 84 | A=$ARG |
83 | checkarg "$2" | 85 | checkarg "$2" |
84 | B=$ARG | 86 | B=$ARG |
85 | shift 2 | 87 | shift 2 |
86 | ;; | 88 | ;; |
87 | --*) | 89 | --*) |
88 | checkarg "$1" | 90 | checkarg "$1" |
89 | shift | 91 | shift |
90 | ;; | 92 | ;; |
91 | esac | 93 | esac |
92 | case "$CMD" in | 94 | case "$CMD" in |
93 | --enable|-e) | 95 | --enable|-e) |
94 | set_var "CONFIG_$ARG" "CONFIG_$ARG=y" | 96 | set_var "CONFIG_$ARG" "CONFIG_$ARG=y" |
95 | ;; | 97 | ;; |
96 | 98 | ||
97 | --disable|-d) | 99 | --disable|-d) |
98 | set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set" | 100 | set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set" |
99 | ;; | 101 | ;; |
100 | 102 | ||
101 | --module|-m) | 103 | --module|-m) |
102 | set_var "CONFIG_$ARG" "CONFIG_$ARG=m" | 104 | set_var "CONFIG_$ARG" "CONFIG_$ARG=m" |
105 | ;; | ||
106 | |||
107 | --set-str) | ||
108 | set_var "CONFIG_$ARG" "CONFIG_$ARG=\"$1\"" | ||
109 | shift | ||
103 | ;; | 110 | ;; |
104 | 111 | ||
105 | --state|-s) | 112 | --state|-s) |
106 | if grep -q "# CONFIG_$ARG is not set" $FN ; then | 113 | if grep -q "# CONFIG_$ARG is not set" $FN ; then |
107 | echo n | 114 | echo n |
108 | else | 115 | else |
109 | V="$(grep "^CONFIG_$ARG=" $FN)" | 116 | V="$(grep "^CONFIG_$ARG=" $FN)" |
110 | if [ $? != 0 ] ; then | 117 | if [ $? != 0 ] ; then |
111 | echo undef | 118 | echo undef |
112 | else | 119 | else |
113 | V="${V/CONFIG_$ARG=/}" | 120 | V="${V/CONFIG_$ARG=/}" |
114 | V="${V/\"/}" | 121 | V="${V/\"/}" |
115 | echo "$V" | 122 | echo "$V" |
116 | fi | 123 | fi |
117 | fi | 124 | fi |
118 | ;; | 125 | ;; |
119 | 126 | ||
120 | --enable-after|-E) | 127 | --enable-after|-E) |
121 | set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A" | 128 | set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A" |
122 | ;; | 129 | ;; |
123 | 130 | ||
124 | --disable-after|-D) | 131 | --disable-after|-D) |
125 | set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A" | 132 | set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A" |
126 | ;; | 133 | ;; |
127 | 134 | ||
128 | --module-after|-M) | 135 | --module-after|-M) |
129 | set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A" | 136 | set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A" |
130 | ;; | 137 | ;; |
131 | 138 | ||
132 | # undocumented because it ignores --file (fixme) | 139 | # undocumented because it ignores --file (fixme) |
133 | --refresh) | 140 | --refresh) |
134 | yes "" | make oldconfig | 141 | yes "" | make oldconfig |
135 | ;; | 142 | ;; |
136 | 143 | ||
137 | *) | 144 | *) |
138 | usage | 145 | usage |
139 | ;; | 146 | ;; |
140 | esac | 147 | esac |
141 | done | 148 | done |
142 | 149 | ||
143 | 150 |