Update Plan 9, Win32, VMS configs with $shortsize and $longsize
[p5sagit/p5-mst-13.2.git] / vms / genconfig.pl
CommitLineData
a0d0e21e 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 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#
36477c24 9# Rev. 3-Dec-1996 Charles Bailey bailey@genetics.upenn.edu
a0d0e21e 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 22unshift(@INC,'lib'); # In case someone didn't define Perl_Root
23 # before the build
a0d0e21e 24
a5f75d66 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 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 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 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'
70ccdlflags=''
71cccdlflags=''
72mab=''
73libpth='/sys\$share /sys\$library'
e518068a 74ld='Link'
75lddlflags='/Share'
e518068a 76ranlib=''
77ar=''
78eunicefix=':'
c07a80fd 79hint='none'
e518068a 80hintfile=''
81intsize='4'
82488b82 82longsize='4'
83shortsize='2'
e518068a 84alignbytes='8'
85shrplib='define'
86usemymalloc='n'
7aa5c81f 87usevfork='true'
88useposix='false'
c07a80fd 89spitshell='write sys\$output '
7aa5c81f 90dlsrc='dl_vms.c'
91binexp='$installbin'
92man1ext='rno'
93man3ext='rno'
94arch='VMS_$archsufx'
95archname='VMS_$archsufx'
96osvers='$osvers'
97prefix='$prefix'
98builddir='$builddir'
99installbin='$installbin'
edc7bc49 100installscript='$installscript'
7aa5c81f 101installman1dir='$installman1dir'
102installman3dir='$installman3dir'
103installprivlib='$installprivlib'
104installarchlib='$installarchlib'
edc7bc49 105installsitelib='$installsitelib'
106installsitearch='$installsitearch'
774d564b 107path_sep='|'
108startperl='\$ perl 'f\$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' !
4fdae800 109\$ exit++ + ++\$status != 0 and \$exit = \$status = undef;'
a0d0e21e 110EndOfIntro
111
748a9306 112foreach (@ARGV) {
113 ($key,$val) = split('=',$_,2);
e518068a 114 if ($key eq 'cc') { # Figure out which C compiler we're using
c07a80fd 115 my($cc,$ccflags) = split('/',$val,2);
116 my($d_attr);
117 $ccflags = "/$ccflags";
118 if ($ccflags =~s!/DECC!!ig) {
119 $cc .= '/DECC';
120 $cctype = 'decc';
121 $d_attr = 'undef';
122 }
123 elsif ($ccflags =~s!/VAXC!!ig) {
124 $cc .= '/VAXC';
125 $cctype = 'vaxc';
126 $d_attr = 'undef';
127 }
7aa5c81f 128 elsif (`$val/NoObject/NoList _nla0:/Version` =~ /GNU C version (\S+)/) {
c07a80fd 129 $cctype = 'gcc';
130 $d_attr = 'define';
7aa5c81f 131 print OUT "gccversion='$1'\n";
e518068a 132 }
133 elsif ($archsufx eq 'VAX' &&
71be2cbc 134 # Check exit status too, in case message is turned off
135 ( `$val/NoObject/NoList /prefix=all _nla0:` =~ /IVQUAL/ ||
136 $? == 0x38240 )) {
c07a80fd 137 $cctype = 'vaxc';
138 $d_attr = 'undef';
e518068a 139 }
140 else {
c07a80fd 141 $cctype = 'decc';
142 $d_attr = 'undef';
143 }
144 print OUT "vms_cc_type='$cctype'\n";
145 print OUT "d_attribut='$d_attr'\n";
146 print OUT "cc='$cc'\n";
147 if ( ($cctype eq 'decc' and $archsufx eq 'VAX') || $cctype eq 'gcc') {
148 # gcc and DECC for VAX requires filename in /object qualifier, so we
e518068a 149 # have to remove it here. Alas, this means we lose the user's
150 # object file suffix if it's not .obj.
c07a80fd 151 $ccflags =~ s#/obj(?:ect)?=[^/\s]+##i;
e518068a 152 }
c07a80fd 153 print OUT "ccflags='$ccflags'\n";
154 $dosock = ($ccflags =~ m!/DEF[^/]+VMS_DO_SOCKETS!i and
155 $ccflags !~ m!/UND[^/]+VMS_DO_SOCKETS!i);
7aa5c81f 156 print OUT "d_vms_do_sockets=",$dosock ? "'define'\n" : "'undef'\n";
157 print OUT "d_socket=",$dosock ? "'define'\n" : "'undef'\n";
158 print OUT "d_sockpair=",$dosock ? "'define'\n" : "'undef'\n";
159 print OUT "d_gethent=",$dosock ? "'define'\n" : "'undef'\n";
160 print OUT "d_select=",$dosock ? "'define'\n" : "'undef'\n";
161 print OUT "i_niin=",$dosock ? "'define'\n" : "'undef'\n";
162 print OUT "i_neterrno=",$dosock ? "'define'\n" : "'undef'\n";
edc7bc49 163
36477c24 164 if ($cctype eq 'decc') { $rtlhas = 'define'; }
165 else { $rtlhas = 'undef'; }
166 foreach (qw[ d_stdstdio d_stdio_ptr_lval d_stdio_cnt_lval d_stdiobase
167 d_locconv d_setlocale i_locale d_mbstowcs d_mbtowc
168 d_wcstombs d_wctomb d_mblen d_mktime d_strcoll d_strxfrm ]) {
169 print OUT "$_='$rtlhas'\n";
edc7bc49 170 }
c07a80fd 171 next;
e518068a 172 }
7aa5c81f 173 elsif ($key eq 'exe_ext') {
174 my($nodot) = $val;
175 $nodot =~ s!\.!!;
176 print OUT "so='$nodot'\ndlext='$nodot'\n";
177 }
178 elsif ($key eq 'obj_ext') { print OUT "dlobj='dl_vms$val'\n"; }
179 print OUT "$key='$val'\n";
c07a80fd 180}
181
182# Are there any other logicals which TCP/IP stacks use for the host name?
183$myname = $ENV{'ARPANET_HOST_NAME'} || $ENV{'INTERNET_HOST_NAME'} ||
184 $ENV{'MULTINET_HOST_NAME'} || $ENV{'UCX$INET_HOST'} ||
185 $ENV{'TCPWARE_DOMAINNAME'} || $ENV{'NEWS_ADDRESS'};
186if (!$myname) {
187 ($myname) = `hostname` =~ /^(\S+)/;
188 if ($myname =~ /IVVERB/) {
189 warn "Can't determine TCP/IP hostname" if $dosock;
190 $myname = '';
e518068a 191 }
748a9306 192}
c07a80fd 193$myname = $ENV{'SYS$NODE'} unless $myname;
194($myhostname,$mydomain) = split(/\./,$myname,2);
195print OUT "myhostname='$myhostname'\n" if $myhostname;
196if ($mydomain) {
197 print OUT "mydomain='.$mydomain'\n";
198 print OUT "perladmin='$cf_by\@$myhostname.$mydomain'\n";
199 print OUT "cf_email='$cf_by\@$myhostname.$mydomain'\n";
200}
201else {
202 print OUT "perladmin='$cf_by'\n";
203 print OUT "cf_email='$cf_by'\n";
204}
205chomp($hwname = `Write Sys\$Output F\$GetSyi("HW_NAME")`);
206$hwname = $archsufx if $hwname =~ /IVKEYW/; # *really* old VMS version
207print OUT "myuname='VMS $myname $osvers $hwname'\n";
748a9306 208
7aa5c81f 209# Before we read the C header file, find out what config.sh constants are
210# equivalent to the C preprocessor macros
211if (open(SH,"${outdir}config_h.SH")) {
212 while (<SH>) {
213 next unless m%^#(?!if).*\$%;
214 s/^#//; s!(.*?)\s*/\*.*!$1!;
215 my(@words) = split;
216 $words[1] =~ s/\(.*//; # Clip off args from macro
217 # Did we use a shell variable for the preprocessor directive?
218 if ($words[0] =~ m!^\$(\w+)!) { $pp_vars{$words[1]} = $1; }
219 if (@words > 2) { # We may also have a shell var in the value
220 shift @words; # Discard preprocessor directive
221 my($token) = shift @words; # and keep constant name
222 my($word);
223 foreach $word (@words) {
224 next unless $word =~ m!\$(\w+)!;
225 $val_vars{$token} = $1;
226 last;
227 }
228 }
229 }
230 close SH;
231}
232else { warn "Couldn't read ${outdir}config_h.SH: $!\n"; }
233$pp_vars{UNLINK_ALL_VERSIONS} = 'd_unlink_all_versions'; # VMS_specific
234
235# OK, now read the C header file, and retcon statements into config.sh
a0d0e21e 236while (<IN>) { # roll through the comment header in Config.VMS
e518068a 237 last if /config-start/;
a0d0e21e 238}
239
240while (<IN>) {
241 chop;
242 while (/\\\s*$/) { # pick up contination lines
243 my $line = $_;
244 $line =~ s/\\\s*$//;
245 $_ = <IN>;
246 s/^\s*//;
247 $_ = $line . $_;
248 }
7aa5c81f 249 next unless my ($blocked,$un,$token,$val) =
250 m%^(\/\*)?\s*\#\s*(un)?def\w*\s+([A-Za-z0-9]\w+)\S*\s*(.*)%;
251 if (/config-skip/) {
252 delete $pp_vars{$token} if exists $pp_vars{$token};
253 delete $val_vars{$token} if exists $val_vars{$token};
254 next;
255 }
256 $val =~ s!\s*/\*.*!!; # strip off trailing comment
257 my($had_val); # Maybe a macro with args that we just #undefd or commented
258 if (!length($val) and $val_vars{$token} and ($un || $blocked)) {
259 print OUT "$val_vars{$token}=''\n";
260 delete $val_vars{$token};
261 $had_val = 1;
262 }
a0d0e21e 263 $state = ($blocked || $un) ? 'undef' : 'define';
7aa5c81f 264 if ($pp_vars{$token}) {
265 print OUT "$pp_vars{$token}='$state'\n";
266 delete $pp_vars{$token};
267 }
268 elsif (not length $val and not $had_val) {
269 # Wups -- should have been shell var for C preprocessor directive
270 warn "Constant $token not found in config_h.SH\n";
55497cff 271 $token = lc $token;
a0d0e21e 272 $token = "d_$token" unless $token =~ /^i_/;
e518068a 273 print OUT "$token='$state'\n";
748a9306 274 }
7aa5c81f 275 next unless length $val;
276 $val =~ s/^"//; $val =~ s/"$//; # remove end quotes
277 $val =~ s/","/ /g; # make signal list look nice
278 # Library directory; convert to VMS syntax
279 $val = VMS::Filespec::vmspath($val) if ($token =~ /EXP$/);
280 if ($val_vars{$token}) {
281 print OUT "$val_vars{$token}='$val'\n";
282 if ($val_vars{$token} =~ s/exp$//) {print OUT "$val_vars{$token}='$val'\n";}
283 delete $val_vars{$token};
284 }
285 elsif (!$pp_vars{$token}) { # Haven't seen it previously, either
286 warn "Constant $token not found in config_h.SH (val=|$val|)\n";
55497cff 287 $token = lc $token;
7aa5c81f 288 print OUT "$token='$val'\n";
289 if ($token =~ s/exp$//) {print OUT "$token='$val'\n";}
290 }
a0d0e21e 291}
292close IN;
7aa5c81f 293# Special case -- preprocessor manifest "VMS" is defined automatically
294# on VMS systems, but is also used erroneously by the Perl build process
295# as the manifest for the obsolete variable $d_eunice.
296print OUT "d_eunice='undef'\n"; delete $pp_vars{VMS};
a0d0e21e 297
7aa5c81f 298foreach (sort keys %pp_vars) {
299 warn "Didn't see $_ in $infile\n";
300}
301foreach (sort keys %val_vars) {
302 warn "Didn't see $_ in $infile(val)\n";
748a9306 303}
a0d0e21e 304
e518068a 305if (open(OPT,"${outdir}crtl.opt")) {
306 while (<OPT>) {
307 next unless m#/(sha|lib)#i;
308 chomp;
c07a80fd 309 if (/crtl/i || /gcclib/i) { push(@crtls,$_); }
310 else { push(@libs,$_); }
e518068a 311 }
312 close OPT;
313 print OUT "libs='",join(' ',@libs),"'\n";
c07a80fd 314 push(@crtls,'(DECCRTL)') if $cctype eq 'decc';
315 print OUT "libc='",join(' ',@crtls),"'\n";
316}
317else { warn "Can't read ${outdir}crtl.opt - skipping 'libs' & 'libc'"; }
318
319if (open(PL,"${outdir}patchlevel.h")) {
320 while (<PL>) {
8ae5b802 321 if (/^#define PATCHLEVEL\s+(\S+)/) { print OUT "PATCHLEVEL='$1'\n"; }
322 elsif (/^#define SUBVERSION\s+(\S+)/) { print OUT "SUBVERSION='$1'\n"; }
c07a80fd 323 }
324 close PL;
e518068a 325}
c07a80fd 326else { warn "Can't read ${outdir}patchlevel.h - skipping 'PATCHLEVEL'"; }
e518068a 327
7aa5c81f 328# simple pager support for perldoc
bbce6d69 329if (`most not..file` =~ /IVVERB/) {
e518068a 330 $pager = 'more';
331 if (`more nl:` =~ /IVVERB/) { $pager = 'type/page'; }
332}
333else { $pager = 'most'; }
334print OUT "pager='$pager'\n";
335
336close OUT;