This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Populate metaconfig branch.
[metaconfig.git] / U / modified / Options.U
CommitLineData
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
50?T:arg argn symbol config_arg0 config_args config_argc
51?F:./optdef.sh ./cmdline.opt
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.
65cat > cmdline.opt <<EOSH
66# Configure command line arguments.
67config_arg0='$0'
68config_args='$*'
69config_argc=$#
70EOSH
71argn=1
72for arg in "$@"; do
73 cat >>cmdline.opt <<EOSH
74config_arg$argn='$arg'
75EOSH
76 argn=`expr $argn + 1`
77done
78
79: produce awk script to parse command line options
80cat >options.awk <<'EOF'
81BEGIN {
82 optstr = "dD:eEf:hKOrsSU:V"; # getopt-style specification
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}
120END {
121 if (expect)
122 print "?";
123}
124EOF
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.
132set X `for arg in "$@"; do echo "X$arg"; done |
133 sed -e s/X// | awk -f options.awk`
134eval "set $*"
135shift
136rm -f options.awk
137
138: set up default values
139fastread=''
140reuseval=false
141config_sh=''
142alldone=''
143error=''
144silent=''
145extractsh=''
146override=''
147knowitall=''
148rm -f optdef.sh
149cat >optdef.sh <<EOS
150$startsh
151EOS
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
168while 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 ;;
215 -V) echo "$me generated by metaconfig <VERSION> PL<PATCHLEVEL>." >&2
216 exit 0;;
217 --) break;;
218 -*) echo "$me: unknown option $1" >&2; shift; error=true;;
219 *) break;;
220 esac
221done
222
223case "$error" in
224true)
225 cat >&2 <<EOM
226Usage: $me [-dehrsEKOSV] [-f config.sh] [-D symbol] [-D symbol=value]
227 [-U symbol] [-U symbol=]
228 -d : use defaults for all answers.
229 -e : go on without questioning past the production of config.sh.
230 -f : specify an alternate default configuration file.
231 -h : print this help message and exit (with an error status).
232 -r : reuse C symbols value if possible (skips costly nm extraction).
233 -s : silent mode, only echoes questions and essential information.
234 -D : define symbol to have some value:
235 -D symbol symbol gets the value 'define'
236 -D symbol=value symbol gets the value 'value'
237 -E : stop at the end of questions, after having produced config.sh.
238 -K : do not use unless you know what you are doing.
239 -O : let -D and -U override definitions from loaded configuration file.
240 -S : perform variable substitutions on all .SH files (can mix with -f)
241 -U : undefine symbol:
242 -U symbol symbol gets the value 'undef'
243 -U symbol= symbol gets completely empty
244 -V : print version number and exit (with a zero status).
245EOM
246 exit 1
247 ;;
248esac
249
250?X:
251?X: Unless they specified both -d and -e/E, make sure we're running
252?X: interactively, i.e. attached to a terminal. Moved from Head.U to be able
253?X: to handle batch configurations...
254?X:
255?X: We have to hardwire the Configure name and cannot use $me, since if they
256?X: said 'sh <Configure', then $me is 'sh'...
257?X:
258: Sanity checks
259case "$fastread$alldone" in
260yescont|yesexit) ;;
261*)
262 if test ! -t 0; then
263 echo "Say 'sh Configure', not 'sh <Configure'"
264 exit 1
265 fi
266 ;;
267esac
268
269?X: In silent mode, the standard output is closed. Questions are asked by
270?X: outputing on file descriptor #4, which is the original stdout descriptor.
271?X: This filters out all the "junk", since all the needed information is written
272?X: on #4. Note that ksh will not let us redirect output if the file descriptor
273?X: has not be defined yet, unlike sh, hence the following line...--RAM.
274exec 4>&1
275case "$silent" in
276true) exec 1>/dev/null;;
277esac
278
279: run the defines and the undefines, if any, but leave the file out there...
280touch optdef.sh
281. ./optdef.sh
282