Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: Options.U,v 3.0.1.7 1997/02/28 15:08:15 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
4 | ?RCS: | |
5 | ?RCS: You may redistribute only under the terms of the Artistic Licence, | |
6 | ?RCS: as specified in the README file that comes with the distribution. | |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
8 | ?RCS: that same Artistic Licence; a copy of which may be found at the root | |
9 | ?RCS: of the source tree for dist 3.0. | |
10 | ?RCS: | |
11 | ?RCS: $Log: Options.U,v $ | |
12 | ?RCS: Revision 3.0.1.7 1997/02/28 15:08:15 ram | |
13 | ?RCS: patch61: optdef.sh now starts with a "startsh" | |
14 | ?RCS: patch61: moved some code from Head.U | |
15 | ?RCS: | |
16 | ?RCS: Revision 3.0.1.6 1995/09/25 09:14:46 ram | |
17 | ?RCS: patch59: protected option parsing code against 'echo -*' option failure | |
18 | ?RCS: | |
19 | ?RCS: Revision 3.0.1.5 1995/05/12 12:04:52 ram | |
20 | ?RCS: patch54: added -K option for experts | |
21 | ?RCS: | |
22 | ?RCS: Revision 3.0.1.4 1995/01/30 14:27:52 ram | |
23 | ?RCS: patch49: this unit now exports file optdef.sh, not a variable | |
24 | ?RCS: | |
25 | ?RCS: Revision 3.0.1.3 1995/01/11 15:19:00 ram | |
26 | ?RCS: patch45: new -O option allowing -D and -U to override config.sh setttings | |
27 | ?RCS: patch45: file optdef.sh is no longer removed after sourcing | |
28 | ?RCS: | |
29 | ?RCS: Revision 3.0.1.2 1994/10/29 15:58:06 ram | |
30 | ?RCS: patch36: ensure option definition file is removed before appending | |
31 | ?RCS: patch36: protect variable definitions with spaces in them | |
32 | ?RCS: | |
33 | ?RCS: Revision 3.0.1.1 1994/06/20 06:55:44 ram | |
34 | ?RCS: patch30: now uses new me symbol to tag error messages | |
35 | ?RCS: patch30: new -D and -U options to define/undef symbols (JHI) | |
36 | ?RCS: | |
37 | ?RCS: Revision 3.0 1993/08/18 12:05:14 ram | |
38 | ?RCS: Baseline for dist 3.0 netwide release. | |
39 | ?RCS: | |
40 | ?X: | |
41 | ?X: Command line parsing. It is really important that the variables used here | |
42 | ?X: be not listed in the MAKE line, or they will be saved in config.sh and | |
43 | ?X: loading this file to fetch default answers would clobber the values set | |
44 | ?X: herein. | |
45 | ?X: | |
46 | ?MAKE:Options: startsh | |
47 | ?MAKE: -pick wipe $@ %< | |
48 | ?V:reuseval alldone error realsilent silent extractsh fastread \ | |
49 | override knowitall: config_sh | |
c71449a6 JH |
50 | ?T:arg argn symbol config_arg0 config_args config_argc xxx yyy zzz uuu |
51 | ?F:./optdef.sh ./cmdline.opt ./posthint.sh | |
959f3c4c JH |
52 | |
53 | : Save command line options in file UU/cmdline.opt for later use in | |
54 | : generating config.sh. | |
55 | ?X: This temporary file will be read by Oldsym.U. I used a temporary | |
56 | ?X: file to preserve all sorts of potential command line quotes and | |
57 | ?X: also because we don't know in advance how many variables we'll | |
58 | ?X: need, so I can't actually declare them on the MAKE line. | |
59 | ?X: The config_args variable won't be quite correct if Configure is | |
60 | ?X: fed something like ./Configure -Dcc="gcc -B/usr/ccs/bin/" | |
61 | ?X: since the quotes are gone by the time we see them. You'd have to | |
62 | ?X: reconstruct the command line from the config_arg? lines, but since | |
63 | ?X: I don't imagine anyone actually having to do that, I'm not going | |
64 | ?X: to worry too much. | |
65 | cat > cmdline.opt <<EOSH | |
66 | # Configure command line arguments. | |
67 | config_arg0='$0' | |
68 | config_args='$*' | |
69 | config_argc=$# | |
70 | EOSH | |
71 | argn=1 | |
72 | for arg in "$@"; do | |
73 | cat >>cmdline.opt <<EOSH | |
74 | config_arg$argn='$arg' | |
75 | EOSH | |
76 | argn=`expr $argn + 1` | |
77 | done | |
78 | ||
79 | : produce awk script to parse command line options | |
80 | cat >options.awk <<'EOF' | |
81 | BEGIN { | |
c71449a6 | 82 | optstr = "A:dD:eEf:hKOrsSU:V"; # getopt-style specification |
959f3c4c JH |
83 | |
84 | len = length(optstr); | |
85 | for (i = 1; i <= len; i++) { | |
86 | c = substr(optstr, i, 1); | |
87 | ?X: some older awk's do not have the C ?: construct | |
88 | if (i < len) a = substr(optstr, i + 1, 1); else a = ""; | |
89 | if (a == ":") { | |
90 | arg[c] = 1; | |
91 | i++; | |
92 | } | |
93 | opt[c] = 1; | |
94 | } | |
95 | } | |
96 | { | |
97 | expect = 0; | |
98 | str = $0; | |
99 | if (substr(str, 1, 1) != "-") { | |
100 | printf("'%s'\n", str); | |
101 | next; | |
102 | } | |
103 | len = length($0); | |
104 | for (i = 2; i <= len; i++) { | |
105 | c = substr(str, i, 1); | |
106 | if (!opt[c]) { | |
107 | printf("-%s\n", substr(str, i)); | |
108 | next; | |
109 | } | |
110 | printf("-%s\n", c); | |
111 | if (arg[c]) { | |
112 | if (i < len) | |
113 | printf("'%s'\n", substr(str, i + 1)); | |
114 | else | |
115 | expect = 1; | |
116 | next; | |
117 | } | |
118 | } | |
119 | } | |
120 | END { | |
121 | if (expect) | |
122 | print "?"; | |
123 | } | |
124 | EOF | |
125 | ||
126 | : process the command line options | |
127 | ?X: Use "$@" to keep arguments with spaces in them from being split apart. | |
128 | ?X: For the same reason, awk will output quoted arguments and the final eval | |
129 | ?X: removes them and sets a proper $* array. An 'X' is prependend to each | |
130 | ?X: argument before being fed to echo to guard against 'echo -x', where -x | |
131 | ?X: would be understood as an echo option! It is removed before feeding awk. | |
132 | set X `for arg in "$@"; do echo "X$arg"; done | | |
133 | sed -e s/X// | awk -f options.awk` | |
134 | eval "set $*" | |
135 | shift | |
136 | rm -f options.awk | |
137 | ||
138 | : set up default values | |
139 | fastread='' | |
140 | reuseval=false | |
141 | config_sh='' | |
142 | alldone='' | |
143 | error='' | |
144 | silent='' | |
145 | extractsh='' | |
146 | override='' | |
147 | knowitall='' | |
c71449a6 | 148 | rm -f optdef.sh posthint.sh |
959f3c4c JH |
149 | cat >optdef.sh <<EOS |
150 | $startsh | |
151 | EOS | |
152 | ||
153 | ?X: | |
154 | ?X: Given that we now have the possibility to execute Configure remotely | |
155 | ?X: thanks to the new src.U support, we have to face the possibility | |
156 | ?X: of having to ask where the source lie, which means we need the Myread.U | |
157 | ?X: stuff and possibly other things that might echo something on the | |
158 | ?X: screen... | |
159 | ?X: | |
160 | ?X: That's not pretty, and might be confusing in 99% of the time. So... | |
161 | ?X: We introduce a new realsilent variable which is set when -s is given, | |
162 | ?X: and we force silent=true if -S is supplied. The Extractall.U unit | |
163 | ?X: will then undo the >&4 redirection based on the value of the | |
164 | ?X: realsilent variable... -- RAM, 18/93/96 | |
165 | ?X: | |
166 | ||
167 | : option parsing | |
168 | while test $# -gt 0; do | |
169 | case "$1" in | |
170 | -d) shift; fastread=yes;; | |
171 | -e) shift; alldone=cont;; | |
172 | -f) | |
173 | shift | |
174 | cd .. | |
175 | if test -r "$1"; then | |
176 | config_sh="$1" | |
177 | else | |
178 | echo "$me: cannot read config file $1." >&2 | |
179 | error=true | |
180 | fi | |
181 | cd UU | |
182 | shift;; | |
183 | -h) shift; error=true;; | |
184 | -r) shift; reuseval=true;; | |
185 | -s) shift; silent=true; realsilent=true;; | |
186 | -E) shift; alldone=exit;; | |
187 | -K) shift; knowitall=true;; | |
188 | -O) shift; override=true;; | |
189 | -S) shift; silent=true; extractsh=true;; | |
190 | -D) | |
191 | shift | |
192 | case "$1" in | |
193 | *=) | |
194 | echo "$me: use '-U symbol=', not '-D symbol='." >&2 | |
195 | echo "$me: ignoring -D $1" >&2 | |
196 | ;; | |
197 | *=*) echo "$1" | \ | |
198 | sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> optdef.sh;; | |
199 | *) echo "$1='define'" >> optdef.sh;; | |
200 | esac | |
201 | shift | |
202 | ;; | |
203 | -U) | |
204 | shift | |
205 | case "$1" in | |
206 | *=) echo "$1" >> optdef.sh;; | |
207 | *=*) | |
208 | echo "$me: use '-D symbol=val', not '-U symbol=val'." >&2 | |
209 | echo "$me: ignoring -U $1" >&2 | |
210 | ;; | |
211 | *) echo "$1='undef'" >> optdef.sh;; | |
212 | esac | |
213 | shift | |
214 | ;; | |
c71449a6 JH |
215 | -A) |
216 | shift | |
217 | xxx='' | |
218 | yyy="$1" | |
c71449a6 | 219 | zzz='' |
2256e445 | 220 | uuu=undef |
c71449a6 | 221 | case "$yyy" in |
2256e445 JH |
222 | *=*) zzz=`echo $yyy|sed 's!=.*!!'` |
223 | case "$zzz" in | |
224 | *:*) zzz='' ;; | |
225 | *) xxx=append | |
226 | zzz=" "`echo $yyy|sed 's!^[^=]*=!!'` | |
227 | yyy=`echo $yyy|sed 's!=.*!!'` ;; | |
228 | esac | |
229 | ;; | |
230 | esac | |
231 | case "$xxx" in | |
232 | '') case "$yyy" in | |
233 | *:*) xxx=`echo $yyy|sed 's!:.*!!'` | |
234 | yyy=`echo $yyy|sed 's!^[^:]*:!!'` | |
235 | zzz=`echo $yyy|sed 's!^[^=]*=!!'` | |
236 | yyy=`echo $yyy|sed 's!=.*!!'` ;; | |
237 | *) xxx=`echo $yyy|sed 's!:.*!!'` | |
238 | yyy=`echo $yyy|sed 's!^[^:]*:!!'` ;; | |
239 | esac | |
240 | ;; | |
241 | esac | |
c71449a6 JH |
242 | case "$xxx" in |
243 | append) | |
2256e445 | 244 | echo "$yyy=\"\${$yyy}$zzz\"" >> posthint.sh ;; |
c71449a6 | 245 | clear) |
2256e445 | 246 | echo "$yyy=''" >> posthint.sh ;; |
c71449a6 JH |
247 | define) |
248 | case "$zzz" in | |
249 | '') zzz=define ;; | |
250 | esac | |
2256e445 | 251 | echo "$yyy='$zzz'" >> posthint.sh ;; |
c71449a6 | 252 | eval) |
2256e445 | 253 | echo "eval \"$yyy=$zzz\"" >> posthint.sh ;; |
c71449a6 | 254 | prepend) |
2256e445 | 255 | echo "$yyy=\"$zzz\${$yyy}\"" >> posthint.sh ;; |
c71449a6 JH |
256 | undef) |
257 | case "$zzz" in | |
258 | '') zzz="$uuu" ;; | |
259 | esac | |
2256e445 JH |
260 | echo "$yyy=$zzz" >> posthint.sh ;; |
261 | *) echo "$me: unknown -A command '$xxx', ignoring -A $1" >&2 ;; | |
c71449a6 | 262 | esac |
91985011 | 263 | shift |
c71449a6 | 264 | ;; |
959f3c4c | 265 | -V) echo "$me generated by metaconfig <VERSION> PL<PATCHLEVEL>." >&2 |
2256e445 | 266 | exit 0;; |
959f3c4c JH |
267 | --) break;; |
268 | -*) echo "$me: unknown option $1" >&2; shift; error=true;; | |
269 | *) break;; | |
270 | esac | |
271 | done | |
272 | ||
273 | case "$error" in | |
274 | true) | |
275 | cat >&2 <<EOM | |
276 | Usage: $me [-dehrsEKOSV] [-f config.sh] [-D symbol] [-D symbol=value] | |
c71449a6 | 277 | [-U symbol] [-U symbol=] [-A command:symbol...] |
959f3c4c JH |
278 | -d : use defaults for all answers. |
279 | -e : go on without questioning past the production of config.sh. | |
280 | -f : specify an alternate default configuration file. | |
281 | -h : print this help message and exit (with an error status). | |
282 | -r : reuse C symbols value if possible (skips costly nm extraction). | |
283 | -s : silent mode, only echoes questions and essential information. | |
284 | -D : define symbol to have some value: | |
285 | -D symbol symbol gets the value 'define' | |
286 | -D symbol=value symbol gets the value 'value' | |
287 | -E : stop at the end of questions, after having produced config.sh. | |
288 | -K : do not use unless you know what you are doing. | |
289 | -O : let -D and -U override definitions from loaded configuration file. | |
290 | -S : perform variable substitutions on all .SH files (can mix with -f) | |
291 | -U : undefine symbol: | |
292 | -U symbol symbol gets the value 'undef' | |
293 | -U symbol= symbol gets completely empty | |
c71449a6 | 294 | -A : manipulate symbol after the platform specific hints have been applied: |
2256e445 | 295 | -A symbol=value append " "value to symbol |
c71449a6 JH |
296 | -A append:symbol=value append value to symbol |
297 | -A define:symbol=value define symbol to have value | |
c71449a6 JH |
298 | -A clear:symbol define symbol to be '' |
299 | -A define:symbol define symbol to be 'define' | |
300 | -A eval:symbol=value define symbol to be eval of value | |
301 | -A prepend:symbol=value prepend value to symbol | |
302 | -A undef:symbol define symbol to be 'undef' | |
303 | -A undef:symbol= define symbol to be '' | |
959f3c4c JH |
304 | -V : print version number and exit (with a zero status). |
305 | EOM | |
306 | exit 1 | |
307 | ;; | |
308 | esac | |
309 | ||
310 | ?X: | |
e02148a3 GS |
311 | ?X: Unless they specified either -S or both -d and -e/E, make sure we're |
312 | ?X: running interactively, i.e. attached to a terminal. Moved from Head.U to | |
313 | ?X: be able to handle batch configurations... | |
959f3c4c JH |
314 | ?X: |
315 | ?X: We have to hardwire the Configure name and cannot use $me, since if they | |
316 | ?X: said 'sh <Configure', then $me is 'sh'... | |
317 | ?X: | |
318 | : Sanity checks | |
319 | case "$fastread$alldone" in | |
320 | yescont|yesexit) ;; | |
321 | *) | |
e02148a3 GS |
322 | case "$extractsh" in |
323 | true) ;; | |
324 | *) | |
325 | if test ! -t 0; then | |
326 | echo "Say 'sh Configure', not 'sh <Configure'" | |
327 | exit 1 | |
328 | fi | |
329 | ;; | |
330 | esac | |
959f3c4c JH |
331 | ;; |
332 | esac | |
333 | ||
334 | ?X: In silent mode, the standard output is closed. Questions are asked by | |
335 | ?X: outputing on file descriptor #4, which is the original stdout descriptor. | |
336 | ?X: This filters out all the "junk", since all the needed information is written | |
337 | ?X: on #4. Note that ksh will not let us redirect output if the file descriptor | |
338 | ?X: has not be defined yet, unlike sh, hence the following line...--RAM. | |
339 | exec 4>&1 | |
340 | case "$silent" in | |
341 | true) exec 1>/dev/null;; | |
342 | esac | |
343 | ||
344 | : run the defines and the undefines, if any, but leave the file out there... | |
345 | touch optdef.sh | |
346 | . ./optdef.sh | |
c71449a6 JH |
347 | : create the posthint manipulation script and leave the file out there... |
348 | touch posthint.sh | |
959f3c4c | 349 |