aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/config
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/config')
-rwxr-xr-xscripts/config150
1 files changed, 150 insertions, 0 deletions
diff --git a/scripts/config b/scripts/config
new file mode 100755
index 000000000000..68b9761cdc38
--- /dev/null
+++ b/scripts/config
@@ -0,0 +1,150 @@
1#!/bin/bash
2# Manipulate options in a .config file from the command line
3
4usage() {
5 cat >&2 <<EOL
6Manipulate options in a .config file from the command line.
7Usage:
8config options command ...
9commands:
10 --enable|-e option Enable option
11 --disable|-d option Disable option
12 --module|-m option Turn option into a module
13 --state|-s option Print state of option (n,y,m,undef)
14
15 --enable-after|-E beforeopt option
16 Enable option directly after other option
17 --disable-after|-D beforeopt option
18 Disable option directly after other option
19 --module-after|-M beforeopt option
20 Turn option into module directly after other option
21
22 commands can be repeated multiple times
23
24options:
25 --file .config file to change (default .config)
26
27config doesn't check the validity of the .config file. This is done at next
28 make time.
29The options need to be already in the file before they can be changed,
30but sometimes you can cheat with the --*-after options.
31EOL
32 exit 1
33}
34
35checkarg() {
36 ARG="$1"
37 if [ "$ARG" = "" ] ; then
38 usage
39 fi
40 case "$ARG" in
41 CONFIG_*)
42 ARG="${ARG/CONFIG_/}"
43 ;;
44 esac
45 ARG="`echo $ARG | tr a-z A-Z`"
46}
47
48replace() {
49 sed -i -e "$@" $FN
50}
51
52if [ "$1" = "--file" ]; then
53 FN="$2"
54 if [ "$FN" = "" ] ; then
55 usage
56 fi
57 shift
58 shift
59else
60 FN=.config
61fi
62
63while [ "$1" != "" ] ; do
64 CMD="$1"
65 shift
66 case "$CMD" in
67 --enable|-e)
68 checkarg "$1"
69 replace "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
70 shift
71 ;;
72
73 --disable|-d)
74 checkarg "$1"
75 replace "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
76 shift
77 ;;
78
79 --module|-m)
80 checkarg "$1"
81 replace "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
82 -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
83 shift
84 ;;
85
86 --state|-s)
87 checkarg "$1"
88 if grep -q "# CONFIG_$ARG is not set" $FN ; then
89 echo n
90 else
91 V="$(grep "^CONFIG_$ARG=" $FN)"
92 if [ $? != 0 ] ; then
93 echo undef
94 else
95 V="${V/CONFIG_$ARG=/}"
96 V="${V/\"/}"
97 echo "$V"
98 fi
99 fi
100 shift
101 ;;
102
103 --enable-after|-E)
104 checkarg "$1"
105 A=$ARG
106 checkarg "$2"
107 B=$ARG
108 replace "/CONFIG_$A=[my]/aCONFIG_$B=y" \
109 -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=y" \
110 -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
111 shift
112 shift
113 ;;
114
115 --disable-after|-D)
116 checkarg "$1"
117 A=$ARG
118 checkarg "$2"
119 B=$ARG
120 replace "/CONFIG_$A=[my]/a# CONFIG_$B is not set" \
121 -e "/# CONFIG_$ARG is not set/a/# CONFIG_$ARG is not set" \
122 -e "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
123 shift
124 shift
125 ;;
126
127 --module-after|-M)
128 checkarg "$1"
129 A=$ARG
130 checkarg "$2"
131 B=$ARG
132 replace "/CONFIG_$A=[my]/aCONFIG_$B=m" \
133 -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=m" \
134 -e "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
135 -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
136 shift
137 shift
138 ;;
139
140 # undocumented because it ignores --file (fixme)
141 --refresh)
142 yes "" | make oldconfig
143 ;;
144
145 *)
146 usage
147 ;;
148 esac
149done
150