aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorAndi Kleen <andi@firstfloor.org>2009-01-02 21:21:41 -0500
committerSam Ravnborg <sam@ravnborg.org>2009-01-07 15:44:22 -0500
commit8e54701ea85b0ab0971637825a628f5aa2b678a4 (patch)
tree5763cf394b3a2f096fef6b2330a3dc19d63bcc44 /scripts
parent4f628248a578585472e19e4cba2c604643af8c6c (diff)
kconfig: add script to manipulate .config files on the command line
I often change single options in .config files. Instead of using an editor or one of the frontends it's convenient to do this from the command line. It's also useful to do from automated build scripts when building different variants from a base config file. I extracted most of the CONFIG manipulation code from one of my build scripts into a new shell script scripts/config The script is not integrated with the normal Kconfig machinery and doesn't do any checking against Kconfig files, but just manipulates that text format. This is always done at make time anyways. I believe this script would be a useful standard addition for scripts/* Sample usage: ./scripts/config --disable smp Disable SMP in .config file ./scripts/config --file otherdir/.config --module e1000e Enable E1000E as module in otherdir/.config ./scripts/config --state smp y Check state of config option CONFIG_SMP After merging into git please make scripts/config executable Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts')
-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