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