Pack Patch (was Re: 5.002 - pack/unpack does not do "I" right)
[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#
7aa5c81f 9# Rev. 23-Apr-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]";
16$installman1dir="$prefix:[man.man1]";
17$installman3dir="$prefix:[man.man3]";
18$installprivlib="$prefix:[lib]";
19
a0d0e21e 20unshift(@INC,'lib'); # In case someone didn't define Perl_Root
21 # before the build
a0d0e21e 22
a5f75d66 23if ($ARGV[0] eq '-f') {
24 open(ARGS,$ARGV[1]) or die "Can't read data from $ARGV[1]: $!\n";
25 @ARGV = ();
26 while (<ARGS>) {
27 push(@ARGV,split(/\|/,$_));
28 }
29 close ARGS;
30}
31
a0d0e21e 32if (-f "config.vms") { $infile = "config.vms"; $outdir = "[-]"; }
33elsif (-f "[.vms]config.vms") { $infile = "[.vms]config.vms"; $outdir = "[]"; }
34elsif (-f "config.h") { $infile = "config.h"; $outdir = "[]";}
35
36if ($infile) { print "Generating Config.sh from $infile . . .\n"; }
37else { die <<EndOfGasp;
38Can't find config.vms or config.h to read!
39 Please run this script from the perl source directory or
40 the VMS subdirectory in the distribution.
41EndOfGasp
42}
43$outdir = '';
44open(IN,"$infile") || die "Can't open $infile: $!\n";
45open(OUT,">${outdir}Config.sh") || die "Can't open ${outdir}Config.sh: $!\n";
a0d0e21e 46
e518068a 47$time = localtime;
7aa5c81f 48$cf_by = (getpwuid($<))[0];
49$archsufx = `Write Sys\$Output F\$GetSyi("HW_MODEL")` > 1024 ? 'AXP' : 'VAX';
50($vers = $]) =~ tr/./_/;
51$installarchlib = VMS::Filespec::vmspath($installprivlib);
52$installarchlib =~ s#\]#.VMS_$archsufx.$vers\]#;
53($osvers = `Write Sys\$Output F\$GetSyi("VERSION")`) =~ s/^V?(\S+)\s*\n?$/$1/;
54
748a9306 55print OUT <<EndOfIntro;
a0d0e21e 56# This file generated by GenConfig.pl on a VMS system.
57# Input obtained from:
58# $infile
59# $0
60# Time: $time
61
e518068a 62package='perl5'
63CONFIG='true'
64cf_time='$time'
7aa5c81f 65cf_by='$cf_by'
66ccdlflags=''
67cccdlflags=''
68mab=''
69libpth='/sys\$share /sys\$library'
e518068a 70ld='Link'
71lddlflags='/Share'
e518068a 72ranlib=''
73ar=''
74eunicefix=':'
c07a80fd 75hint='none'
e518068a 76hintfile=''
77intsize='4'
78alignbytes='8'
79shrplib='define'
80usemymalloc='n'
7aa5c81f 81usevfork='true'
82useposix='false'
c07a80fd 83spitshell='write sys\$output '
7aa5c81f 84dlsrc='dl_vms.c'
85binexp='$installbin'
86man1ext='rno'
87man3ext='rno'
88arch='VMS_$archsufx'
89archname='VMS_$archsufx'
90osvers='$osvers'
91prefix='$prefix'
92builddir='$builddir'
93installbin='$installbin'
94installman1dir='$installman1dir'
95installman3dir='$installman3dir'
96installprivlib='$installprivlib'
97installarchlib='$installarchlib'
a0d0e21e 98EndOfIntro
99
748a9306 100foreach (@ARGV) {
101 ($key,$val) = split('=',$_,2);
e518068a 102 if ($key eq 'cc') { # Figure out which C compiler we're using
c07a80fd 103 my($cc,$ccflags) = split('/',$val,2);
104 my($d_attr);
105 $ccflags = "/$ccflags";
106 if ($ccflags =~s!/DECC!!ig) {
107 $cc .= '/DECC';
108 $cctype = 'decc';
109 $d_attr = 'undef';
110 }
111 elsif ($ccflags =~s!/VAXC!!ig) {
112 $cc .= '/VAXC';
113 $cctype = 'vaxc';
114 $d_attr = 'undef';
115 }
7aa5c81f 116 elsif (`$val/NoObject/NoList _nla0:/Version` =~ /GNU C version (\S+)/) {
c07a80fd 117 $cctype = 'gcc';
118 $d_attr = 'define';
7aa5c81f 119 print OUT "gccversion='$1'\n";
e518068a 120 }
121 elsif ($archsufx eq 'VAX' &&
122 `$val/NoObject/NoList /prefix=all _nla0:` =~ /IVQUAL/) {
c07a80fd 123 $cctype = 'vaxc';
124 $d_attr = 'undef';
e518068a 125 }
126 else {
c07a80fd 127 $cctype = 'decc';
128 $d_attr = 'undef';
129 }
130 print OUT "vms_cc_type='$cctype'\n";
131 print OUT "d_attribut='$d_attr'\n";
132 print OUT "cc='$cc'\n";
133 if ( ($cctype eq 'decc' and $archsufx eq 'VAX') || $cctype eq 'gcc') {
134 # gcc and DECC for VAX requires filename in /object qualifier, so we
e518068a 135 # have to remove it here. Alas, this means we lose the user's
136 # object file suffix if it's not .obj.
c07a80fd 137 $ccflags =~ s#/obj(?:ect)?=[^/\s]+##i;
e518068a 138 }
c07a80fd 139 print OUT "ccflags='$ccflags'\n";
140 $dosock = ($ccflags =~ m!/DEF[^/]+VMS_DO_SOCKETS!i and
141 $ccflags !~ m!/UND[^/]+VMS_DO_SOCKETS!i);
7aa5c81f 142 print OUT "d_vms_do_sockets=",$dosock ? "'define'\n" : "'undef'\n";
143 print OUT "d_socket=",$dosock ? "'define'\n" : "'undef'\n";
144 print OUT "d_sockpair=",$dosock ? "'define'\n" : "'undef'\n";
145 print OUT "d_gethent=",$dosock ? "'define'\n" : "'undef'\n";
146 print OUT "d_select=",$dosock ? "'define'\n" : "'undef'\n";
147 print OUT "i_niin=",$dosock ? "'define'\n" : "'undef'\n";
148 print OUT "i_neterrno=",$dosock ? "'define'\n" : "'undef'\n";
c07a80fd 149 next;
e518068a 150 }
7aa5c81f 151 elsif ($key eq 'exe_ext') {
152 my($nodot) = $val;
153 $nodot =~ s!\.!!;
154 print OUT "so='$nodot'\ndlext='$nodot'\n";
155 }
156 elsif ($key eq 'obj_ext') { print OUT "dlobj='dl_vms$val'\n"; }
157 print OUT "$key='$val'\n";
c07a80fd 158}
159
160# Are there any other logicals which TCP/IP stacks use for the host name?
161$myname = $ENV{'ARPANET_HOST_NAME'} || $ENV{'INTERNET_HOST_NAME'} ||
162 $ENV{'MULTINET_HOST_NAME'} || $ENV{'UCX$INET_HOST'} ||
163 $ENV{'TCPWARE_DOMAINNAME'} || $ENV{'NEWS_ADDRESS'};
164if (!$myname) {
165 ($myname) = `hostname` =~ /^(\S+)/;
166 if ($myname =~ /IVVERB/) {
167 warn "Can't determine TCP/IP hostname" if $dosock;
168 $myname = '';
e518068a 169 }
748a9306 170}
c07a80fd 171$myname = $ENV{'SYS$NODE'} unless $myname;
172($myhostname,$mydomain) = split(/\./,$myname,2);
173print OUT "myhostname='$myhostname'\n" if $myhostname;
174if ($mydomain) {
175 print OUT "mydomain='.$mydomain'\n";
176 print OUT "perladmin='$cf_by\@$myhostname.$mydomain'\n";
177 print OUT "cf_email='$cf_by\@$myhostname.$mydomain'\n";
178}
179else {
180 print OUT "perladmin='$cf_by'\n";
181 print OUT "cf_email='$cf_by'\n";
182}
183chomp($hwname = `Write Sys\$Output F\$GetSyi("HW_NAME")`);
184$hwname = $archsufx if $hwname =~ /IVKEYW/; # *really* old VMS version
185print OUT "myuname='VMS $myname $osvers $hwname'\n";
748a9306 186
7aa5c81f 187# Before we read the C header file, find out what config.sh constants are
188# equivalent to the C preprocessor macros
189if (open(SH,"${outdir}config_h.SH")) {
190 while (<SH>) {
191 next unless m%^#(?!if).*\$%;
192 s/^#//; s!(.*?)\s*/\*.*!$1!;
193 my(@words) = split;
194 $words[1] =~ s/\(.*//; # Clip off args from macro
195 # Did we use a shell variable for the preprocessor directive?
196 if ($words[0] =~ m!^\$(\w+)!) { $pp_vars{$words[1]} = $1; }
197 if (@words > 2) { # We may also have a shell var in the value
198 shift @words; # Discard preprocessor directive
199 my($token) = shift @words; # and keep constant name
200 my($word);
201 foreach $word (@words) {
202 next unless $word =~ m!\$(\w+)!;
203 $val_vars{$token} = $1;
204 last;
205 }
206 }
207 }
208 close SH;
209}
210else { warn "Couldn't read ${outdir}config_h.SH: $!\n"; }
211$pp_vars{UNLINK_ALL_VERSIONS} = 'd_unlink_all_versions'; # VMS_specific
212
213# OK, now read the C header file, and retcon statements into config.sh
a0d0e21e 214while (<IN>) { # roll through the comment header in Config.VMS
e518068a 215 last if /config-start/;
a0d0e21e 216}
217
218while (<IN>) {
219 chop;
220 while (/\\\s*$/) { # pick up contination lines
221 my $line = $_;
222 $line =~ s/\\\s*$//;
223 $_ = <IN>;
224 s/^\s*//;
225 $_ = $line . $_;
226 }
7aa5c81f 227 next unless my ($blocked,$un,$token,$val) =
228 m%^(\/\*)?\s*\#\s*(un)?def\w*\s+([A-Za-z0-9]\w+)\S*\s*(.*)%;
229 if (/config-skip/) {
230 delete $pp_vars{$token} if exists $pp_vars{$token};
231 delete $val_vars{$token} if exists $val_vars{$token};
232 next;
233 }
234 $val =~ s!\s*/\*.*!!; # strip off trailing comment
235 my($had_val); # Maybe a macro with args that we just #undefd or commented
236 if (!length($val) and $val_vars{$token} and ($un || $blocked)) {
237 print OUT "$val_vars{$token}=''\n";
238 delete $val_vars{$token};
239 $had_val = 1;
240 }
a0d0e21e 241 $state = ($blocked || $un) ? 'undef' : 'define';
7aa5c81f 242 if ($pp_vars{$token}) {
243 print OUT "$pp_vars{$token}='$state'\n";
244 delete $pp_vars{$token};
245 }
246 elsif (not length $val and not $had_val) {
247 # Wups -- should have been shell var for C preprocessor directive
248 warn "Constant $token not found in config_h.SH\n";
249 $token =~ tr/A-Z/a-z/;
a0d0e21e 250 $token = "d_$token" unless $token =~ /^i_/;
e518068a 251 print OUT "$token='$state'\n";
748a9306 252 }
7aa5c81f 253 next unless length $val;
254 $val =~ s/^"//; $val =~ s/"$//; # remove end quotes
255 $val =~ s/","/ /g; # make signal list look nice
256 # Library directory; convert to VMS syntax
257 $val = VMS::Filespec::vmspath($val) if ($token =~ /EXP$/);
258 if ($val_vars{$token}) {
259 print OUT "$val_vars{$token}='$val'\n";
260 if ($val_vars{$token} =~ s/exp$//) {print OUT "$val_vars{$token}='$val'\n";}
261 delete $val_vars{$token};
262 }
263 elsif (!$pp_vars{$token}) { # Haven't seen it previously, either
264 warn "Constant $token not found in config_h.SH (val=|$val|)\n";
265 $token =~ tr/A-Z/a-z/;
266 print OUT "$token='$val'\n";
267 if ($token =~ s/exp$//) {print OUT "$token='$val'\n";}
268 }
a0d0e21e 269}
270close IN;
7aa5c81f 271# Special case -- preprocessor manifest "VMS" is defined automatically
272# on VMS systems, but is also used erroneously by the Perl build process
273# as the manifest for the obsolete variable $d_eunice.
274print OUT "d_eunice='undef'\n"; delete $pp_vars{VMS};
a0d0e21e 275
7aa5c81f 276foreach (sort keys %pp_vars) {
277 warn "Didn't see $_ in $infile\n";
278}
279foreach (sort keys %val_vars) {
280 warn "Didn't see $_ in $infile(val)\n";
748a9306 281}
a0d0e21e 282
e518068a 283if (open(OPT,"${outdir}crtl.opt")) {
284 while (<OPT>) {
285 next unless m#/(sha|lib)#i;
286 chomp;
c07a80fd 287 if (/crtl/i || /gcclib/i) { push(@crtls,$_); }
288 else { push(@libs,$_); }
e518068a 289 }
290 close OPT;
291 print OUT "libs='",join(' ',@libs),"'\n";
c07a80fd 292 push(@crtls,'(DECCRTL)') if $cctype eq 'decc';
293 print OUT "libc='",join(' ',@crtls),"'\n";
294}
295else { warn "Can't read ${outdir}crtl.opt - skipping 'libs' & 'libc'"; }
296
297if (open(PL,"${outdir}patchlevel.h")) {
298 while (<PL>) {
8ae5b802 299 if (/^#define PATCHLEVEL\s+(\S+)/) { print OUT "PATCHLEVEL='$1'\n"; }
300 elsif (/^#define SUBVERSION\s+(\S+)/) { print OUT "SUBVERSION='$1'\n"; }
c07a80fd 301 }
302 close PL;
e518068a 303}
c07a80fd 304else { warn "Can't read ${outdir}patchlevel.h - skipping 'PATCHLEVEL'"; }
e518068a 305
7aa5c81f 306# simple pager support for perldoc
8ae5b802 307if (`most` =~ /IVVERB/) {
e518068a 308 $pager = 'more';
309 if (`more nl:` =~ /IVVERB/) { $pager = 'type/page'; }
310}
311else { $pager = 'most'; }
312print OUT "pager='$pager'\n";
313
314close OUT;