This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[win32] another toke.c maintpatch
[perl5.git] / vms / genconfig.pl
CommitLineData
a0d0e21e
LW
1#!/usr/bin/perl
2# Habit . . .
3#
4# Extract info from Config.VMS, and add extra data here, to generate Config.sh
5# Edit the static information after __END__ to reflect your site and options
748a9306
LW
6# that went into your perl binary. In addition, values which change from run
7# to run may be supplied on the command line as key=val pairs.
a0d0e21e 8#
61bb5906 9# Rev. 10-Nov-1997 Charles Bailey bailey@newman.upenn.edu
a0d0e21e
LW
10#
11
7aa5c81f 12#==== Locations of installed Perl components
13$prefix='perl_root';
14$builddir="$prefix:[000000]";
15$installbin="$prefix:[000000]";
edc7bc49 16$installscript="$prefix:[000000]";
7aa5c81f 17$installman1dir="$prefix:[man.man1]";
18$installman3dir="$prefix:[man.man3]";
19$installprivlib="$prefix:[lib]";
edc7bc49 20$installsitelib="$prefix:[lib.site_perl]";
7aa5c81f 21
a0d0e21e
LW
22unshift(@INC,'lib'); # In case someone didn't define Perl_Root
23 # before the build
a0d0e21e 24
a5f75d66
AD
25if ($ARGV[0] eq '-f') {
26 open(ARGS,$ARGV[1]) or die "Can't read data from $ARGV[1]: $!\n";
27 @ARGV = ();
28 while (<ARGS>) {
29 push(@ARGV,split(/\|/,$_));
30 }
31 close ARGS;
32}
33
a0d0e21e
LW
34if (-f "config.vms") { $infile = "config.vms"; $outdir = "[-]"; }
35elsif (-f "[.vms]config.vms") { $infile = "[.vms]config.vms"; $outdir = "[]"; }
36elsif (-f "config.h") { $infile = "config.h"; $outdir = "[]";}
37
38if ($infile) { print "Generating Config.sh from $infile . . .\n"; }
39else { die <<EndOfGasp;
40Can't find config.vms or config.h to read!
41 Please run this script from the perl source directory or
42 the VMS subdirectory in the distribution.
43EndOfGasp
44}
45$outdir = '';
46open(IN,"$infile") || die "Can't open $infile: $!\n";
47open(OUT,">${outdir}Config.sh") || die "Can't open ${outdir}Config.sh: $!\n";
a0d0e21e 48
e518068a 49$time = localtime;
7aa5c81f 50$cf_by = (getpwuid($<))[0];
51$archsufx = `Write Sys\$Output F\$GetSyi("HW_MODEL")` > 1024 ? 'AXP' : 'VAX';
52($vers = $]) =~ tr/./_/;
53$installarchlib = VMS::Filespec::vmspath($installprivlib);
54$installarchlib =~ s#\]#.VMS_$archsufx.$vers\]#;
edc7bc49
CB
55$installsitearch = VMS::Filespec::vmspath($installsitelib);
56$installsitearch =~ s#\]#.VMS_$archsufx\]#;
7aa5c81f 57($osvers = `Write Sys\$Output F\$GetSyi("VERSION")`) =~ s/^V?(\S+)\s*\n?$/$1/;
58
748a9306 59print OUT <<EndOfIntro;
a0d0e21e
LW
60# This file generated by GenConfig.pl on a VMS system.
61# Input obtained from:
62# $infile
63# $0
64# Time: $time
65
e518068a 66package='perl5'
67CONFIG='true'
68cf_time='$time'
7aa5c81f 69cf_by='$cf_by'
fc1ce8cc
CB
70ccdlflags='undef'
71cccdlflags='undef'
72mab='undef'
7aa5c81f 73libpth='/sys\$share /sys\$library'
e518068a 74ld='Link'
75lddlflags='/Share'
fc1ce8cc
CB
76ranlib='undef'
77ar='undef'
e518068a 78eunicefix=':'
c07a80fd 79hint='none'
fc1ce8cc 80hintfile='undef'
61bb5906 81useshrplib='define'
e518068a 82usemymalloc='n'
7aa5c81f 83usevfork='true'
c07a80fd 84spitshell='write sys\$output '
7aa5c81f 85dlsrc='dl_vms.c'
86binexp='$installbin'
87man1ext='rno'
88man3ext='rno'
89arch='VMS_$archsufx'
90archname='VMS_$archsufx'
91osvers='$osvers'
92prefix='$prefix'
93builddir='$builddir'
94installbin='$installbin'
edc7bc49 95installscript='$installscript'
7aa5c81f 96installman1dir='$installman1dir'
97installman3dir='$installman3dir'
98installprivlib='$installprivlib'
99installarchlib='$installarchlib'
edc7bc49
CB
100installsitelib='$installsitelib'
101installsitearch='$installsitearch'
774d564b 102path_sep='|'
103startperl='\$ perl 'f\$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' !
4fdae800 104\$ exit++ + ++\$status != 0 and \$exit = \$status = undef;'
a0d0e21e
LW
105EndOfIntro
106
748a9306
LW
107foreach (@ARGV) {
108 ($key,$val) = split('=',$_,2);
e518068a 109 if ($key eq 'cc') { # Figure out which C compiler we're using
c07a80fd 110 my($cc,$ccflags) = split('/',$val,2);
111 my($d_attr);
112 $ccflags = "/$ccflags";
113 if ($ccflags =~s!/DECC!!ig) {
114 $cc .= '/DECC';
115 $cctype = 'decc';
116 $d_attr = 'undef';
117 }
118 elsif ($ccflags =~s!/VAXC!!ig) {
119 $cc .= '/VAXC';
120 $cctype = 'vaxc';
121 $d_attr = 'undef';
122 }
7aa5c81f 123 elsif (`$val/NoObject/NoList _nla0:/Version` =~ /GNU C version (\S+)/) {
c07a80fd 124 $cctype = 'gcc';
125 $d_attr = 'define';
7aa5c81f 126 print OUT "gccversion='$1'\n";
e518068a 127 }
128 elsif ($archsufx eq 'VAX' &&
71be2cbc 129 # Check exit status too, in case message is turned off
130 ( `$val/NoObject/NoList /prefix=all _nla0:` =~ /IVQUAL/ ||
131 $? == 0x38240 )) {
c07a80fd 132 $cctype = 'vaxc';
133 $d_attr = 'undef';
e518068a 134 }
135 else {
c07a80fd 136 $cctype = 'decc';
137 $d_attr = 'undef';
138 }
139 print OUT "vms_cc_type='$cctype'\n";
140 print OUT "d_attribut='$d_attr'\n";
141 print OUT "cc='$cc'\n";
142 if ( ($cctype eq 'decc' and $archsufx eq 'VAX') || $cctype eq 'gcc') {
143 # gcc and DECC for VAX requires filename in /object qualifier, so we
e518068a 144 # have to remove it here. Alas, this means we lose the user's
145 # object file suffix if it's not .obj.
c07a80fd 146 $ccflags =~ s#/obj(?:ect)?=[^/\s]+##i;
e518068a 147 }
61bb5906
CB
148 $debug = $optimize = '';
149 while ( ($qual) = $ccflags =~ m|(/(No)?Deb[^/]*)|i ) {
150 $debug = $qual;
151 $ccflags =~ s/$qual//;
152 }
153 while ( ($qual) = $ccflags =~ m|(/(No)?Opt[^/]*)|i ) {
154 $optimize = $qual;
155 $ccflags =~ s/$qual//;
156 }
157 $optimize = "$debug$optimize";
c07a80fd 158 print OUT "ccflags='$ccflags'\n";
61bb5906
CB
159 print OUT "optimize='$optimize'\n";
160 $usethreads = ($ccflags =~ m!/DEF[^/]+USE_THREADS!i and
161 $ccflags !~ m!/UND[^/]+USE_THREADS!i);
162 print OUT "usethreads='$usethreads'\n";
c07a80fd 163 $dosock = ($ccflags =~ m!/DEF[^/]+VMS_DO_SOCKETS!i and
164 $ccflags !~ m!/UND[^/]+VMS_DO_SOCKETS!i);
7aa5c81f 165 print OUT "d_vms_do_sockets=",$dosock ? "'define'\n" : "'undef'\n";
166 print OUT "d_socket=",$dosock ? "'define'\n" : "'undef'\n";
167 print OUT "d_sockpair=",$dosock ? "'define'\n" : "'undef'\n";
168 print OUT "d_gethent=",$dosock ? "'define'\n" : "'undef'\n";
169 print OUT "d_select=",$dosock ? "'define'\n" : "'undef'\n";
fc1ce8cc 170 print OUT "i_netdb=",$dosock ? "'define'\n" : "'undef'\n";
7aa5c81f 171 print OUT "i_niin=",$dosock ? "'define'\n" : "'undef'\n";
172 print OUT "i_neterrno=",$dosock ? "'define'\n" : "'undef'\n";
fc1ce8cc
CB
173 print OUT "d_gethbadd=",$dosock ? "'define'\n" : "'undef'\n";
174 print OUT "gethbadd_addr_type=",$dosock ? "'char *'\n" : "'undef'\n";
175 print OUT "gethbadd_alen_type=",$dosock ? "'int'\n" : "'undef'\n";
176
61bb5906 177 if ($dosock and $cctype eq 'decc' and $ccflags =~ /DECCRTL_SOCKETS/) {
fc1ce8cc
CB
178 print OUT "selecttype='fd_set'\n";
179 print OUT "d_getnbadd='define'\n";
180 print OUT "getnbadd_net_type='long'\n";
181 }
182 else {
183 print OUT "selecttype='int'\n";
184 print OUT "d_getnbadd='undef'\n";
185 print OUT "getnbadd_net_type='undef'\n";
61bb5906 186 }
edc7bc49 187
61bb5906
CB
188 if ($cctype eq 'decc') { $rtlhas = 'define'; print OUT "useposix='true'\n"; }
189 else { $rtlhas = 'undef'; print OUT "useposix='false'\n"; }
36477c24 190 foreach (qw[ d_stdstdio d_stdio_ptr_lval d_stdio_cnt_lval d_stdiobase
191 d_locconv d_setlocale i_locale d_mbstowcs d_mbtowc
192 d_wcstombs d_wctomb d_mblen d_mktime d_strcoll d_strxfrm ]) {
193 print OUT "$_='$rtlhas'\n";
edc7bc49 194 }
c07a80fd 195 next;
e518068a 196 }
7aa5c81f 197 elsif ($key eq 'exe_ext') {
198 my($nodot) = $val;
199 $nodot =~ s!\.!!;
200 print OUT "so='$nodot'\ndlext='$nodot'\n";
201 }
202 elsif ($key eq 'obj_ext') { print OUT "dlobj='dl_vms$val'\n"; }
203 print OUT "$key='$val'\n";
c07a80fd 204}
205
206# Are there any other logicals which TCP/IP stacks use for the host name?
207$myname = $ENV{'ARPANET_HOST_NAME'} || $ENV{'INTERNET_HOST_NAME'} ||
208 $ENV{'MULTINET_HOST_NAME'} || $ENV{'UCX$INET_HOST'} ||
209 $ENV{'TCPWARE_DOMAINNAME'} || $ENV{'NEWS_ADDRESS'};
210if (!$myname) {
211 ($myname) = `hostname` =~ /^(\S+)/;
212 if ($myname =~ /IVVERB/) {
213 warn "Can't determine TCP/IP hostname" if $dosock;
214 $myname = '';
e518068a 215 }
748a9306 216}
c07a80fd 217$myname = $ENV{'SYS$NODE'} unless $myname;
218($myhostname,$mydomain) = split(/\./,$myname,2);
219print OUT "myhostname='$myhostname'\n" if $myhostname;
220if ($mydomain) {
221 print OUT "mydomain='.$mydomain'\n";
222 print OUT "perladmin='$cf_by\@$myhostname.$mydomain'\n";
223 print OUT "cf_email='$cf_by\@$myhostname.$mydomain'\n";
224}
225else {
226 print OUT "perladmin='$cf_by'\n";
227 print OUT "cf_email='$cf_by'\n";
228}
229chomp($hwname = `Write Sys\$Output F\$GetSyi("HW_NAME")`);
230$hwname = $archsufx if $hwname =~ /IVKEYW/; # *really* old VMS version
231print OUT "myuname='VMS $myname $osvers $hwname'\n";
748a9306 232
7aa5c81f 233# Before we read the C header file, find out what config.sh constants are
234# equivalent to the C preprocessor macros
235if (open(SH,"${outdir}config_h.SH")) {
236 while (<SH>) {
237 next unless m%^#(?!if).*\$%;
238 s/^#//; s!(.*?)\s*/\*.*!$1!;
239 my(@words) = split;
240 $words[1] =~ s/\(.*//; # Clip off args from macro
241 # Did we use a shell variable for the preprocessor directive?
242 if ($words[0] =~ m!^\$(\w+)!) { $pp_vars{$words[1]} = $1; }
243 if (@words > 2) { # We may also have a shell var in the value
244 shift @words; # Discard preprocessor directive
245 my($token) = shift @words; # and keep constant name
246 my($word);
247 foreach $word (@words) {
248 next unless $word =~ m!\$(\w+)!;
249 $val_vars{$token} = $1;
250 last;
251 }
252 }
253 }
254 close SH;
255}
256else { warn "Couldn't read ${outdir}config_h.SH: $!\n"; }
257$pp_vars{UNLINK_ALL_VERSIONS} = 'd_unlink_all_versions'; # VMS_specific
258
259# OK, now read the C header file, and retcon statements into config.sh
a0d0e21e 260while (<IN>) { # roll through the comment header in Config.VMS
e518068a 261 last if /config-start/;
a0d0e21e
LW
262}
263
264while (<IN>) {
265 chop;
266 while (/\\\s*$/) { # pick up contination lines
267 my $line = $_;
268 $line =~ s/\\\s*$//;
269 $_ = <IN>;
270 s/^\s*//;
271 $_ = $line . $_;
272 }
7aa5c81f 273 next unless my ($blocked,$un,$token,$val) =
274 m%^(\/\*)?\s*\#\s*(un)?def\w*\s+([A-Za-z0-9]\w+)\S*\s*(.*)%;
275 if (/config-skip/) {
276 delete $pp_vars{$token} if exists $pp_vars{$token};
277 delete $val_vars{$token} if exists $val_vars{$token};
278 next;
279 }
280 $val =~ s!\s*/\*.*!!; # strip off trailing comment
281 my($had_val); # Maybe a macro with args that we just #undefd or commented
282 if (!length($val) and $val_vars{$token} and ($un || $blocked)) {
aa689395 283 print OUT "$val_vars{$token}=''\n" unless exists $done{$val_vars{$token}};
284 $done{$val_vars{$token}}++;
7aa5c81f 285 delete $val_vars{$token};
286 $had_val = 1;
287 }
a0d0e21e 288 $state = ($blocked || $un) ? 'undef' : 'define';
7aa5c81f 289 if ($pp_vars{$token}) {
aa689395 290 print OUT "$pp_vars{$token}='$state'\n" unless exists $done{$pp_vars{$token}};
291 $done{$pp_vars{$token}}++;
7aa5c81f 292 delete $pp_vars{$token};
293 }
294 elsif (not length $val and not $had_val) {
295 # Wups -- should have been shell var for C preprocessor directive
296 warn "Constant $token not found in config_h.SH\n";
55497cff 297 $token = lc $token;
a0d0e21e 298 $token = "d_$token" unless $token =~ /^i_/;
e518068a 299 print OUT "$token='$state'\n";
748a9306 300 }
7aa5c81f 301 next unless length $val;
302 $val =~ s/^"//; $val =~ s/"$//; # remove end quotes
303 $val =~ s/","/ /g; # make signal list look nice
304 # Library directory; convert to VMS syntax
305 $val = VMS::Filespec::vmspath($val) if ($token =~ /EXP$/);
306 if ($val_vars{$token}) {
aa689395 307 print OUT "$val_vars{$token}='$val'\n" unless exists $done{$val_vars{$token}};
308 if ($val_vars{$token} =~ s/exp$//) {
309 print OUT "$val_vars{$token}='$val'\n" unless exists $done{$val_vars{$token}};;
310 }
311 $done{$val_vars{$token}}++;
7aa5c81f 312 delete $val_vars{$token};
313 }
314 elsif (!$pp_vars{$token}) { # Haven't seen it previously, either
315 warn "Constant $token not found in config_h.SH (val=|$val|)\n";
55497cff 316 $token = lc $token;
7aa5c81f 317 print OUT "$token='$val'\n";
318 if ($token =~ s/exp$//) {print OUT "$token='$val'\n";}
319 }
a0d0e21e
LW
320}
321close IN;
7aa5c81f 322# Special case -- preprocessor manifest "VMS" is defined automatically
323# on VMS systems, but is also used erroneously by the Perl build process
324# as the manifest for the obsolete variable $d_eunice.
325print OUT "d_eunice='undef'\n"; delete $pp_vars{VMS};
a0d0e21e 326
7aa5c81f 327foreach (sort keys %pp_vars) {
328 warn "Didn't see $_ in $infile\n";
329}
330foreach (sort keys %val_vars) {
331 warn "Didn't see $_ in $infile(val)\n";
748a9306 332}
a0d0e21e 333
e518068a 334if (open(OPT,"${outdir}crtl.opt")) {
335 while (<OPT>) {
336 next unless m#/(sha|lib)#i;
337 chomp;
c07a80fd 338 if (/crtl/i || /gcclib/i) { push(@crtls,$_); }
339 else { push(@libs,$_); }
e518068a 340 }
341 close OPT;
342 print OUT "libs='",join(' ',@libs),"'\n";
c07a80fd 343 push(@crtls,'(DECCRTL)') if $cctype eq 'decc';
344 print OUT "libc='",join(' ',@crtls),"'\n";
345}
346else { warn "Can't read ${outdir}crtl.opt - skipping 'libs' & 'libc'"; }
347
348if (open(PL,"${outdir}patchlevel.h")) {
349 while (<PL>) {
8ae5b802 350 if (/^#define PATCHLEVEL\s+(\S+)/) { print OUT "PATCHLEVEL='$1'\n"; }
351 elsif (/^#define SUBVERSION\s+(\S+)/) { print OUT "SUBVERSION='$1'\n"; }
c07a80fd 352 }
353 close PL;
e518068a 354}
c07a80fd 355else { warn "Can't read ${outdir}patchlevel.h - skipping 'PATCHLEVEL'"; }
e518068a 356
7aa5c81f 357# simple pager support for perldoc
bbce6d69 358if (`most not..file` =~ /IVVERB/) {
e518068a 359 $pager = 'more';
360 if (`more nl:` =~ /IVVERB/) { $pager = 'type/page'; }
361}
362else { $pager = 'most'; }
363print OUT "pager='$pager'\n";
364
365close OUT;