MINI2440: Added new T35 (QVGA) and Innolux 5.6" (VGA) TFTs
[linux-2.6/mini2440.git] / scripts / config
blob608d7fdb13e8d6ac901eaf99cc3b1b5df0a7cc95
1 #!/bin/bash
2 # Manipulate options in a .config file from the command line
4 usage() {
5 cat >&2 <<EOL
6 Manipulate options in a .config file from the command line.
7 Usage:
8 config options command ...
9 commands:
10 --enable|-e option Enable option
11 --disable|-d option Disable option
12 --module|-m option Turn option into a module
13 --set-str option value
14 Set option to "value"
15 --state|-s option Print state of option (n,y,m,undef)
17 --enable-after|-E beforeopt option
18 Enable option directly after other option
19 --disable-after|-D beforeopt option
20 Disable option directly after other option
21 --module-after|-M beforeopt option
22 Turn option into module directly after other option
24 commands can be repeated multiple times
26 options:
27 --file .config file to change (default .config)
29 config doesn't check the validity of the .config file. This is done at next
30 make time.
31 EOL
32 exit 1
35 checkarg() {
36 ARG="$1"
37 if [ "$ARG" = "" ] ; then
38 usage
40 case "$ARG" in
41 CONFIG_*)
42 ARG="${ARG/CONFIG_/}"
44 esac
45 ARG="`echo $ARG | tr a-z A-Z`"
48 set_var() {
49 local name=$1 new=$2 before=$3
51 name_re="^($name=|# $name is not set)"
52 before_re="^($before=|# $before is not set)"
53 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
54 sed -ri "/$before_re/a $new" "$FN"
55 elif grep -Eq "$name_re" "$FN"; then
56 sed -ri "s:$name_re.*:$new:" "$FN"
57 else
58 echo "$new" >>"$FN"
62 if [ "$1" = "--file" ]; then
63 FN="$2"
64 if [ "$FN" = "" ] ; then
65 usage
67 shift 2
68 else
69 FN=.config
72 if [ "$1" = "" ] ; then
73 usage
76 while [ "$1" != "" ] ; do
77 CMD="$1"
78 shift
79 case "$CMD" in
80 --refresh)
82 --*-after)
83 checkarg "$1"
84 A=$ARG
85 checkarg "$2"
86 B=$ARG
87 shift 2
89 --*)
90 checkarg "$1"
91 shift
93 esac
94 case "$CMD" in
95 --enable|-e)
96 set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
99 --disable|-d)
100 set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set"
103 --module|-m)
104 set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
107 --set-str)
108 set_var "CONFIG_$ARG" "CONFIG_$ARG=\"$1\""
109 shift
112 --state|-s)
113 if grep -q "# CONFIG_$ARG is not set" $FN ; then
114 echo n
115 else
116 V="$(grep "^CONFIG_$ARG=" $FN)"
117 if [ $? != 0 ] ; then
118 echo undef
119 else
120 V="${V/CONFIG_$ARG=/}"
121 V="${V/\"/}"
122 echo "$V"
127 --enable-after|-E)
128 set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A"
131 --disable-after|-D)
132 set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A"
135 --module-after|-M)
136 set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A"
139 # undocumented because it ignores --file (fixme)
140 --refresh)
141 yes "" | make oldconfig
145 usage
147 esac
148 done