1 ?RCS: $Id: Options.U,v 3.0.1.7 1997/02/28 15:08:15 ram Exp $
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
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.
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
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
19 ?RCS: Revision 3.0.1.5 1995/05/12 12:04:52 ram
20 ?RCS: patch54: added -K option for experts
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
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
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
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)
37 ?RCS: Revision 3.0 1993/08/18 12:05:14 ram
38 ?RCS: Baseline for dist 3.0 netwide release.
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
46 ?MAKE:Options: startsh
47 ?MAKE: -pick wipe $@ %<
48 ?V:reuseval alldone error realsilent silent extractsh fastread \
49 override knowitall: config_sh
50 ?T:arg argn symbol config_arg0 config_args config_argc xxx yyy zzz uuu
51 ?F:./optdef.sh ./cmdline.opt ./posthint.sh
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.
73 cat >>cmdline.opt <<EOSH
74 config_arg$argn='$arg'
79 : produce awk script to parse command line options
80 cat >options.awk <<'EOF'
82 optstr = "A:dD:eEf:hKOrsSU:V"; # getopt-style specification
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 = "";
99 if (substr(str, 1, 1) != "-") {
100 printf("'%s'\n", str);
104 for (i = 2; i <= len; i++) {
105 c = substr(str, i, 1);
107 printf("-%s\n", substr(str, i));
113 printf("'%s'\n", substr(str, i + 1));
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`
138 : set up default values
148 rm -f optdef.sh posthint.sh
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
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
168 while test $# -gt 0; do
170 -d) shift; fastread=yes;;
171 -e) shift; alldone=cont;;
175 if test -r "$1"; then
178 echo "$me: cannot read config file $1." >&2
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;;
194 echo "$me: use '-U symbol=', not '-D symbol='." >&2
195 echo "$me: ignoring -D $1" >&2
198 sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> optdef.sh;;
199 *) echo "$1='define'" >> optdef.sh;;
206 *=) echo "$1" >> optdef.sh;;
208 echo "$me: use '-D symbol=val', not '-U symbol=val'." >&2
209 echo "$me: ignoring -U $1" >&2
211 *) echo "$1='undef'" >> optdef.sh;;
222 *=*) zzz=`echo $yyy|sed 's!=.*!!'`
226 zzz=" "`echo $yyy|sed 's!^[^=]*=!!'`
227 yyy=`echo $yyy|sed 's!=.*!!'` ;;
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!^[^:]*:!!'` ;;
244 echo "$yyy=\"\${$yyy}$zzz\"" >> posthint.sh ;;
246 echo "$yyy=''" >> posthint.sh ;;
251 echo "$yyy='$zzz'" >> posthint.sh ;;
253 echo "eval \"$yyy=$zzz\"" >> posthint.sh ;;
255 echo "$yyy=\"$zzz\${$yyy}\"" >> posthint.sh ;;
260 echo "$yyy=$zzz" >> posthint.sh ;;
261 *) echo "$me: unknown -A command '$xxx', ignoring -A $1" >&2 ;;
264 -V) echo "$me generated by metaconfig <VERSION> PL<PATCHLEVEL>." >&2
267 -*) echo "$me: unknown option $1" >&2; shift; error=true;;
275 Usage: $me [-dehrsEKOSV] [-f config.sh] [-D symbol] [-D symbol=value]
276 [-U symbol] [-U symbol=] [-A command:symbol...]
277 -d : use defaults for all answers.
278 -e : go on without questioning past the production of config.sh.
279 -f : specify an alternate default configuration file.
280 -h : print this help message and exit (with an error status).
281 -r : reuse C symbols value if possible (skips costly nm extraction).
282 -s : silent mode, only echoes questions and essential information.
283 -D : define symbol to have some value:
284 -D symbol symbol gets the value 'define'
285 -D symbol=value symbol gets the value 'value'
286 -E : stop at the end of questions, after having produced config.sh.
287 -K : do not use unless you know what you are doing.
288 -O : let -D and -U override definitions from loaded configuration file.
289 -S : perform variable substitutions on all .SH files (can mix with -f)
290 -U : undefine symbol:
291 -U symbol symbol gets the value 'undef'
292 -U symbol= symbol gets completely empty
293 -A : manipulate symbol after the platform specific hints have been applied:
294 -A symbol=value append " "value to symbol
295 -A append:symbol=value append value to symbol
296 -A define:symbol=value define symbol to have value
297 -A clear:symbol define symbol to be ''
298 -A define:symbol define symbol to be 'define'
299 -A eval:symbol=value define symbol to be eval of value
300 -A prepend:symbol=value prepend value to symbol
301 -A undef:symbol define symbol to be 'undef'
302 -A undef:symbol= define symbol to be ''
303 -V : print version number and exit (with a zero status).
310 ?X: Unless they specified both -d and -e/E, make sure we're running
311 ?X: interactively, i.e. attached to a terminal. Moved from Head.U to be able
312 ?X: to handle batch configurations...
314 ?X: We have to hardwire the Configure name and cannot use $me, since if they
315 ?X: said 'sh <Configure', then $me is 'sh'...
318 case "$fastread$alldone" in
322 echo "Say 'sh Configure', not 'sh <Configure'"
328 ?X: In silent mode, the standard output is closed. Questions are asked by
329 ?X: outputing on file descriptor #4, which is the original stdout descriptor.
330 ?X: This filters out all the "junk", since all the needed information is written
331 ?X: on #4. Note that ksh will not let us redirect output if the file descriptor
332 ?X: has not be defined yet, unlike sh, hence the following line...--RAM.
335 true) exec 1>/dev/null;;
338 : run the defines and the undefines, if any, but leave the file out there...
341 : create the posthint manipulation script and leave the file out there...