This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Silence metalint
[metaconfig.git] / U / modified / Options.U
CommitLineData
3ad39853
MB
1?RCS: $Id: Options.U 1 2006-08-24 12:32:52Z rmanfredi $
2?RCS:
3?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
959f3c4c 4?RCS:
959f3c4c
JH
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
3ad39853 9?RCS: of the source tree for dist 4.0.
959f3c4c
JH
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 50?T:arg argn symbol config_arg0 config_args config_argc xxx yyy zzz uuu
91365186 51?T:args_exp args_sep arg_exp ccflags
3ad39853 52?F:!Configure
9b04e79a 53?F:./optdef.sh ./cmdline.opt ./posthint.sh ./cmdl.opt
959f3c4c
JH
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.
66cat > cmdline.opt <<EOSH
3ad39853 67: Configure command line arguments.
959f3c4c
JH
68config_arg0='$0'
69config_args='$*'
70config_argc=$#
71EOSH
72argn=1
875282d6
JH
73args_exp=''
74args_sep=''
959f3c4c
JH
75for arg in "$@"; do
76 cat >>cmdline.opt <<EOSH
77config_arg$argn='$arg'
78EOSH
3ad39853 79?X: Extreme backslashitis: replace each ' by '"'"'
875282d6
JH
80 cat <<EOC | sed -e "s/'/'"'"'"'"'"'"'/g" > cmdl.opt
81$arg
82EOC
83 arg_exp=`cat cmdl.opt`
84 args_exp="$args_exp$args_sep'$arg_exp'"
959f3c4c 85 argn=`expr $argn + 1`
875282d6 86 args_sep=' '
959f3c4c 87done
3ad39853
MB
88?X: args_exp is good for restarting self: eval "set X $args_exp"; shift; $0 "$@"
89?X: used by hints/os2.sh in Perl, for instance
875282d6 90rm -f cmdl.opt
959f3c4c
JH
91
92: produce awk script to parse command line options
93cat >options.awk <<'EOF'
94BEGIN {
c71449a6 95 optstr = "A:dD:eEf:hKOrsSU:V"; # getopt-style specification
959f3c4c
JH
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}
133END {
134 if (expect)
135 print "?";
136}
137EOF
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.
145set X `for arg in "$@"; do echo "X$arg"; done |
146 sed -e s/X// | awk -f options.awk`
147eval "set $*"
148shift
149rm -f options.awk
150
151: set up default values
152fastread=''
153reuseval=false
154config_sh=''
155alldone=''
156error=''
157silent=''
158extractsh=''
159override=''
160knowitall=''
c71449a6 161rm -f optdef.sh posthint.sh
959f3c4c
JH
162cat >optdef.sh <<EOS
163$startsh
164EOS
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
181while 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;;
d4b0fb96 196 --help|\
959f3c4c
JH
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;;
204 -D)
205 shift
206 case "$1" in
207 *=)
208 echo "$me: use '-U symbol=', not '-D symbol='." >&2
209 echo "$me: ignoring -D $1" >&2
210 ;;
211 *=*) echo "$1" | \
212 sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> optdef.sh;;
213 *) echo "$1='define'" >> optdef.sh;;
214 esac
215 shift
216 ;;
217 -U)
218 shift
219 case "$1" in
220 *=) echo "$1" >> optdef.sh;;
221 *=*)
222 echo "$me: use '-D symbol=val', not '-U symbol=val'." >&2
223 echo "$me: ignoring -U $1" >&2
224 ;;
225 *) echo "$1='undef'" >> optdef.sh;;
226 esac
227 shift
228 ;;
c71449a6
JH
229 -A)
230 shift
231 xxx=''
232 yyy="$1"
c71449a6 233 zzz=''
2256e445 234 uuu=undef
c71449a6 235 case "$yyy" in
e36eeeff 236 *=*) zzz=`echo "$yyy"|sed 's!=.*!!'`
2256e445
JH
237 case "$zzz" in
238 *:*) zzz='' ;;
239 *) xxx=append
3ad39853 240 zzz=" "`echo "$yyy"|sed 's!^[^=]*=!!'`
e36eeeff 241 yyy=`echo "$yyy"|sed 's!=.*!!'` ;;
2256e445
JH
242 esac
243 ;;
244 esac
245 case "$xxx" in
246 '') case "$yyy" in
e36eeeff
JH
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!^[^:]*:!!'` ;;
2256e445 253 esac
3ad39853 254 ;;
2256e445 255 esac
c71449a6
JH
256 case "$xxx" in
257 append)
2256e445 258 echo "$yyy=\"\${$yyy}$zzz\"" >> posthint.sh ;;
c71449a6 259 clear)
2256e445 260 echo "$yyy=''" >> posthint.sh ;;
c71449a6
JH
261 define)
262 case "$zzz" in
263 '') zzz=define ;;
264 esac
2256e445 265 echo "$yyy='$zzz'" >> posthint.sh ;;
c71449a6 266 eval)
2256e445 267 echo "eval \"$yyy=$zzz\"" >> posthint.sh ;;
c71449a6 268 prepend)
2256e445 269 echo "$yyy=\"$zzz\${$yyy}\"" >> posthint.sh ;;
c71449a6
JH
270 undef)
271 case "$zzz" in
272 '') zzz="$uuu" ;;
273 esac
2256e445
JH
274 echo "$yyy=$zzz" >> posthint.sh ;;
275 *) echo "$me: unknown -A command '$xxx', ignoring -A $1" >&2 ;;
c71449a6 276 esac
91985011 277 shift
c71449a6 278 ;;
959f3c4c 279 -V) echo "$me generated by metaconfig <VERSION> PL<PATCHLEVEL>." >&2
2256e445 280 exit 0;;
959f3c4c
JH
281 --) break;;
282 -*) echo "$me: unknown option $1" >&2; shift; error=true;;
283 *) break;;
284 esac
285done
286
287case "$error" in
288true)
289 cat >&2 <<EOM
290Usage: $me [-dehrsEKOSV] [-f config.sh] [-D symbol] [-D symbol=value]
c71449a6 291 [-U symbol] [-U symbol=] [-A command:symbol...]
959f3c4c
JH
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'
d4b0fb96
MB
301 common used examples (see INSTALL for more info):
302 -Duse64bitint use 64bit integers
234cf2bf 303 -Duse64bitall use 64bit integers and pointers
d4b0fb96 304 -Dusethreads use thread support
234cf2bf 305 -Dinc_version_list=none do not include older perl trees in @INC
d4b0fb96
MB
306 -DEBUGGING=none DEBUGGING options
307 -Dcc=gcc choose your compiler
308 -Dprefix=/opt/perl5 choose your destination
959f3c4c
JH
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
d4b0fb96 316 e.g.: -Uversiononly
c71449a6 317 -A : manipulate symbol after the platform specific hints have been applied:
49275c39
MB
318 -A append:symbol=value append value to symbol
319 -A symbol=value like append:, but with a separating space
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 ''
d4b0fb96 327 e.g.: -A prepend:libswanted='cl pthread '
49275c39 328 -A ccflags=-DSOME_MACRO
959f3c4c
JH
329 -V : print version number and exit (with a zero status).
330EOM
331 exit 1
332 ;;
333esac
334
335?X:
e02148a3
GS
336?X: Unless they specified either -S or both -d and -e/E, make sure we're
337?X: running interactively, i.e. attached to a terminal. Moved from Head.U to
338?X: be able to handle batch configurations...
959f3c4c
JH
339?X:
340?X: We have to hardwire the Configure name and cannot use $me, since if they
341?X: said 'sh <Configure', then $me is 'sh'...
342?X:
343: Sanity checks
344case "$fastread$alldone" in
345yescont|yesexit) ;;
346*)
e02148a3
GS
347 case "$extractsh" in
348 true) ;;
349 *)
350 if test ! -t 0; then
351 echo "Say 'sh Configure', not 'sh <Configure'"
352 exit 1
353 fi
354 ;;
355 esac
959f3c4c
JH
356 ;;
357esac
358
359?X: In silent mode, the standard output is closed. Questions are asked by
360?X: outputing on file descriptor #4, which is the original stdout descriptor.
361?X: This filters out all the "junk", since all the needed information is written
362?X: on #4. Note that ksh will not let us redirect output if the file descriptor
363?X: has not be defined yet, unlike sh, hence the following line...--RAM.
364exec 4>&1
365case "$silent" in
366true) exec 1>/dev/null;;
367esac
368
369: run the defines and the undefines, if any, but leave the file out there...
370touch optdef.sh
371. ./optdef.sh
c71449a6 372: create the posthint manipulation script and leave the file out there...
3ad39853 373?X: this file will be perused by Oldconfig.U
c71449a6 374touch posthint.sh
959f3c4c 375