cifs: update ctime and mtime during truncate
[linux/fpc-iii.git] / scripts / config
blob73de17d396987098ddab8fadcffc2ec81a7d8ebc
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 # We use an uncommon delimiter for sed substitutions
10 SED_DELIM=$(echo -en "\001")
12 usage() {
13 cat >&2 <<EOL
14 Manipulate options in a .config file from the command line.
15 Usage:
16 $myname options command ...
17 commands:
18 --enable|-e option Enable option
19 --disable|-d option Disable option
20 --module|-m option Turn option into a module
21 --set-str option string
22 Set option to "string"
23 --set-val option value
24 Set option to value
25 --undefine|-u option Undefine option
26 --state|-s option Print state of option (n,y,m,undef)
28 --enable-after|-E beforeopt option
29 Enable option directly after other option
30 --disable-after|-D beforeopt option
31 Disable option directly after other option
32 --module-after|-M beforeopt option
33 Turn option into module directly after other option
35 commands can be repeated multiple times
37 options:
38 --file config-file .config file to change (default .config)
39 --keep-case|-k Keep next symbols' case (dont' upper-case it)
41 $myname doesn't check the validity of the .config file. This is done at next
42 make time.
44 By default, $myname will upper-case the given symbol. Use --keep-case to keep
45 the case of all following symbols unchanged.
47 $myname uses 'CONFIG_' as the default symbol prefix. Set the environment
48 variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" $myname ...
49 EOL
50 exit 1
53 checkarg() {
54 ARG="$1"
55 if [ "$ARG" = "" ] ; then
56 usage
58 case "$ARG" in
59 ${CONFIG_}*)
60 ARG="${ARG/${CONFIG_}/}"
62 esac
63 if [ "$MUNGE_CASE" = "yes" ] ; then
64 ARG="`echo $ARG | tr a-z A-Z`"
68 txt_append() {
69 local anchor="$1"
70 local insert="$2"
71 local infile="$3"
72 local tmpfile="$infile.swp"
74 # sed append cmd: 'a\' + newline + text + newline
75 cmd="$(printf "a\\%b$insert" "\n")"
77 sed -e "/$anchor/$cmd" "$infile" >"$tmpfile"
78 # replace original file with the edited one
79 mv "$tmpfile" "$infile"
82 txt_subst() {
83 local before="$1"
84 local after="$2"
85 local infile="$3"
86 local tmpfile="$infile.swp"
88 sed -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmpfile"
89 # replace original file with the edited one
90 mv "$tmpfile" "$infile"
93 txt_delete() {
94 local text="$1"
95 local infile="$2"
96 local tmpfile="$infile.swp"
98 sed -e "/$text/d" "$infile" >"$tmpfile"
99 # replace original file with the edited one
100 mv "$tmpfile" "$infile"
103 set_var() {
104 local name=$1 new=$2 before=$3
106 name_re="^($name=|# $name is not set)"
107 before_re="^($before=|# $before is not set)"
108 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
109 txt_append "^$before=" "$new" "$FN"
110 txt_append "^# $before is not set" "$new" "$FN"
111 elif grep -Eq "$name_re" "$FN"; then
112 txt_subst "^$name=.*" "$new" "$FN"
113 txt_subst "^# $name is not set" "$new" "$FN"
114 else
115 echo "$new" >>"$FN"
119 undef_var() {
120 local name=$1
122 txt_delete "^$name=" "$FN"
123 txt_delete "^# $name is not set" "$FN"
126 if [ "$1" = "--file" ]; then
127 FN="$2"
128 if [ "$FN" = "" ] ; then
129 usage
131 shift 2
132 else
133 FN=.config
136 if [ "$1" = "" ] ; then
137 usage
140 MUNGE_CASE=yes
141 while [ "$1" != "" ] ; do
142 CMD="$1"
143 shift
144 case "$CMD" in
145 --keep-case|-k)
146 MUNGE_CASE=no
147 continue
149 --refresh)
151 --*-after|-E|-D|-M)
152 checkarg "$1"
153 A=$ARG
154 checkarg "$2"
155 B=$ARG
156 shift 2
159 checkarg "$1"
160 shift
162 esac
163 case "$CMD" in
164 --enable|-e)
165 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
168 --disable|-d)
169 set_var "${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
172 --module|-m)
173 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
176 --set-str)
177 # sed swallows one level of escaping, so we need double-escaping
178 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
179 shift
182 --set-val)
183 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
184 shift
186 --undefine|-u)
187 undef_var "${CONFIG_}$ARG"
190 --state|-s)
191 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
192 echo n
193 else
194 V="$(grep "^${CONFIG_}$ARG=" $FN)"
195 if [ $? != 0 ] ; then
196 echo undef
197 else
198 V="${V/#${CONFIG_}$ARG=/}"
199 V="${V/#\"/}"
200 V="${V/%\"/}"
201 V="${V//\\\"/\"}"
202 echo "${V}"
207 --enable-after|-E)
208 set_var "${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
211 --disable-after|-D)
212 set_var "${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
215 --module-after|-M)
216 set_var "${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
219 # undocumented because it ignores --file (fixme)
220 --refresh)
221 yes "" | make oldconfig
225 usage
227 esac
228 done