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 ?T:args_exp args_sep arg_exp libswanted
52 ?F:./optdef.sh ./cmdline.opt ./posthint.sh ./cmdl.opt
54 : Save command line options in file UU/cmdline.opt for later use in
55 : generating config.sh.
56 ?X: This temporary file will be read by Oldsym.U. I used a temporary
57 ?X: file to preserve all sorts of potential command line quotes and
58 ?X: also because we don't know in advance how many variables we'll
59 ?X: need, so I can't actually declare them on the MAKE line.
60 ?X: The config_args variable won't be quite correct if Configure is
61 ?X: fed something like ./Configure -Dcc="gcc -B/usr/ccs/bin/"
62 ?X: since the quotes are gone by the time we see them. You'd have to
63 ?X: reconstruct the command line from the config_arg? lines, but since
64 ?X: I don't imagine anyone actually having to do that, I'm not going
65 ?X: to worry too much.
66 cat > cmdline.opt <<EOSH
67 # Configure command line arguments.
76 cat >>cmdline.opt <<EOSH
77 config_arg$argn='$arg'
79 # Extreme backslashitis: replace each ' by '"'"'
80 cat <<EOC | sed -e "s/'/'"'"'"'"'"'"'/g" > cmdl.opt
83 arg_exp=`cat cmdl.opt`
84 args_exp="$args_exp$args_sep'$arg_exp'"
88 # args_exp is good for restarting self: eval "set X $args_exp"; shift; $0 "$@"
89 # used by ./hints/os2.sh
92 : produce awk script to parse command line options
93 cat >options.awk <<'EOF'
95 optstr = "A:dD:eEf:hKOrsSU:V"; # getopt-style specification
98 for (i = 1; i <= len; i++) {
99 c = substr(optstr, i, 1);
100 ?X: some older awk's do not have the C ?: construct
101 if (i < len) a = substr(optstr, i + 1, 1); else a = "";
112 if (substr(str, 1, 1) != "-") {
113 printf("'%s'\n", str);
117 for (i = 2; i <= len; i++) {
118 c = substr(str, i, 1);
120 printf("-%s\n", substr(str, i));
126 printf("'%s'\n", substr(str, i + 1));
139 : process the command line options
140 ?X: Use "$@" to keep arguments with spaces in them from being split apart.
141 ?X: For the same reason, awk will output quoted arguments and the final eval
142 ?X: removes them and sets a proper $* array. An 'X' is prependend to each
143 ?X: argument before being fed to echo to guard against 'echo -x', where -x
144 ?X: would be understood as an echo option! It is removed before feeding awk.
145 set X `for arg in "$@"; do echo "X$arg"; done |
146 sed -e s/X// | awk -f options.awk`
151 : set up default values
161 rm -f optdef.sh posthint.sh
167 ?X: Given that we now have the possibility to execute Configure remotely
168 ?X: thanks to the new src.U support, we have to face the possibility
169 ?X: of having to ask where the source lie, which means we need the Myread.U
170 ?X: stuff and possibly other things that might echo something on the
173 ?X: That's not pretty, and might be confusing in 99% of the time. So...
174 ?X: We introduce a new realsilent variable which is set when -s is given,
175 ?X: and we force silent=true if -S is supplied. The Extractall.U unit
176 ?X: will then undo the >&4 redirection based on the value of the
177 ?X: realsilent variable... -- RAM, 18/93/96
181 while test $# -gt 0; do
183 -d) shift; fastread=yes;;
184 -e) shift; alldone=cont;;
188 if test -r "$1"; then
191 echo "$me: cannot read config file $1." >&2
197 -h) shift; error=true;;
198 -r) shift; reuseval=true;;
199 -s) shift; silent=true; realsilent=true;;
200 -E) shift; alldone=exit;;
201 -K) shift; knowitall=true;;
202 -O) shift; override=true;;
203 -S) shift; silent=true; extractsh=true;;
208 echo "$me: use '-U symbol=', not '-D symbol='." >&2
209 echo "$me: ignoring -D $1" >&2
212 sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> optdef.sh;;
213 *) echo "$1='define'" >> optdef.sh;;
220 *=) echo "$1" >> optdef.sh;;
222 echo "$me: use '-D symbol=val', not '-U symbol=val'." >&2
223 echo "$me: ignoring -U $1" >&2
225 *) echo "$1='undef'" >> optdef.sh;;
236 *=*) zzz=`echo "$yyy"|sed 's!=.*!!'`
240 zzz=" "`echo "$yyy"|sed 's!^[^=]*=!!'`
241 yyy=`echo "$yyy"|sed 's!=.*!!'` ;;
247 *:*) xxx=`echo "$yyy"|sed 's!:.*!!'`
248 yyy=`echo "$yyy"|sed 's!^[^:]*:!!'`
249 zzz=`echo "$yyy"|sed 's!^[^=]*=!!'`
250 yyy=`echo "$yyy"|sed 's!=.*!!'` ;;
251 *) xxx=`echo "$yyy"|sed 's!:.*!!'`
252 yyy=`echo "$yyy"|sed 's!^[^:]*:!!'` ;;
258 echo "$yyy=\"\${$yyy}$zzz\"" >> posthint.sh ;;
260 echo "$yyy=''" >> posthint.sh ;;
265 echo "$yyy='$zzz'" >> posthint.sh ;;
267 echo "eval \"$yyy=$zzz\"" >> posthint.sh ;;
269 echo "$yyy=\"$zzz\${$yyy}\"" >> posthint.sh ;;
274 echo "$yyy=$zzz" >> posthint.sh ;;
275 *) echo "$me: unknown -A command '$xxx', ignoring -A $1" >&2 ;;
279 -V) echo "$me generated by metaconfig <VERSION> PL<PATCHLEVEL>." >&2
282 -*) echo "$me: unknown option $1" >&2; shift; error=true;;
290 Usage: $me [-dehrsEKOSV] [-f config.sh] [-D symbol] [-D symbol=value]
291 [-U symbol] [-U symbol=] [-A command:symbol...]
292 -d : use defaults for all answers.
293 -e : go on without questioning past the production of config.sh.
294 -f : specify an alternate default configuration file.
295 -h : print this help message and exit (with an error status).
296 -r : reuse C symbols value if possible (skips costly nm extraction).
297 -s : silent mode, only echoes questions and essential information.
298 -D : define symbol to have some value:
299 -D symbol symbol gets the value 'define'
300 -D symbol=value symbol gets the value 'value'
301 common used examples (see INSTALL for more info):
302 -Duse64bitint use 64bit integers
303 -Duse64bitall use 64bit inttegers and pointers
304 -Dusethreads use thread support
305 -Dinc_version_list=none do not include older perl treess in @INC
306 -DEBUGGING=none DEBUGGING options
307 -Dcc=gcc choose your compiler
308 -Dprefix=/opt/perl5 choose your destination
309 -E : stop at the end of questions, after having produced config.sh.
310 -K : do not use unless you know what you are doing.
311 -O : let -D and -U override definitions from loaded configuration file.
312 -S : perform variable substitutions on all .SH files (can mix with -f)
313 -U : undefine symbol:
314 -U symbol symbol gets the value 'undef'
315 -U symbol= symbol gets completely empty
317 -A : manipulate symbol after the platform specific hints have been applied:
318 -A symbol=value append " "value to symbol
319 -A append:symbol=value append value to symbol
320 -A define:symbol=value define symbol to have value
321 -A clear:symbol define symbol to be ''
322 -A define:symbol define symbol to be 'define'
323 -A eval:symbol=value define symbol to be eval of value
324 -A prepend:symbol=value prepend value to symbol
325 -A undef:symbol define symbol to be 'undef'
326 -A undef:symbol= define symbol to be ''
327 e.g.: -A prepend:libswanted='cl pthread '
328 -V : print version number and exit (with a zero status).
335 ?X: Unless they specified either -S or both -d and -e/E, make sure we're
336 ?X: running interactively, i.e. attached to a terminal. Moved from Head.U to
337 ?X: be able to handle batch configurations...
339 ?X: We have to hardwire the Configure name and cannot use $me, since if they
340 ?X: said 'sh <Configure', then $me is 'sh'...
343 case "$fastread$alldone" in
350 echo "Say 'sh Configure', not 'sh <Configure'"
358 ?X: In silent mode, the standard output is closed. Questions are asked by
359 ?X: outputing on file descriptor #4, which is the original stdout descriptor.
360 ?X: This filters out all the "junk", since all the needed information is written
361 ?X: on #4. Note that ksh will not let us redirect output if the file descriptor
362 ?X: has not be defined yet, unlike sh, hence the following line...--RAM.
365 true) exec 1>/dev/null;;
368 : run the defines and the undefines, if any, but leave the file out there...
371 : create the posthint manipulation script and leave the file out there...