Fix utils/perldoc.PL for dos-djgpp:
[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. 10-Nov-1997  Charles Bailey  bailey@newman.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 useshrplib='define'
82 usemymalloc='n'
83 usevfork='true'
84 spitshell='write sys\$output '
85 dlsrc='dl_vms.c'
86 binexp='$installbin'
87 man1ext='rno'
88 man3ext='rno'
89 arch='VMS_$archsufx'
90 archname='VMS_$archsufx'
91 osvers='$osvers'
92 prefix='$prefix'
93 builddir='$builddir'
94 installbin='$installbin'
95 installscript='$installscript'
96 installman1dir='$installman1dir'
97 installman3dir='$installman3dir'
98 installprivlib='$installprivlib'
99 installarchlib='$installarchlib'
100 installsitelib='$installsitelib'
101 installsitearch='$installsitearch'
102 path_sep='|'
103 startperl='\$ perl 'f\$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' !
104 \$ exit++ + ++\$status != 0 and \$exit = \$status = undef;'
105 EndOfIntro
106
107 foreach (@ARGV) {
108   ($key,$val) = split('=',$_,2);
109   if ($key eq 'cc') {  # Figure out which C compiler we're using
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     }
123     elsif (`$val/NoObject/NoList _nla0:/Version` =~ /GNU C version (\S+)/) {
124       $cctype = 'gcc';
125       $d_attr = 'define';
126       print OUT "gccversion='$1'\n";
127     }
128     elsif ($archsufx eq 'VAX' &&
129            # Check exit status too, in case message is turned off
130            ( `$val/NoObject/NoList /prefix=all _nla0:` =~ /IVQUAL/ ||
131               $? == 0x38240 )) {
132       $cctype = 'vaxc';
133       $d_attr = 'undef';
134     }
135     else {
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
144       # have to remove it here.  Alas, this means we lose the user's
145       # object file suffix if it's not .obj.
146       $ccflags =~ s#/obj(?:ect)?=[^/\s]+##i;
147     }
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";
158     print OUT "ccflags='$ccflags'\n";
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";
163     $dosock = ($ccflags =~ m!/DEF[^/]+VMS_DO_SOCKETS!i and
164                $ccflags !~ m!/UND[^/]+VMS_DO_SOCKETS!i);
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";
170     print OUT "i_niin=",$dosock ? "'define'\n" : "'undef'\n";
171     print OUT "i_neterrno=",$dosock ? "'define'\n" : "'undef'\n";
172     if ($dosock and $cctype eq 'decc' and $ccflags =~ /DECCRTL_SOCKETS/) {
173       print OUT "selecttype=fd_set\n";
174     }
175     else { print OUT "selecttype=int\n"; }
176
177     if ($cctype eq 'decc') { $rtlhas  = 'define'; print OUT "useposix='true'\n";  }
178     else                   { $rtlhas  = 'undef';  print OUT "useposix='false'\n"; }
179     foreach (qw[ d_stdstdio d_stdio_ptr_lval d_stdio_cnt_lval d_stdiobase
180                  d_locconv d_setlocale i_locale d_mbstowcs d_mbtowc
181                  d_wcstombs d_wctomb d_mblen d_mktime d_strcoll d_strxfrm ]) {
182       print OUT "$_='$rtlhas'\n";
183     }
184     next;
185   }
186   elsif ($key eq 'exe_ext') { 
187     my($nodot) = $val;
188     $nodot =~ s!\.!!;
189     print OUT "so='$nodot'\ndlext='$nodot'\n";
190   }
191   elsif ($key eq 'obj_ext') { print OUT "dlobj='dl_vms$val'\n";     }
192   print OUT "$key='$val'\n";
193 }
194
195 # Are there any other logicals which TCP/IP stacks use for the host name?
196 $myname = $ENV{'ARPANET_HOST_NAME'}  || $ENV{'INTERNET_HOST_NAME'} ||
197           $ENV{'MULTINET_HOST_NAME'} || $ENV{'UCX$INET_HOST'}      ||
198           $ENV{'TCPWARE_DOMAINNAME'} || $ENV{'NEWS_ADDRESS'};
199 if (!$myname) {
200   ($myname) = `hostname` =~ /^(\S+)/;
201   if ($myname =~ /IVVERB/) {
202     warn "Can't determine TCP/IP hostname" if $dosock;
203     $myname = '';
204   }
205 }
206 $myname = $ENV{'SYS$NODE'} unless $myname;
207 ($myhostname,$mydomain) = split(/\./,$myname,2);
208 print OUT "myhostname='$myhostname'\n" if $myhostname;
209 if ($mydomain) {
210   print OUT "mydomain='.$mydomain'\n";
211   print OUT "perladmin='$cf_by\@$myhostname.$mydomain'\n";
212   print OUT "cf_email='$cf_by\@$myhostname.$mydomain'\n";
213 }
214 else {
215   print OUT "perladmin='$cf_by'\n";
216   print OUT "cf_email='$cf_by'\n";
217 }
218 chomp($hwname = `Write Sys\$Output F\$GetSyi("HW_NAME")`);
219 $hwname = $archsufx if $hwname =~ /IVKEYW/;  # *really* old VMS version
220 print OUT "myuname='VMS $myname $osvers $hwname'\n";
221
222 # Before we read the C header file, find out what config.sh constants are
223 # equivalent to the C preprocessor macros
224 if (open(SH,"${outdir}config_h.SH")) {
225   while (<SH>) {
226     next unless m%^#(?!if).*\$%;
227     s/^#//; s!(.*?)\s*/\*.*!$1!;
228     my(@words) = split;
229     $words[1] =~ s/\(.*//;  # Clip off args from macro
230     # Did we use a shell variable for the preprocessor directive?
231     if ($words[0] =~ m!^\$(\w+)!) { $pp_vars{$words[1]} = $1; }
232     if (@words > 2) {  # We may also have a shell var in the value
233       shift @words;              #  Discard preprocessor directive
234       my($token) = shift @words; #  and keep constant name
235       my($word);
236       foreach $word (@words) {
237         next unless $word =~ m!\$(\w+)!;
238         $val_vars{$token} = $1;
239         last;
240       }
241     }
242   }
243   close SH;
244 }
245 else { warn "Couldn't read ${outdir}config_h.SH: $!\n"; }
246 $pp_vars{UNLINK_ALL_VERSIONS} = 'd_unlink_all_versions';  # VMS_specific
247
248 # OK, now read the C header file, and retcon statements into config.sh
249 while (<IN>) {  # roll through the comment header in Config.VMS
250   last if /config-start/;
251 }
252
253 while (<IN>) {
254   chop;
255   while (/\\\s*$/) {  # pick up contination lines
256     my $line = $_;
257     $line =~ s/\\\s*$//;
258     $_ = <IN>;
259     s/^\s*//;
260     $_ = $line . $_;
261   }              
262   next unless my ($blocked,$un,$token,$val) =
263                  m%^(\/\*)?\s*\#\s*(un)?def\w*\s+([A-Za-z0-9]\w+)\S*\s*(.*)%;
264   if (/config-skip/) {
265     delete $pp_vars{$token} if exists $pp_vars{$token};
266     delete $val_vars{$token} if exists $val_vars{$token};
267     next;
268   }
269   $val =~ s!\s*/\*.*!!; # strip off trailing comment
270   my($had_val); # Maybe a macro with args that we just #undefd or commented
271   if (!length($val) and $val_vars{$token} and ($un || $blocked)) {
272     print OUT "$val_vars{$token}=''\n" unless exists $done{$val_vars{$token}};
273     $done{$val_vars{$token}}++;
274     delete $val_vars{$token};
275     $had_val = 1;
276   }
277   $state = ($blocked || $un) ? 'undef' : 'define';
278   if ($pp_vars{$token}) {
279     print OUT "$pp_vars{$token}='$state'\n" unless exists $done{$pp_vars{$token}};
280     $done{$pp_vars{$token}}++;
281     delete $pp_vars{$token};
282   }
283   elsif (not length $val and not $had_val) {
284     # Wups -- should have been shell var for C preprocessor directive
285     warn "Constant $token not found in config_h.SH\n";
286     $token = lc $token;
287     $token = "d_$token" unless $token =~ /^i_/;
288     print OUT "$token='$state'\n";
289   }
290   next unless length $val;
291   $val =~ s/^"//; $val =~ s/"$//;               # remove end quotes
292   $val =~ s/","/ /g;                            # make signal list look nice
293   # Library directory; convert to VMS syntax
294   $val = VMS::Filespec::vmspath($val) if ($token =~ /EXP$/);
295   if ($val_vars{$token}) {
296     print OUT "$val_vars{$token}='$val'\n" unless exists $done{$val_vars{$token}};
297     if ($val_vars{$token} =~ s/exp$//) {
298       print OUT "$val_vars{$token}='$val'\n" unless exists $done{$val_vars{$token}};;
299     }
300     $done{$val_vars{$token}}++;
301     delete $val_vars{$token};
302   }
303   elsif (!$pp_vars{$token}) {  # Haven't seen it previously, either
304     warn "Constant $token not found in config_h.SH (val=|$val|)\n";
305     $token = lc $token;
306     print OUT "$token='$val'\n";
307     if ($token =~ s/exp$//) {print OUT "$token='$val'\n";}
308   }
309 }
310 close IN;
311 # Special case -- preprocessor manifest "VMS" is defined automatically
312 # on VMS systems, but is also used erroneously by the Perl build process
313 # as the manifest for the obsolete variable $d_eunice.
314 print OUT "d_eunice='undef'\n";  delete $pp_vars{VMS};
315
316 foreach (sort keys %pp_vars) {
317   warn "Didn't see $_ in $infile\n";
318 }
319 foreach (sort keys %val_vars) {
320   warn "Didn't see $_ in $infile(val)\n";
321 }
322
323 if (open(OPT,"${outdir}crtl.opt")) {
324   while (<OPT>) {
325     next unless m#/(sha|lib)#i;
326     chomp;
327     if (/crtl/i || /gcclib/i) { push(@crtls,$_); }
328     else                      { push(@libs,$_);  }
329   }
330   close OPT;
331   print OUT "libs='",join(' ',@libs),"'\n";
332   push(@crtls,'(DECCRTL)') if $cctype eq 'decc';
333   print OUT "libc='",join(' ',@crtls),"'\n";
334 }
335 else { warn "Can't read ${outdir}crtl.opt - skipping 'libs' & 'libc'"; }
336
337 if (open(PL,"${outdir}patchlevel.h")) {
338   while (<PL>) {
339     if    (/^#define PATCHLEVEL\s+(\S+)/) { print OUT "PATCHLEVEL='$1'\n"; }
340     elsif (/^#define SUBVERSION\s+(\S+)/) { print OUT "SUBVERSION='$1'\n"; }
341   }
342   close PL;
343 }
344 else { warn "Can't read ${outdir}patchlevel.h - skipping 'PATCHLEVEL'"; }
345
346 # simple pager support for perldoc                                             
347 if    (`most not..file` =~ /IVVERB/) {
348   $pager = 'more';
349   if (`more nl:` =~ /IVVERB/) { $pager = 'type/page'; }
350 }
351 else { $pager = 'most'; }
352 print OUT "pager='$pager'\n";
353
354 close OUT;