PM / sleep: Asynchronous threads for suspend_late
[linux/fpc-iii.git] / scripts / config
blob68041793698c5f22099782129b03c81b8b4bca54
1 #!/bin/bash
2 # Manipulate options in a .config file from the command line
4 myname=${0##*/}
6 # If no prefix forced, use the default CONFIG_
7 CONFIG_="${CONFIG_-CONFIG_}"
9 usage() {
10 cat >&2 <<EOL
11 Manipulate options in a .config file from the command line.
12 Usage:
13 $myname options command ...
14 commands:
15 --enable|-e option Enable option
16 --disable|-d option Disable option
17 --module|-m option Turn option into a module
18 --set-str option string
19 Set option to "string"
20 --set-val option value
21 Set option to value
22 --undefine|-u option Undefine option
23 --state|-s option Print state of option (n,y,m,undef)
25 --enable-after|-E beforeopt option
26 Enable option directly after other option
27 --disable-after|-D beforeopt option
28 Disable option directly after other option
29 --module-after|-M beforeopt option
30 Turn option into module directly after other option
32 commands can be repeated multiple times
34 options:
35 --file config-file .config file to change (default .config)
36 --keep-case|-k Keep next symbols' case (dont' upper-case it)
38 $myname doesn't check the validity of the .config file. This is done at next
39 make time.
41 By default, $myname will upper-case the given symbol. Use --keep-case to keep
42 the case of all following symbols unchanged.
44 $myname uses 'CONFIG_' as the default symbol prefix. Set the environment
45 variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" $myname ...
46 EOL
47 exit 1
50 checkarg() {
51 ARG="$1"
52 if [ "$ARG" = "" ] ; then
53 usage
55 case "$ARG" in
56 ${CONFIG_}*)
57 ARG="${ARG/${CONFIG_}/}"
59 esac
60 if [ "$MUNGE_CASE" = "yes" ] ; then
61 ARG="`echo $ARG | tr a-z A-Z`"
65 txt_append() {
66 local anchor="$1"
67 local insert="$2"
68 local infile="$3"
69 local tmpfile="$infile.swp"
71 # sed append cmd: 'a\' + newline + text + newline
72 cmd="$(printf "a\\%b$insert" "\n")"
74 sed -e "/$anchor/$cmd" "$infile" >"$tmpfile"
75 # replace original file with the edited one
76 mv "$tmpfile" "$infile"
79 txt_subst() {
80 local before="$1"
81 local after="$2"
82 local infile="$3"
83 local tmpfile="$infile.swp"
85 sed -e "s:$before:$after:" "$infile" >"$tmpfile"
86 # replace original file with the edited one
87 mv "$tmpfile" "$infile"
90 txt_delete() {
91 local text="$1"
92 local infile="$2"
93 local tmpfile="$infile.swp"
95 sed -e "/$text/d" "$infile" >"$tmpfile"
96 # replace original file with the edited one
97 mv "$tmpfile" "$infile"
100 set_var() {
101 local name=$1 new=$2 before=$3
103 name_re="^($name=|# $name is not set)"
104 before_re="^($before=|# $before is not set)"
105 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
106 txt_append "^$before=" "$new" "$FN"
107 txt_append "^# $before is not set" "$new" "$FN"
108 elif grep -Eq "$name_re" "$FN"; then
109 txt_subst "^$name=.*" "$new" "$FN"
110 txt_subst "^# $name is not set" "$new" "$FN"
111 else
112 echo "$new" >>"$FN"
116 undef_var() {
117 local name=$1
119 txt_delete "^$name=" "$FN"
120 txt_delete "^# $name is not set" "$FN"
123 if [ "$1" = "--file" ]; then
124 FN="$2"
125 if [ "$FN" = "" ] ; then
126 usage
128 shift 2
129 else
130 FN=.config
133 if [ "$1" = "" ] ; then
134 usage
137 MUNGE_CASE=yes
138 while [ "$1" != "" ] ; do
139 CMD="$1"
140 shift
141 case "$CMD" in
142 --keep-case|-k)
143 MUNGE_CASE=no
144 continue
146 --refresh)
148 --*-after|-E|-D|-M)
149 checkarg "$1"
150 A=$ARG
151 checkarg "$2"
152 B=$ARG
153 shift 2
156 checkarg "$1"
157 shift
159 esac
160 case "$CMD" in
161 --enable|-e)
162 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
165 --disable|-d)
166 set_var "${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
169 --module|-m)
170 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
173 --set-str)
174 # sed swallows one level of escaping, so we need double-escaping
175 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
176 shift
179 --set-val)
180 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
181 shift
183 --undefine|-u)
184 undef_var "${CONFIG_}$ARG"
187 --state|-s)
188 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
189 echo n
190 else
191 V="$(grep "^${CONFIG_}$ARG=" $FN)"
192 if [ $? != 0 ] ; then
193 echo undef
194 else
195 V="${V/#${CONFIG_}$ARG=/}"
196 V="${V/#\"/}"
197 V="${V/%\"/}"
198 V="${V//\\\"/\"}"
199 echo "${V}"
204 --enable-after|-E)
205 set_var "${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
208 --disable-after|-D)
209 set_var "${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
212 --module-after|-M)
213 set_var "${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
216 # undocumented because it ignores --file (fixme)
217 --refresh)
218 yes "" | make oldconfig
222 usage
224 esac
225 done