This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RE: [perl #26136] localtime(3) calls tzset(3), but localtime_r(3) may not.
[metaconfig.git] / U / modified / Options.U
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
50 ?T:arg argn symbol config_arg0 config_args config_argc xxx yyy zzz uuu
51 ?T:args_exp args_sep arg_exp
52 ?F:./optdef.sh ./cmdline.opt ./posthint.sh ./cmdl.opt
53
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.
68 config_arg0='$0'
69 config_args='$*'
70 config_argc=$#
71 EOSH
72 argn=1
73 args_exp=''
74 args_sep=''
75 for arg in "$@"; do
76         cat >>cmdline.opt <<EOSH
77 config_arg$argn='$arg'
78 EOSH
79         # Extreme backslashitis: replace each ' by '"'"'
80         cat <<EOC | sed -e "s/'/'"'"'"'"'"'"'/g" > cmdl.opt
81 $arg
82 EOC
83         arg_exp=`cat cmdl.opt`
84         args_exp="$args_exp$args_sep'$arg_exp'"
85         argn=`expr $argn + 1`
86         args_sep=' '
87 done
88 # args_exp is good for restarting self: eval "set X $args_exp"; shift; $0 "$@"
89 # used by ./hints/os2.sh
90 rm -f cmdl.opt
91
92 : produce awk script to parse command line options
93 cat >options.awk <<'EOF'
94 BEGIN {
95         optstr = "A:dD:eEf:hKOrsSU:V";  # getopt-style specification
96
97         len = length(optstr);
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 = "";
102                 if (a == ":") {
103                         arg[c] = 1;
104                         i++;
105                 }
106                 opt[c] = 1;
107         }
108 }
109 {
110         expect = 0;
111         str = $0;
112         if (substr(str, 1, 1) != "-") {
113                 printf("'%s'\n", str);
114                 next;
115         }
116         len = length($0);
117         for (i = 2; i <= len; i++) {
118                 c = substr(str, i, 1);
119                 if (!opt[c]) {
120                         printf("-%s\n", substr(str, i));
121                         next;
122                 }
123                 printf("-%s\n", c);
124                 if (arg[c]) {
125                         if (i < len)
126                                 printf("'%s'\n", substr(str, i + 1));
127                         else
128                                 expect = 1;
129                         next;
130                 }
131         }
132 }
133 END {
134         if (expect)
135                 print "?";
136 }
137 EOF
138
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`
147 eval "set $*"
148 shift
149 rm -f options.awk
150
151 : set up default values
152 fastread=''
153 reuseval=false
154 config_sh=''
155 alldone=''
156 error=''
157 silent=''
158 extractsh=''
159 override=''
160 knowitall=''
161 rm -f optdef.sh posthint.sh
162 cat >optdef.sh <<EOS
163 $startsh
164 EOS
165
166 ?X:
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
171 ?X: screen...
172 ?X:
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
178 ?X:
179
180 : option parsing
181 while test $# -gt 0; do
182         case "$1" in
183         -d) shift; fastread=yes;;
184         -e) shift; alldone=cont;;
185         -f)
186                 shift
187                 cd ..
188                 if test -r "$1"; then
189                         config_sh="$1"
190                 else
191                         echo "$me: cannot read config file $1." >&2
192                         error=true
193                 fi
194                 cd UU
195                 shift;;
196         -h) shift; error=true;;
197         -r) shift; reuseval=true;;
198         -s) shift; silent=true; realsilent=true;;
199         -E) shift; alldone=exit;;
200         -K) shift; knowitall=true;;
201         -O) shift; override=true;;
202         -S) shift; silent=true; extractsh=true;;
203         -D)
204                 shift
205                 case "$1" in
206                 *=)
207                         echo "$me: use '-U symbol=', not '-D symbol='." >&2
208                         echo "$me: ignoring -D $1" >&2
209                         ;;
210                 *=*) echo "$1" | \
211                                 sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> optdef.sh;;
212                 *) echo "$1='define'" >> optdef.sh;;
213                 esac
214                 shift
215                 ;;
216         -U)
217                 shift
218                 case "$1" in
219                 *=) echo "$1" >> optdef.sh;;
220                 *=*)
221                         echo "$me: use '-D symbol=val', not '-U symbol=val'." >&2
222                         echo "$me: ignoring -U $1" >&2
223                         ;;
224                 *) echo "$1='undef'" >> optdef.sh;;
225                 esac
226                 shift
227                 ;;
228         -A)
229             shift
230             xxx=''
231             yyy="$1"
232             zzz=''
233             uuu=undef
234             case "$yyy" in
235             *=*) zzz=`echo "$yyy"|sed 's!=.*!!'`
236                  case "$zzz" in
237                  *:*) zzz='' ;;
238                  *)   xxx=append
239                       zzz=" "`echo "$yyy"|sed 's!^[^=]*=!!'` 
240                       yyy=`echo "$yyy"|sed 's!=.*!!'` ;;
241                  esac
242                  ;;
243             esac
244             case "$xxx" in
245             '')  case "$yyy" in
246                  *:*) xxx=`echo "$yyy"|sed 's!:.*!!'`
247                       yyy=`echo "$yyy"|sed 's!^[^:]*:!!'`
248                       zzz=`echo "$yyy"|sed 's!^[^=]*=!!'`
249                       yyy=`echo "$yyy"|sed 's!=.*!!'` ;;
250                  *)   xxx=`echo "$yyy"|sed 's!:.*!!'`
251                       yyy=`echo "$yyy"|sed 's!^[^:]*:!!'` ;;
252                  esac
253                  ;;       
254             esac
255             case "$xxx" in
256             append)
257                 echo "$yyy=\"\${$yyy}$zzz\""    >> posthint.sh ;;
258             clear)
259                 echo "$yyy=''"                  >> posthint.sh ;;
260             define)
261                 case "$zzz" in
262                 '') zzz=define ;;
263                 esac
264                 echo "$yyy='$zzz'"              >> posthint.sh ;;
265             eval)
266                 echo "eval \"$yyy=$zzz\""       >> posthint.sh ;;
267             prepend)
268                 echo "$yyy=\"$zzz\${$yyy}\""    >> posthint.sh ;;
269             undef)
270                 case "$zzz" in
271                 '') zzz="$uuu" ;;
272                 esac
273                 echo "$yyy=$zzz"                >> posthint.sh ;;
274             *)  echo "$me: unknown -A command '$xxx', ignoring -A $1" >&2 ;;
275             esac
276             shift
277             ;;
278         -V) echo "$me generated by metaconfig <VERSION> PL<PATCHLEVEL>." >&2
279             exit 0;;
280         --) break;;
281         -*) echo "$me: unknown option $1" >&2; shift; error=true;;
282         *) break;;
283         esac
284 done
285
286 case "$error" in
287 true)
288         cat >&2 <<EOM
289 Usage: $me [-dehrsEKOSV] [-f config.sh] [-D symbol] [-D symbol=value]
290                  [-U symbol] [-U symbol=] [-A command:symbol...]
291   -d : use defaults for all answers.
292   -e : go on without questioning past the production of config.sh.
293   -f : specify an alternate default configuration file.
294   -h : print this help message and exit (with an error status).
295   -r : reuse C symbols value if possible (skips costly nm extraction).
296   -s : silent mode, only echoes questions and essential information.
297   -D : define symbol to have some value:
298          -D symbol         symbol gets the value 'define'
299          -D symbol=value   symbol gets the value 'value'
300   -E : stop at the end of questions, after having produced config.sh.
301   -K : do not use unless you know what you are doing.
302   -O : let -D and -U override definitions from loaded configuration file.
303   -S : perform variable substitutions on all .SH files (can mix with -f)
304   -U : undefine symbol:
305          -U symbol    symbol gets the value 'undef'
306          -U symbol=   symbol gets completely empty
307   -A : manipulate symbol after the platform specific hints have been applied:
308          -A symbol=value                append " "value to symbol
309          -A append:symbol=value         append value to symbol
310          -A define:symbol=value         define symbol to have value
311          -A clear:symbol                define symbol to be ''
312          -A define:symbol               define symbol to be 'define'
313          -A eval:symbol=value           define symbol to be eval of value
314          -A prepend:symbol=value        prepend value to symbol
315          -A undef:symbol                define symbol to be 'undef'
316          -A undef:symbol=               define symbol to be ''
317   -V : print version number and exit (with a zero status).
318 EOM
319         exit 1
320         ;;
321 esac
322
323 ?X:
324 ?X: Unless they specified either -S or both -d and -e/E, make sure we're
325 ?X: running interactively, i.e. attached to a terminal. Moved from Head.U to
326 ?X: be able to handle batch configurations...
327 ?X:
328 ?X: We have to hardwire the Configure name and cannot use $me, since if they
329 ?X: said 'sh <Configure', then $me is 'sh'...
330 ?X:
331 : Sanity checks
332 case "$fastread$alldone" in
333 yescont|yesexit) ;;
334 *)
335         case "$extractsh" in
336         true) ;;
337         *)
338                 if test ! -t 0; then
339                         echo "Say 'sh Configure', not 'sh <Configure'"
340                         exit 1
341                 fi
342                 ;;
343         esac
344         ;;
345 esac
346
347 ?X: In silent mode, the standard output is closed. Questions are asked by
348 ?X: outputing on file descriptor #4, which is the original stdout descriptor.
349 ?X: This filters out all the "junk", since all the needed information is written
350 ?X: on #4. Note that ksh will not let us redirect output if the file descriptor
351 ?X: has not be defined yet, unlike sh, hence the following line...--RAM.
352 exec 4>&1
353 case "$silent" in
354 true) exec 1>/dev/null;;
355 esac
356
357 : run the defines and the undefines, if any, but leave the file out there...
358 touch optdef.sh
359 . ./optdef.sh
360 : create the posthint manipulation script and leave the file out there...
361 touch posthint.sh
362