158c55a50845361ad4e7f4c544db7b2f057f35eb
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_VMS.pm
1 #   MM_VMS.pm
2 #   MakeMaker default methods for VMS
3 #   This package is inserted into @ISA of MakeMaker's MM before the
4 #   built-in MM_Unix methods if MakeMaker.pm is run under VMS.
5 #
6 #   Version: 5.16
7 #   Author:  Charles Bailey  bailey@genetics.upenn.edu
8 #   Revised: 03-Jan-1996
9
10 package ExtUtils::MM_VMS;
11
12 use Config;
13 require Exporter;
14 use VMS::Filespec;
15 use File::Basename;
16
17 Exporter::import('ExtUtils::MakeMaker', '$Verbose', '&neatvalue');
18
19
20 sub eliminate_macros {
21     my($self,$path) = @_;
22     unless (ref $self){
23         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
24         $self = $ExtUtils::MakeMaker::Parent[-1];
25     }
26     unless ($path) {
27         print "eliminate_macros('') = ||\n" if $Verbose >= 3;
28         return '';
29     }
30     my($npath) = unixify($path);
31     my($head,$macro,$tail);
32
33     # perform m##g in scalar context so it acts as an iterator
34     while ($npath =~ m#(.*?)\$\((\S+?)\)(.*)#g) { 
35         if ($self->{$2}) {
36             ($head,$macro,$tail) = ($1,$2,$3);
37             ($macro = unixify($self->{$macro})) =~ s#/$##;
38             $npath = "$head$macro$tail";
39         }
40     }
41     print "eliminate_macros($path) = |$npath|\n" if $Verbose >= 3;
42     $npath;
43 }
44
45 # Catchall routine to clean up problem macros.  Expands macros in any directory
46 # specification, and expands expressions which are all macro, so that we can
47 # tell how long the expansion is, and avoid overrunning DCL's command buffer
48 # when MM[KS] is running.
49 sub fixpath {
50     my($self,$path,$force_path) = @_;
51     unless (ref $self){
52         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
53         $self = $ExtUtils::MakeMaker::Parent[-1];
54     }
55     unless ($path) {
56         print "eliminate_macros('') = ||\n" if $Verbose >= 3;
57         return '';
58     }
59     my($fixedpath,$prefix,$name);
60
61     if ($path =~ m#^\$\(.+\)$# || $path =~ m#[/:>\]]#) { 
62         if ($force_path or $path =~ /(?:DIR\)|\])$/) {
63             $fixedpath = vmspath($self->eliminate_macros($path));
64         }
65         else {
66             $fixedpath = vmsify($self->eliminate_macros($path));
67         }
68     }
69     elsif ((($prefix,$name) = ($path =~ m#^\$\(([^\)]+)\)(.+)#)) && $self->{$prefix}) {
70         my($vmspre) = vmspath($self->{$prefix}) || ''; # is it a dir or just a name?
71         $fixedpath = ($vmspre ? $vmspre : $self->{$prefix}) . $name;
72         $fixedpath = vmspath($fixedpath) if $force_path;
73     }
74     else {
75         $fixedpath = $path;
76         $fixedpath = vmspath($fixedpath) if $force_path;
77     }
78     # Convert names without directory or type to paths
79     if (!$force_path and $fixedpath !~ /[:>(.\]]/) { $fixedpath = vmspath($fixedpath); }
80     print "fixpath($path) = |$fixedpath|\n" if $Verbose >= 3;
81     $fixedpath;
82 }
83
84 sub catdir {
85     my($self,@dirs) = @_;
86     unless (ref $self){
87         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
88         $self = $ExtUtils::MakeMaker::Parent[-1];
89     }
90     my($dir) = pop @dirs;
91     my($path) = (@dirs == 1 ? $dirs[0] : $self->catdir(@dirs));
92     my($spath,$sdir) = ($path,$dir);
93     $spath =~ s/.dir$//; $sdir =~ s/.dir$//; 
94     $sdir = $self->eliminate_macros($sdir) unless $sdir =~ /^[\w\-]+$/;
95     my($rslt);
96
97     $rslt = vmspath($self->eliminate_macros($spath)."/$sdir");
98     print "catdir($path,$dir) = |$rslt|\n" if $Verbose >= 3;
99     $rslt;
100 }
101
102 sub catfile {
103     my($self,@files) = @_;
104     unless (ref $self){
105         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
106         $self = $ExtUtils::MakeMaker::Parent[-1];
107     }
108     my($file) = pop @files;
109     my($path) = (@files == 1 ? $files[0] : $self->catdir(@files));
110     my($spath) = $path;
111     $spath =~ s/.dir$//;
112     my($rslt);
113     if ( $spath =~ /^[^\)\]\/:>]+\)$/ && basename($file) eq $file) { $rslt = "$spath$file"; }
114     else { $rslt = vmsify($self->eliminate_macros($spath).'/'.unixify($file)); }
115     print "catfile($path,$file) = |$rslt|\n" if $Verbose >= 3;
116     $rslt;
117 }
118
119
120 # Default name is taken from the directory name if it's not passed in.
121 # Since VMS filenames are case-insensitive, we actually look in the
122 # extension files to find the Mixed-case name
123 sub guess_name {
124     my($self) = @_;
125     unless (ref $self){
126         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
127         $self = $ExtUtils::MakeMaker::Parent[-1];
128     }
129     my($defname,$defpm);
130     local *PM;
131
132     $defname = $ENV{'DEFAULT'};
133     $defname =~ s:.*?([^.\]]+)\]:$1:
134         unless ($defname =~ s:.*[.\[]ext\.(.*)\]:$1:i);
135     $defname =~ s#[.\]]#::#g;
136     ($defpm = $defname) =~ s/.*:://;
137     if (open(PM,"${defpm}.pm")){
138         while (<PM>) {
139             if (/^\s*package\s+([^;]+)/i) {
140                 $defname = $1;
141                 last;
142             }
143         }
144         print STDOUT "Warning (non-fatal): Couldn't find package name in ${defpm}.pm;\n\t",
145                      "defaulting package name to $defname\n"
146             if eof(PM);
147         close PM;
148     }
149     else {
150         print STDOUT "Warning (non-fatal): Couldn't find ${defpm}.pm;\n\t",
151                      "defaulting package name to $defname\n";
152     }
153     $defname =~ s#[\-_][\d.\-]+$##;
154     $defname;
155 }
156
157
158 sub find_perl{
159     my($self, $ver, $names, $dirs, $trace) = @_;
160     unless (ref $self){
161         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
162         $self = $ExtUtils::MakeMaker::Parent[-1];
163     }
164     my($name, $dir,$vmsfile,@cand);
165     if ($trace){
166         print "Looking for perl $ver by these names:\n";
167         print "\t@$names,\n";
168         print "in these dirs:\n";
169         print "\t@$dirs\n";
170     }
171     foreach $dir (@$dirs){
172         next unless defined $dir; # $self->{PERL_SRC} may be undefined
173         foreach $name (@$names){
174             if ($name !~ m![/:>\]]!) { push(@cand,$self->catfile($dir,$name)); }
175             else                     { push(@cand,$self->fixpath($name));      }
176         }
177     }
178     foreach $name (sort { length($a) <=> length($b) } @cand) {
179         print "Checking $name\n" if ($trace >= 2);
180         next unless $vmsfile = $self->maybe_command($name);
181         print "Executing $vmsfile\n" if ($trace >= 2);
182         if (`MCR $vmsfile -e "require $ver; print ""VER_OK\n"""` =~ /VER_OK/) {
183             print "Using PERL=MCR $vmsfile\n" if $trace;
184             return "MCR $vmsfile"
185         }
186     }
187     print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
188     0; # false and not empty
189 }
190
191
192 sub maybe_command {
193     my($self,$file) = @_;
194     return $file if -x $file && ! -d _;
195     return "$file.exe" if -x "$file.exe";
196     if ($file !~ m![/:>\]]!) {
197         my($shrfile) = 'Sys$Share:' . $file;
198         return $file if -x $shrfile && ! -d _;
199         return "$file.exe" if -x "$shrfile.exe";
200     }
201     return 0;
202 }
203
204
205 sub maybe_command_in_dirs {     # $ver is optional argument if looking for perl
206     my($self, $names, $dirs, $trace, $ver) = @_;
207     my($name, $dir);
208     foreach $dir (@$dirs){
209         next unless defined $dir; # $self->{PERL_SRC} may be undefined
210         foreach $name (@$names){
211             my($abs,$tryabs);
212             if ($self->file_name_is_absolute($name)) {
213                 $abs = $name;
214             } else {
215                 $abs = $self->catfile($dir, $name);
216             }
217             print "Checking $abs for $name\n" if ($trace >= 2);
218             next unless $tryabs = $self->maybe_command($abs);
219             print "Substituting $tryabs instead of $abs\n" 
220                 if ($trace >= 2 and $tryabs ne $abs);
221             $abs = $tryabs;
222             if (defined $ver) {
223                 print "Executing $abs\n" if ($trace >= 2);
224                 if (`$abs -e 'require $ver; print "VER_OK\n" ' 2>&1` =~ /VER_OK/) {
225                     print "Using PERL=$abs\n" if $trace;
226                     return $abs;
227                 }
228             } else { # Do not look for perl
229                 return $abs;
230             }
231         }
232     }
233 }
234
235
236 sub perl_script {
237     my($self,$file) = @_;
238     return $file if -r $file && ! -d _;
239     return "$file.pl" if -r "$file.pl" && ! -d _;
240     return '';
241 }
242
243 sub file_name_is_absolute {
244     my($sefl,$file);
245     $file =~ m!^/! or $file =~ m![:<\[][^.]!;
246 }
247
248
249 sub replace_manpage_separator {
250     my($self,$man) = @_;
251     $man = unixify($man);
252     $man =~ s#/+#__#g;
253     $man;
254 }
255
256
257 sub init_others {
258     my($self) = @_;
259     unless (ref $self){
260         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
261         $self = $ExtUtils::MakeMaker::Parent[-1];
262     }
263
264     $self->{NOOP} = "\t@ Continue";
265     $self->{FIRST_MAKEFILE} ||= 'Descrip.MMS';
266     $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE};
267     $self->{RM_F} = '$(PERL) -e "foreach (@ARGV) { 1 while ( -d $_ ? rmdir $_ : unlink $_)}"';
268     $self->{RM_RF} = '$(PERL) -e "use File::Path; @dirs = map(VMS::Filespec::unixify($_),@ARGV); rmtree(\@dirs,0,0)"';
269     $self->{TOUCH} = '$(PERL) -e "$t=time; foreach (@ARGV) { -e $_ ? utime($t,$t,@ARGV) : (open(F,qq(>$_)),close F)}"';
270     $self->{CHMOD} = '$(PERL) -e "chmod @ARGV"';  # expect Unix syntax from MakeMaker
271     $self->{CP} = 'Copy/NoConfirm';
272     $self->{MV} = 'Rename/NoConfirm';
273     $self->{UMASK_NULL} = "\t!";  
274     &MM_Unix::init_others;
275 }
276
277 sub constants {
278     my($self) = @_;
279     unless (ref $self){
280         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
281         $self = $ExtUtils::MakeMaker::Parent[-1];
282     }
283     my(@m,$def);
284     push @m, "
285 NAME = $self->{NAME}
286 DISTNAME = $self->{DISTNAME}
287 NAME_SYM = $self->{NAME_SYM}
288 VERSION = $self->{VERSION}
289 VERSION_SYM = $self->{VERSION_SYM}
290 VERSION_MACRO = VERSION
291 DEFINE_VERSION = ",'"$(VERSION_MACRO)=""$(VERSION)"""',"
292 XS_VERSION = $self->{XS_VERSION}
293 XS_VERSION_MACRO = XS_VERSION
294 XS_DEFINE_VERSION = ",'"$(XS_VERSION_MACRO)=""$(XS_VERSION)"""',"
295
296 # In which library should we install this extension?
297 # This is typically the same as PERL_LIB.
298 # (also see INST_LIBDIR and relationship to ROOTEXT)
299 INST_LIB = ",$self->fixpath($self->{INST_LIB},1),"
300 INST_ARCHLIB = ",$self->fixpath($self->{INST_ARCHLIB},1),"
301 INST_EXE = ",$self->fixpath($self->{INST_EXE},1),"
302
303 PREFIX = $self->{PREFIX}
304
305 # AFS users will want to set the installation directories for
306 # the final 'make install' early without setting INST_LIB,
307 # INST_ARCHLIB, and INST_EXE for the testing phase
308 INSTALLPRIVLIB = ",$self->fixpath($self->{INSTALLPRIVLIB},1),'
309 INSTALLARCHLIB = ',$self->fixpath($self->{INSTALLARCHLIB},1),'
310 INSTALLBIN = ',$self->fixpath($self->{INSTALLBIN},1),'
311
312 # Perl library to use when building the extension
313 PERL_LIB = ',$self->fixpath($self->{PERL_LIB},1),'
314 PERL_ARCHLIB = ',$self->fixpath($self->{PERL_ARCHLIB},1),'
315 LIBPERL_A = ',$self->fixpath($self->{LIBPERL_A}),'
316
317 MAKEMAKER = ',$self->catfile($self->{PERL_LIB},'ExtUtils','MakeMaker.pm'),"
318 MM_VERSION = $ExtUtils::MakeMaker::VERSION
319 FIRST_MAKEFILE  = ",$self->fixpath($self->{FIRST_MAKEFILE}),'
320 MAKE_APERL_FILE = ',$self->fixpath($self->{MAKE_APERL_FILE}),"
321
322 PERLMAINCC = $self->{PERLMAINCC}
323 ";
324
325     if ($self->{PERL_SRC}) {
326          push @m, "
327 # Where is the perl source code located?
328 PERL_SRC = ",$self->fixpath($self->{PERL_SRC},1);
329         push @m, "
330 PERL_VMS = ",$self->catdir($self->{PERL_SRC},q(VMS));
331     }
332     push @m,"
333 # Perl header files (will eventually be under PERL_LIB)
334 PERL_INC = ",$self->fixpath($self->{PERL_INC},1),"
335 # Perl binaries
336 PERL = $self->{PERL}
337 FULLPERL = $self->{FULLPERL}
338
339 # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
340 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
341 # ROOTEXT = Directory part of FULLEXT with leading slash (e.g /DBD)
342 FULLEXT = ",$self->fixpath($self->{FULLEXT},1),"
343 BASEEXT = $self->{BASEEXT}
344 ROOTEXT = ",($self->{ROOTEXT} eq '') ? '[]' : $self->fixpath($self->{ROOTEXT},1),"
345 DLBASE  = $self->{DLBASE}
346 INC = ";
347
348     if ($self->{'INC'}) {
349         push @m,'/Include=(';
350         my(@includes) = split(/\s+/,$self->{INC});
351         my($plural);
352         foreach (@includes) {
353             s/^-I//;
354             push @m,', ' if $plural++;
355             push @m,$self->fixpath($_,1);
356         }
357         push @m, ")\n";
358     }
359
360     if ($self->{DEFINE} ne '') {
361         my(@defs) = split(/\s+/,$self->{DEFINE});
362         foreach $def (@defs) {
363             next unless $def;
364             $def =~ s/^-D//;
365             $def = "\"$def\"" if $def =~ /=/;
366         }
367         $self->{DEFINE} = join ',',@defs;
368     }
369
370     if ($self->{OBJECT} =~ /\s/) {
371         $self->{OBJECT} =~ s/(\\)?\n+\s+/ /g;
372         $self->{OBJECT} = map($self->fixpath($_),split(/,?\s+/,$self->{OBJECT}));
373     }
374     $self->{LDFROM} = join(' ',map($self->fixpath($_),split(/,?\s+/,$self->{LDFROM})));
375
376     push @m,"
377 DEFINE = $self->{DEFINE}
378 OBJECT = $self->{OBJECT}
379 LDFROM = $self->{LDFROM}
380 LINKTYPE = $self->{LINKTYPE}
381
382 # Handy lists of source code files:
383 XS_FILES = ",join(', ', sort keys %{$self->{XS}}),'
384 C_FILES  = ',join(', ', @{$self->{C}}),'
385 O_FILES  = ',join(', ', @{$self->{O_FILES}} ),'
386 H_FILES  = ',join(', ', @{$self->{H}}),'
387 MAN1PODS = ',join(" \\\n\t", sort keys %{$self->{MAN1PODS}}),'
388 MAN3PODS = ',join(" \\\n\t", sort keys %{$self->{MAN3PODS}}),'
389
390 # Man installation stuff:
391 INST_MAN1DIR = ',$self->fixpath($self->{INST_MAN1DIR},1),'
392 INSTALLMAN1DIR = ',$self->fixpath($self->{INSTALLMAN1DIR},1),"
393 MAN1EXT = $self->{MAN1EXT}
394
395 INST_MAN3DIR = ",$self->fixpath($self->{INST_MAN3DIR},1),'
396 INSTALLMAN3DIR = ',$self->fixpath($self->{INSTALLMAN3DIR},1),"
397 MAN3EXT = $self->{MAN3EXT}
398
399
400 .SUFFIXES : .xs .c \$(OBJ_EXT)
401
402 # This extension may link to it's own library (see SDBM_File)";
403     push @m,"
404 MYEXTLIB = ",$self->fixpath($self->{MYEXTLIB}),"
405
406 # Here is the Config.pm that we are using/depend on
407 CONFIGDEP = \$(PERL_ARCHLIB)Config.pm, \$(PERL_INC)config.h
408
409 # Where to put things:
410 INST_LIBDIR = ",($self->{'INST_LIBDIR'} = $self->catdir($self->{INST_LIB},$self->{ROOTEXT})),"
411 INST_ARCHLIBDIR = ",($self->{'INST_ARCHLIBDIR'} = $self->catdir($self->{INST_ARCHLIB},$self->{ROOTEXT})),"
412
413 INST_AUTODIR = ",($self->{'INST_AUTODIR'} = $self->catdir($self->{INST_LIB},'auto',$self->{FULLEXT})),'
414 INST_ARCHAUTODIR = ',($self->{'INST_ARCHAUTODIR'} = $self->catdir($self->{INST_ARCHLIB},'auto',$self->{FULLEXT})),'
415 ';
416
417     if ($self->has_link_code()) {
418         push @m,'
419 INST_STATIC = $(INST_ARCHAUTODIR)$(BASEEXT)$(LIB_EXT)
420 INST_DYNAMIC = $(INST_ARCHAUTODIR)$(BASEEXT).$(DLEXT)
421 INST_BOOT = $(INST_ARCHAUTODIR)$(BASEEXT).bs
422 ';
423     } else {
424         push @m,'
425 INST_STATIC =
426 INST_DYNAMIC =
427 INST_BOOT =
428 ';
429     }
430
431     push @m,'
432 INST_PM = ',join(', ',map($self->fixpath($_),sort values %{$self->{PM}})),'
433 ';
434
435     join('',@m);
436 }
437
438
439 sub const_loadlibs{
440     my($self) = @_;
441     unless (ref $self){
442         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
443         $self = $ExtUtils::MakeMaker::Parent[-1];
444     }
445     my (@m);
446     push @m, "
447 # $self->{NAME} might depend on some other libraries.
448 # (These comments may need revising:)
449 #
450 # Dependent libraries can be linked in one of three ways:
451 #
452 #  1.  (For static extensions) by the ld command when the perl binary
453 #      is linked with the extension library. See EXTRALIBS below.
454 #
455 #  2.  (For dynamic extensions) by the ld command when the shared
456 #      object is built/linked. See LDLOADLIBS below.
457 #
458 #  3.  (For dynamic extensions) by the DynaLoader when the shared
459 #      object is loaded. See BSLOADLIBS below.
460 #
461 # EXTRALIBS =   List of libraries that need to be linked with when
462 #               linking a perl binary which includes this extension
463 #               Only those libraries that actually exist are included.
464 #               These are written to a file and used when linking perl.
465 #
466 # LDLOADLIBS =  List of those libraries which can or must be linked into
467 #               the shared library when created using ld. These may be
468 #               static or dynamic libraries.
469 #               LD_RUN_PATH is a colon separated list of the directories
470 #               in LDLOADLIBS. It is passed as an environment variable to
471 #               the process that links the shared library.
472 #
473 # BSLOADLIBS =  List of those libraries that are needed but can be
474 #               linked in dynamically at run time on this platform.
475 #               SunOS/Solaris does not need this because ld records
476 #               the information (from LDLOADLIBS) into the object file.
477 #               This list is used to create a .bs (bootstrap) file.
478 #
479 EXTRALIBS  = ",map($self->fixpath($_) . ' ',$self->{'EXTRALIBS'}),"
480 BSLOADLIBS = ",map($self->fixpath($_) . ' ',$self->{'BSLOADLIBS'}),"
481 LDLOADLIBS = ",map($self->fixpath($_) . ' ',$self->{'LDLOADLIBS'}),"\n";
482
483     join('',@m);
484 }
485
486
487 sub const_cccmd {
488     my($self,$libperl) = @_;
489     unless (ref $self){
490         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
491         $self = $ExtUtils::MakeMaker::Parent[-1];
492     }
493     my($cmd,$quals) = ($Config{'cc'},$Config{'ccflags'});
494     my($name,$sys,@m);
495
496     ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
497     print STDOUT "Unix shell script ".$Config{"$self->{'BASEEXT'}_cflags"}.
498          " required to modify CC command for $self->{'BASEEXT'}\n"
499     if ($Config{$name});
500
501     # Deal with $self->{DEFINE} here since some C compilers pay attention
502     # to only one /Define clause on command line, so we have to
503     # conflate the ones from $Config{'cc'} and $self->{DEFINE}
504     if ($quals =~ m:(.*)/define=\(?([^\(\/\)\s]+)\)?(.*)?:i) {
505         $quals = "$1/Define=($2," . ($self->{DEFINE} ? "$self->{DEFINE}," : '') .
506                  "\$(DEFINE_VERSION),\$(XS_DEFINE_VERSION))$3";
507     }
508     else {
509         $quals .= '/Define=(' . ($self->{DEFINE} ? "$self->{DEFINE}," : '') .
510                   '$(DEFINE_VERSION),$(XS_DEFINE_VERSION))';
511     }
512
513     $libperl or $libperl = $self->{LIBPERL_A} || "libperl.olb";
514     if ($libperl =~ /libperl(\w+)\./i) {
515         my($type) = uc $1;
516         my(%map) = ( 'D'  => 'DEBUGGING', 'E' => 'EMBED', 'M' => 'MULTIPLICITY',
517                      'DE' => 'DEBUGGING,EMBED', 'DM' => 'DEBUGGING,MULTIPLICITY',
518                      'EM' => 'EMBED,MULTIPLICITY', 'DEM' => 'DEBUGGING,EMBED,MULTIPLICITY' );
519         $quals =~ s:/define=\(([^\)]+)\):/Define=($1,$map{$type}):i
520     }
521
522     # Likewise with $self->{INC} and /Include
523     my($incstr) = '/Include=($(PERL_INC)';
524     if ($self->{'INC'}) {
525         my(@includes) = split(/\s+/,$self->{INC});
526         foreach (@includes) {
527             s/^-I//;
528             $incstr .= ', '.$self->fixpath($_,1);
529         }
530     }
531     if ($quals =~ m:(.*)/include=\(?([^\(\/\)\s]+)\)?(.*):i) {
532         $quals = "$1$incstr,$2)$3";
533     }
534     else { $quals .= "$incstr)"; }
535
536
537    if ($Config{'vms_cc_type'} ne 'decc') {
538         push @m,'
539 .FIRST
540         @ If F$TrnLnm("Sys").eqs."" Then Define/NoLog SYS ',
541         ($Config{'vms_cc_type'} eq 'gcc' ? 'GNU_CC_Include:[VMS]'
542                                          : 'Sys$Library'),'
543
544 ';
545    }
546    push(@m, "CCCMD = $cmd$quals\n");
547
548    $self->{CONST_CCCMD} = join('',@m);
549 }
550
551
552 # --- Tool Sections ---
553
554 sub tool_autosplit{
555     my($self, %attribs) = @_;
556     unless (ref $self){
557         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
558         $self = $ExtUtils::MakeMaker::Parent[-1];
559     }
560     my($asl) = "";
561     $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
562     q{
563 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
564 AUTOSPLITFILE = $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use AutoSplit;}.$asl.q{ AutoSplit::autosplit($ARGV[0], $ARGV[1], 0, 1, 1) ;"
565 };
566 }
567
568 sub tool_xsubpp{
569     my($self) = @_;
570     unless (ref $self){
571         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
572         $self = $ExtUtils::MakeMaker::Parent[-1];
573     }
574     my($xsdir) = $self->catdir($self->{PERL_LIB},'ExtUtils');
575     # drop back to old location if xsubpp is not in new location yet
576     $xsdir = $self->catdir($self->{PERL_SRC},'ext') unless (-f $self->catfile($xsdir,'xsubpp'));
577     my(@tmdeps) = '$(XSUBPPDIR)typemap';
578     if( $self->{TYPEMAPS} ){
579         my $typemap;
580         foreach $typemap (@{$self->{TYPEMAPS}}){
581                 if( ! -f  $typemap ){
582                         warn "Typemap $typemap not found.\n";
583                 }
584                 else{
585                         push(@tmdeps, $self->fixpath($typemap));
586                 }
587         }
588     }
589     push(@tmdeps, "typemap") if -f "typemap";
590     my(@tmargs) = map("-typemap $_", @tmdeps);
591     if( exists $self->{XSOPT} ){
592         unshift( @tmargs, $self->{XSOPT} );
593     }
594
595     my $xsubpp_version = $self->xsubpp_version($self->catfile($xsdir,'xsubpp'));
596
597     # What are the correct thresholds for version 1 && 2 Paul?
598     if ( $xsubpp_version > 1.923 ){
599         $self->{XSPROTOARG} = '' unless defined $self->{XSPROTOARG};
600     } else {
601         if (defined $self->{XSPROTOARG} && $self->{XSPROTOARG} =~ /\-prototypes/) {
602             print STDOUT qq{Warning: This extension wants to pass the switch "-prototypes" to xsubpp.
603         Your version of xsubpp is $xsubpp_version and cannot handle this.
604         Please upgrade to a more recent version of xsubpp.
605 };
606         } else {
607             $self->{XSPROTOARG} = "";
608         }
609     }
610
611     "
612 XSUBPPDIR = ".$self->fixpath($xsdir,1)."
613 XSUBPP = \$(PERL) \"-I\$(PERL_ARCHLIB)\" \"-I\$(PERL_LIB)\" \$(XSUBPPDIR)xsubpp
614 XSPROTOARG = $self->{XSPROTOARG}
615 XSUBPPDEPS = @tmdeps
616 XSUBPPARGS = @tmargs
617 ";
618 }
619
620
621 sub xsubpp_version
622 {
623     my($self,$xsubpp) = @_;
624     my ($version) ;
625
626     # try to figure out the version number of the xsubpp on the system
627
628     # first try the -v flag, introduced in 1.921 & 2.000a2
629
630     my $command = "$self->{PERL} $xsubpp -v";
631     print "Running: $command\n" if $Verbose;
632     $version = `$command` ;
633     warn "Running '$command' exits with status " . $? unless ($? & 1);
634     chop $version ;
635
636     return $1 if $version =~ /^xsubpp version (.*)/ ;
637
638     # nope, then try something else
639
640     my $counter = '000';
641     my ($file) = 'temp' ;
642     $counter++ while -e "$file$counter"; # don't overwrite anything
643     $file .= $counter;
644
645     local(*F);
646     open(F, ">$file") or die "Cannot open file '$file': $!\n" ;
647     print F <<EOM ;
648 MODULE = fred PACKAGE = fred
649
650 int
651 fred(a)
652         int     a;
653 EOM
654
655     close F ;
656
657     $command = "$self->{PERL} $xsubpp $file";
658     print "Running: $command\n" if $Verbose;
659     my $text = `$command` ;
660     warn "Running '$command' exits with status " . $? unless ($? & 1);
661     unlink $file ;
662
663     # gets 1.2 -> 1.92 and 2.000a1
664     return $1 if $text =~ /automatically by xsubpp version ([\S]+)\s*/  ;
665
666     # it is either 1.0 or 1.1
667     return 1.1 if $text =~ /^Warning: ignored semicolon/ ;
668
669     # none of the above, so 1.0
670     return "1.0" ;
671 }
672
673
674 sub tools_other {
675     my($self) = @_;
676     unless (ref $self){
677         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
678         $self = $ExtUtils::MakeMaker::Parent[-1];
679     }
680     "
681 # Assumes \$(MMS) invokes MMS or MMK
682 # (It is assumed in some cases later that the default makefile name
683 # (Descrip.MMS for MM[SK]) is used.)
684 USEMAKEFILE = /Descrip=
685 USEMACROS = /Macro=(
686 MACROEND = )
687 MAKEFILE = Descrip.MMS
688 SHELL = Posix
689 TOUCH = $self->{TOUCH}
690 CHMOD = $self->{CHMOD}
691 CP = $self->{CP}
692 MV = $self->{MV}
693 RM_F  = $self->{RM_F}
694 RM_RF = $self->{RM_RF}
695 UMASK_NULL = $self->{UMASK_NULL}
696 MKPATH = Create/Directory
697 ";
698 }
699
700
701 sub dist {
702     my($self, %attribs) = @_;
703     unless (ref $self){
704         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
705         $self = $ExtUtils::MakeMaker::Parent[-1];
706     }
707     # VERSION should be sanitised before use as a file name
708     my($name)         = $attribs{NAME}          || '$(DISTVNAME)';
709     my($zip)          = $attribs{ZIP}           || 'zip';
710     my($zipflags)     = $attribs{ZIPFLAGS}      || '-Vu';
711     my($suffix)       = $attribs{SUFFIX}        || '';
712     my($shar)         = $attribs{SHAR}          || 'vms_share';
713     my($preop)        = $attribs{PREOP}         || '!'; # e.g., update MANIFEST
714     my($postop)       = $attribs{POSTOP}        || '!';
715     my($dist_cp)  = $attribs{DIST_CP}  || 'best';
716     my($dist_default) = $attribs{DIST_DEFAULT}  || 'zipdist';
717
718     my($src) = $name;
719     $src = "[.$src]" unless $src =~ /\[/;
720     $src =~ s#\]#...]#;
721     $src .= '*.*' if $src =~ /\]$/;
722     $suffix =~ s#\.#_#g;
723 "
724 DISTVNAME = \$(DISTNAME)-\$(VERSION_SYM)
725 SRC = $src
726 ZIP = $zip
727 ZIPFLAGS = $zipflags
728 SUFFIX = $suffix
729 SHARE = $shar
730 PREOP = $preop
731 POSTOP = $postop
732 DIST_CP = $dist_cp
733 DIST_DEFAULT = $dist_default
734 ";
735 }
736
737
738 # --- Translation Sections ---
739
740 sub c_o {
741     my($self) = @_;
742     unless (ref $self){
743         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
744         $self = $ExtUtils::MakeMaker::Parent[-1];
745     }
746     return '' unless $self->needs_linking();
747     '
748 .c$(OBJ_EXT) :
749         $(CCCMD) $(CCCDLFLAGS) $(MMS$TARGET_NAME).c
750 ';
751 }
752
753 sub xs_c {
754     my($self) = @_;
755     unless (ref $self){
756         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
757         $self = $ExtUtils::MakeMaker::Parent[-1];
758     }
759     return '' unless $self->needs_linking();
760     '
761 .xs.c :
762         $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $(MMS$TARGET_NAME).xs >$(MMS$TARGET)
763 ';
764 }
765
766 sub xs_o {      # many makes are too dumb to use xs_c then c_o
767     my($self) = @_;
768     unless (ref $self){
769         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
770         $self = $ExtUtils::MakeMaker::Parent[-1];
771     }
772     return '' unless $self->needs_linking();
773     '
774 .xs$(OBJ_EXT) :
775         $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $(MMS$TARGET_NAME).xs >$(MMS$TARGET_NAME).c
776         $(CCCMD) $(CCCDLFLAGS) $(MMS$TARGET_NAME).c
777 ';
778 }
779
780
781 # --- Target Sections ---
782
783
784 sub top_targets {
785     my($self) = shift;
786     unless (ref $self){
787         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
788         $self = $ExtUtils::MakeMaker::Parent[-1];
789     }
790     my(@m);
791     push @m, '
792 all ::  config $(INST_PM) subdirs linkext manifypods
793         $(NOOP)
794
795 subdirs :: $(MYEXTLIB)
796         $(NOOP)
797
798 config :: $(MAKEFILE) $(INST_LIBDIR).exists
799         $(NOOP)
800
801 config :: $(INST_ARCHAUTODIR).exists Version_check
802         $(NOOP)
803
804 config :: $(INST_AUTODIR).exists
805         $(NOOP)
806 ';
807
808
809     push @m, $self->dir_target(qw[$(INST_AUTODIR) $(INST_LIBDIR) $(INST_ARCHAUTODIR)]);
810     if (%{$self->{MAN1PODS}}) {
811         push @m, q[
812 config :: $(INST_MAN1DIR)/.exists
813         $(NOOP)
814 ];
815         push @m, $self->dir_target(qw[$(INST_MAN1DIR)]);
816     }
817     if (%{$self->{MAN3PODS}}) {
818         push @m, q[
819 config :: $(INST_MAN3DIR).exists
820         $(NOOP)
821 ];
822         push @m, $self->dir_target(qw[$(INST_MAN3DIR)]);
823     }
824
825     push @m, '
826 $(O_FILES) : $(H_FILES)
827 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
828
829     push @m, q{
830 help :
831         perldoc ExtUtils::MakeMaker
832 };
833
834     push @m, q{
835 Version_check :
836         @ $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -
837                 -e "use ExtUtils::MakeMaker qw($Version &Version_check);" -
838                 -e "&Version_check('$(MM_VERSION)')"
839 };
840
841     join('',@m);
842 }
843
844
845 sub dlsyms {
846     my($self,%attribs) = @_;
847     unless (ref $self){
848         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
849         $self = $ExtUtils::MakeMaker::Parent[-1];
850     }
851
852     return '' unless $self->needs_linking();
853
854     my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
855     my($vars)  = $attribs{DL_VARS} || $self->{DL_VARS} || [];
856     my(@m);
857
858     push(@m,'
859 dynamic :: rtls.opt $(INST_ARCHAUTODIR)$(BASEEXT).opt
860         $(NOOP)
861
862 # rtls.opt is built in the same step as $(BASEEXT).opt
863 rtls.opt : $(BASEEXT).opt
864         $(TOUCH) $(MMS$TARGET)
865 ') unless $self->{SKIPHASH}{'dynamic'};
866
867     push(@m,'
868 static :: $(INST_ARCHAUTODIR)$(BASEEXT).opt
869         $(NOOP)
870 ') unless $self->{SKIPHASH}{'static'};
871
872     push(@m,'
873 $(INST_ARCHAUTODIR)$(BASEEXT).opt : $(BASEEXT).opt
874         $(CP) $(MMS$SOURCE) $(MMS$TARGET)
875         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
876
877 $(BASEEXT).opt : makefile.PL
878         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::MakeMaker qw(&mksymlists);" -
879                 -e "MM->new({NAME => \'',$self->{NAME},'\'})->mksymlists({DL_FUNCS => ',neatvalue($self->{DL_FUNCS}),', DL_VARS => ',neatvalue($self->{DL_VARS}),'})"
880         $(PERL) -e "open OPT,\'>>$(MMS$TARGET)\'; print OPT ""$(INST_STATIC)/Include=$(BASEEXT)\n$(INST_STATIC)/Library\n"";close OPT"
881 ');
882
883     join('',@m);
884 }
885
886
887 # --- Dynamic Loading Sections ---
888
889 sub dynamic_lib {
890     my($self, %attribs) = @_;
891     unless (ref $self){
892         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
893         $self = $ExtUtils::MakeMaker::Parent[-1];
894     }
895     return '' unless $self->needs_linking(); #might be because of a subdir
896
897     return '' unless $self->has_link_code();
898
899     ($otherldflags) = $attribs{OTHERLDFLAGS} || "";
900     my(@m);
901     push @m,"
902
903 OTHERLDFLAGS = $otherldflags
904
905 ";
906     push @m, '
907 $(INST_DYNAMIC) : $(INST_STATIC) $(PERL_INC)perlshr_attr.opt rtls.opt $(BASEEXT).opt $(INST_ARCHAUTODIR).exists
908         @ $(MKPATH) $(INST_ARCHAUTODIR)
909         Link $(LDFLAGS) /Shareable=$(MMS$TARGET)$(OTHERLDFLAGS) $(BASEEXT).opt/Option,rtls.opt/Option,$(PERL_INC)perlshr_attr.opt/Option
910         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
911 ';
912
913     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
914     join('',@m);
915 }
916
917 sub dynamic_bs {
918     my($self, %attribs) = @_;
919     unless (ref $self){
920         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
921         $self = $ExtUtils::MakeMaker::Parent[-1];
922     }
923     return '
924 BOOTSTRAP =
925 ' unless $self->has_link_code();
926     '
927 BOOTSTRAP = '."$self->{BASEEXT}.bs".'
928
929 # As MakeMaker mkbootstrap might not write a file (if none is required)
930 # we use touch to prevent make continually trying to remake it.
931 # The DynaLoader only reads a non-empty file.
932 $(BOOTSTRAP) : $(MAKEFILE) '."$self->{BOOTDEP}".' $(INST_ARCHAUTODIR).exists
933         @ Write Sys$Output "Running mkbootstrap for $(NAME) ($(BSLOADLIBS))"
934         @ $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -
935         -e "use ExtUtils::Mkbootstrap; Mkbootstrap(\'$(BASEEXT)\',\'$(BSLOADLIBS)\');"
936         @ $(TOUCH) $(MMS$TARGET)
937         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
938
939 $(INST_BOOT) : $(BOOTSTRAP) $(INST_ARCHAUTODIR).exists
940         @ $(RM_RF) $(INST_BOOT)
941         - $(CP) $(BOOTSTRAP) $(INST_BOOT)
942         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
943 ';
944 }
945 # --- Static Loading Sections ---
946
947 sub static_lib {
948     my($self) = @_;
949     unless (ref $self){
950         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
951         $self = $ExtUtils::MakeMaker::Parent[-1];
952     }
953     return '' unless $self->needs_linking();
954
955     return '
956 $(INST_STATIC) :
957         $(NOOP)
958 ' unless ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB});
959
960     my(@m);
961     push @m,'
962 # Rely on suffix rule for update action
963 $(OBJECT) : $(INST_ARCHAUTODIR).exists
964
965 $(INST_STATIC) : $(OBJECT) $(MYEXTLIB)
966 ';
967     # If this extension has it's own library (eg SDBM_File)
968     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
969     push(@m, '  $(CP) $(MYEXTLIB) $(MMS$TARGET)',"\n") if $self->{MYEXTLIB};
970
971     push(@m,'
972         If F$Search("$(MMS$TARGET)").eqs."" Then Library/Object/Create $(MMS$TARGET)
973         Library/Object/Replace $(MMS$TARGET) $(MMS$SOURCE_LIST)
974         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR)extralibs.ld\';print F qq[$(EXTRALIBS)\n];close F;"
975         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
976 ');
977     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
978     join('',@m);
979 }
980
981
982 sub installpm_x { # called by installpm perl file
983     my($self, $dist, $inst, $splitlib) = @_;
984     unless (ref $self){
985         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
986         $self = $ExtUtils::MakeMaker::Parent[-1];
987     }
988     warn "Warning: Most probably 'make' will have problems processing this file: $inst\n"
989         if $inst =~ m!#!;
990     $inst = $self->fixpath($inst);
991     $dist = $self->fixpath($dist);
992     my($instdir) = $inst =~ /([^\)]+\))[^\)]*$/ ? $1 : dirname($inst);
993     my(@m);
994
995     push(@m, "
996 $inst : $dist \$(MAKEFILE) ${instdir}.exists \$(INST_ARCHAUTODIR).exists
997 ",'     @ $(RM_F) $(MMS$TARGET)
998         @ $(CP) ',"$dist $inst",'
999         $(CHMOD) 644 $(MMS$TARGET)
1000         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
1001 ');
1002     push(@m, '  $(AUTOSPLITFILE) $(MMS$TARGET) ',
1003               $self->catdir($splitlib,'auto')."\n\n")
1004         if ($splitlib and $inst =~ /\.pm$/);
1005     push(@m,$self->dir_target($instdir));
1006
1007     join('',@m);
1008 }
1009
1010
1011 sub manifypods {
1012     my($self, %attribs) = @_;
1013     unless (ref $self){
1014         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1015         $self = $ExtUtils::MakeMaker::Parent[-1];
1016     }
1017     return "\nmanifypods :\n\t\$(NOOP)\n" unless %{$self->{MAN3PODS}};
1018     my($dist);
1019     my($pod2man_exe,$found_pod2man);
1020     if (defined $self->{PERL_SRC}) {
1021         $pod2man_exe = $self->catfile($self->{PERL_SRC},'pod','pod2man');
1022     } else {
1023         $pod2man_exe = $self->catfile($Config{bin},'pod2man');
1024     }
1025     if ($pod2man_exe = $self->perl_script($pod2man_exe)) { $found_pod2man = 1; }
1026     else {
1027         # No pod2man but some MAN3PODS to be installed
1028         print <<END;
1029
1030 Warning: I could not locate your pod2man program.  As a last choice,
1031          I will look for the file to which the logical name POD2MAN
1032          points when MMK is invoked.
1033
1034 END
1035         $pod2man_exe = "pod2man";
1036     }
1037     my(@m);
1038     push @m,
1039 qq[POD2MAN_EXE = $pod2man_exe\n],
1040 q[POD2MAN = $(PERL) -we "%m=@ARGV;for (keys %m){" -
1041 -e "system(""$^X $(POD2MAN_EXE) $_ >$m{$_}"");}"
1042 ];
1043     push @m, "\nmanifypods : ";
1044     push @m, join " ", keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}};
1045     push(@m,"\n");
1046     if (%{$self->{MAN1PODS}} || %{$self->{MAN3PODS}}) {
1047         my($pod);
1048         foreach $pod (sort keys %{$self->{MAN1PODS}}) {
1049             push @m, qq[\t\@- If F\$Search("\$(POD2MAN_EXE)").nes."" Then \$(POD2MAN) ];
1050             push @m, "$pod $self->{MAN1PODS}{$pod}\n";
1051         }
1052         foreach $pod (sort keys %{$self->{MAN3PODS}}) {
1053             push @m, qq[\t\@- If F\$Search("\$(POD2MAN_EXE)").nes."" Then \$(POD2MAN) ];
1054             push @m, "$pod $self->{MAN3PODS}{$pod}\n";
1055         }
1056     }
1057     join('', @m);
1058 }
1059
1060
1061 sub processPL {
1062     my($self) = @_;
1063     unless (ref $self){
1064         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1065         $self = $ExtUtils::MakeMaker::Parent[-1];
1066     }
1067     return "" unless $self->{PL_FILES};
1068     my(@m, $plfile);
1069     foreach $plfile (sort keys %{$self->{PL_FILES}}) {
1070         push @m, "
1071 all :: $self->{PL_FILES}->{$plfile}
1072         \$(NOOP)
1073
1074 $self->{PL_FILES}->{$plfile} :: $plfile
1075 ",'     $(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" '," $plfile
1076 ";
1077     }
1078     join "", @m;
1079 }
1080
1081
1082 sub installbin {
1083     my($self) = @_;
1084     unless (ref $self){
1085         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1086         $self = $ExtUtils::MakeMaker::Parent[-1];
1087     }
1088     return '' unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
1089     return '' unless @{$self->{EXE_FILES}};
1090     my(@m, $from, $to, %fromto, @to, $line);
1091     for $from (@{$self->{EXE_FILES}}) {
1092         my($path) = '$(INST_EXE)' . basename($from);
1093         local($_) = $path;  # backward compatibility
1094         $to = $self->exescan($path);
1095         print "exescan($from) => '$to'\n" if ($Verbose >=2);
1096         $fromto{$from}=$to;
1097     }
1098     @to   = values %fromto;
1099     push @m, "
1100 EXE_FILES = @{$self->{EXE_FILES}}
1101
1102 all :: @to
1103         \$(NOOP)
1104
1105 realclean ::
1106 ";
1107     $line = '';  #avoid unitialized var warning
1108     foreach $to (@to) {
1109         if (length($line) + length($to) > 80) {
1110             push @m, "\t\$(RM_F) $line\n";
1111             $line = $to;
1112         }
1113         else { $line .= " $to"; }
1114     }
1115     push @m, "\t\$(RM_F) $line\n\n";
1116
1117     while (($from,$to) = each %fromto) {
1118         my $todir;
1119         if ($to =~ m#[/>:\]]#) { $todir = dirname($to); }
1120         else                   { ($todir = $to) =~ s/[^\)]+$//; }
1121         $todir = $self->fixpath($todir,1);
1122         push @m, "
1123 $to : $from \$(MAKEFILE) ${todir}.exists
1124         \$(CP) $from $to
1125
1126 ", $self->dir_target($todir);
1127     }
1128     join "", @m;
1129 }
1130
1131
1132 # --- Sub-directory Sections ---
1133
1134 sub pasthru {
1135     my($self) = @_;
1136     unless (ref $self){
1137         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1138         $self = $ExtUtils::MakeMaker::Parent[-1];
1139     }
1140     my(@m,$key);
1141     my(@pasthru);
1142
1143     foreach $key (qw(INSTALLPRIVLIB INSTALLARCHLIB INSTALLBIN 
1144                      INSTALLMAN1DIR INSTALLMAN3DIR LIBPERL_A LINKTYPE)){
1145         push @pasthru, "$key=\"$self->{$key}\"";
1146     }
1147
1148     push @m, "\nPASTHRU = \\\n ", join (",\\\n ", @pasthru), "\n";
1149     join "", @m;
1150 }
1151
1152
1153 sub subdir_x {
1154     my($self, $subdir) = @_;
1155     unless (ref $self){
1156         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1157         $self = $ExtUtils::MakeMaker::Parent[-1];
1158     }
1159     my(@m,$key);
1160     $subdir = $self->fixpath($subdir,1);
1161     push @m, '
1162
1163 subdirs ::
1164         olddef = F$Environment("Default")
1165         Set Default ',$subdir,'
1166         - $(MMS) all $(USEMACROS)$(PASTHRU)$(MACROEND)
1167         Set Default \'olddef\'
1168 ';
1169     join('',@m);
1170 }
1171
1172
1173 # --- Cleanup and Distribution Sections ---
1174
1175 sub clean {
1176     my($self, %attribs) = @_;
1177     unless (ref $self){
1178         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1179         $self = $ExtUtils::MakeMaker::Parent[-1];
1180     }
1181     my(@m,$dir);
1182     push @m, '
1183 # Delete temporary files but do not touch installed files. We don\'t delete
1184 # the Descrip.MMS here so that a later make realclean still has it to use.
1185 clean ::
1186 ';
1187     foreach $dir (@{$self->{DIR}}) { # clean subdirectories first
1188         my($vmsdir) = $self->fixpath($dir,1);
1189         push( @m, '     If F$Search("'.$vmsdir.'$(MAKEFILE)") Then \\',"\n\t",
1190               '$(PERL) -e "chdir ',"'$vmsdir'",'; print `$(MMS) clean`;"',"\n");
1191     }
1192     push @m, '  $(RM_F) *.Map *.lis *.cpp *$(OBJ_EXT) *$(LIB_EXT) *.Opt $(BOOTSTRAP) $(BASEEXT).bso
1193 ';
1194
1195     my(@otherfiles) = values %{$self->{XS}}; # .c files from *.xs files
1196     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1197     push(@otherfiles, 'blib.dir', 'Makeaperl.MMS', 'extralibs.ld', 'perlmain.c');
1198     push(@otherfiles,$self->catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
1199     my($file,$line);
1200     $line = '';  #avoid unitialized var warning
1201     foreach $file (@otherfiles) {
1202         $file = $self->fixpath($file);
1203         if (length($line) + length($file) > 80) {
1204             push @m, "\t\$(RM_RF) $line\n";
1205             $line = "$file";
1206         }
1207         else { $line .= " $file"; }
1208     }
1209     push @m, "\t\$(RM_RF) $line\n\n";
1210     push(@m, "  $attribs{POSTOP}\n") if $attribs{POSTOP};
1211     join('', @m);
1212 }
1213
1214
1215 sub realclean {
1216     my($self, %attribs) = @_;
1217     unless (ref $self){
1218         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1219         $self = $ExtUtils::MakeMaker::Parent[-1];
1220     }
1221     my(@m);
1222     push(@m,'
1223 # Delete temporary files (via clean) and also delete installed files
1224 realclean :: clean
1225 ');
1226     foreach(@{$self->{DIR}}){
1227         my($vmsdir) = $self->fixpath($_,1);
1228         push(@m, '      If F$Search("'."$vmsdir".'$(MAKEFILE)").nes."" Then \\',"\n\t",
1229               '$(PERL) -e "chdir ',"'$vmsdir'",'; print `$(MMS) realclean`;"',"\n");
1230     }
1231     push @m,'   $(RM_RF) $(INST_AUTODIR) $(INST_ARCHAUTODIR)
1232 ';
1233     # We can't expand several of the MMS macros here, since they don't have
1234     # corresponding %$self keys (i.e. they're defined in Descrip.MMS as a
1235     # combination of macros).  In order to stay below DCL's 255 char limit,
1236     # we put only 2 on a line.
1237     my($file,$line,$fcnt);
1238     my(@files) = qw{ *.Opt $(INST_DYNAMIC) $(INST_STATIC) $(INST_BOOT) $(INST_PM) $(OBJECT) $(MAKEFILE) $(MAKEFILE)_old };
1239     $line = '';  #avoid unitialized var warning
1240     foreach $file (@files) {
1241         $file = $self->fixpath($file);
1242         if (length($line) + length($file) > 80 || ++$fcnt >= 2) {
1243             push @m, "\t\$(RM_F) $line\n";
1244             $line = "$file";
1245             $fcnt = 0;
1246         }
1247         else { $line .= " $file"; }
1248     }
1249     push @m, "\t\$(RM_F) $line\n";
1250     if ($attribs{FILES} && ref $attribs{FILES} eq 'ARRAY') {
1251         $line = '';
1252         foreach $file (@{$attribs{'FILES'}}) {
1253             $file = $self->fixpath($file);
1254             if (length($line) + length($file) > 80) {
1255                 push @m, "\t\$(RM_RF) $line\n";
1256                 $line = "$file";
1257             }
1258             else { $line .= " $file"; }
1259         }
1260         push @m, "\t\$(RM_RF) $line\n";
1261     }
1262     push(@m, "  $attribs{POSTOP}\n")                     if $attribs{POSTOP};
1263     join('', @m);
1264 }
1265
1266
1267 sub dist_basics {
1268     my($self) = @_;
1269     unless (ref $self){
1270         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1271         $self = $ExtUtils::MakeMaker::Parent[-1];
1272     }
1273 '
1274 distclean :: realclean distcheck
1275         $(NOOP)
1276
1277 distcheck :
1278         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::Manifest \'&fullcheck\'; fullcheck()"
1279
1280 skipcheck :
1281         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::Manifest \'&fullcheck\'; skipcheck()"
1282
1283 manifest :
1284         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::Manifest \'&mkmanifest\'; mkmanifest()"
1285 ';
1286 }
1287
1288
1289 sub dist_core {
1290     my($self) = @_;
1291     unless (ref $self){
1292         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1293         $self = $ExtUtils::MakeMaker::Parent[-1];
1294     }
1295 '
1296 dist : $(DIST_DEFAULT)
1297         $(NOOP)
1298
1299 zipdist : $(DISTVNAME).zip$(SUFFIX)
1300         $(NOOP)
1301
1302 $(DISTVNAME).zip$(SUFFIX) : distdir
1303         $(PREOP)
1304         $(ZIP) "$(ZIPFLAGS)" $(MMS$TARGET) $(SRC)
1305         $(RM_RF) $(DISTVNAME)
1306         $(POSTOP)
1307
1308 shdist : distdir
1309         $(PREOP)
1310         $(SHARE) $(SRC) $(DISTVNAME).share$(SUFFIX)
1311         $(RM_RF) $(DISTVNAME)
1312         $(POSTOP)
1313 ';
1314 }
1315
1316
1317 sub dist_dir {
1318     my($self) = @_;
1319     unless (ref $self){
1320         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1321         $self = $ExtUtils::MakeMaker::Parent[-1];
1322     }
1323 q{
1324 distdir :
1325         $(RM_RF) $(DISTVNAME)
1326         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::Manifest '/mani/';" \\
1327         -e "manicopy(maniread(),'$(DISTVNAME)','$(DIST_CP)');"
1328 };
1329 }
1330
1331
1332 sub dist_test {
1333     my($self) = @_;
1334     unless (ref $self){
1335         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1336         $self = $ExtUtils::MakeMaker::Parent[-1];
1337     }
1338 q{
1339 disttest : distdir
1340         startdir = F$Environment("Default")
1341         Set Default [.$(DISTVNAME)]
1342         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" Makefile.PL
1343         $(MMS)
1344         $(MMS) test
1345         Set Default 'startdir'
1346 };
1347 }
1348
1349 sub dist_ci {
1350     my($self) = @_;
1351     unless (ref $self){
1352         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1353         $self = $ExtUtils::MakeMaker::Parent[-1];
1354     }
1355 '';
1356 }
1357
1358
1359 # --- Test and Installation Sections ---
1360
1361
1362
1363 sub install {
1364     my($self, %attribs) = @_;
1365     unless (ref $self){
1366         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1367         $self = $ExtUtils::MakeMaker::Parent[-1];
1368     }
1369     my(@m);
1370     push @m, q{
1371 doc_install ::
1372         @ Write Sys$Output "Appending installation info to $(INST_ARCHLIB)perllocal.pod"
1373         @ $(PERL) "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)"  \\
1374                 -e "use ExtUtils::MakeMaker; MY->new({})->writedoc('Module', '$(NAME)', \\
1375                 'LINKTYPE=$(LINKTYPE)', 'VERSION=$(VERSION)', 'XS_VERSION=$(XS_VERSION)', 'EXE_FILES=$(EXE_FILES)')" \\
1376                 >>$(INSTALLARCHLIB)perllocal.pod
1377 };
1378
1379     push(@m, "
1380 install :: pure_install doc_install
1381         \$(NOOP)
1382
1383 # Interim solution for VMS; assumes directory tree of same structure under
1384 # both \$(INST_LIB) and \$(INSTALLPRIVLIB).  This operation will be assumed
1385 # into MakeMaker in a (near) future version.
1386 pure_install :: all
1387 ");
1388 #    # install subdirectories first
1389 #    foreach(@{$self->{DIR}}){
1390 #      my($vmsdir) = $self->fixpath($_,1);
1391 #      push(@m, '       If F$Search("',$vmsdir,'$(MAKEFILE)").nes."" Then $(PERL) -e "chdir ',"'$vmsdir'",
1392 #           '; print `$(MMS) install`"'."\n");
1393 #    }
1394 #
1395 #    push(@m, ' @ $(PERL) "-I$(PERL_LIB)" -e "use File::Path; mkpath(\@ARGV)" $(INSTALLPRIVLIB) $(INSTALLARCHLIB)
1396 #       @ $(PERL) -e "die qq{You do not have permissions to install into $ARGV[0]\n} unless -w VMS::Filespec::fileify($ARGV[0])" $(INSTALLPRIVLIB)
1397 #       @ $(PERL) -e "die qq{You do not have permissions to install into $ARGV[0]\n} unless -w VMS::Filespec::fileify($ARGV[0])" $(INSTALLARCHLIB)',"
1398 #       # Can't install manpages here -- INST_MAN%DIR macros make line >255 chars
1399 #       \$(MMS) \$(USEMACROS)INST_LIB=$self->{INSTALLPRIVLIB},INST_ARCHLIB=$self->{INSTALLARCHLIB},INST_EXE=$self->{INSTALLBIN}\$(MACROEND)",'
1400 #       @ $(PERL) -i_bak -lne "print unless $seen{$_}++" $(INST_ARCHAUTODIR).packlist
1401 #');
1402
1403     my($curtop,$insttop);
1404     ($curtop = $self->fixpath($self->{INST_LIB},1)) =~ s/]$//;
1405     ($insttop = $self->fixpath($self->{INSTALLPRIVLIB},1)) =~ s/]$//;
1406     push(@m,"   Backup/Log ${curtop}...]*.*; ${insttop}...]/New_Version/By_Owner=Parent\n");
1407
1408     push @m, '
1409 ##### UNINSTALL IS STILL EXPERIMENTAL ####
1410 uninstall ::
1411 ';
1412     foreach(@{$self->{DIR}}){
1413       my($vmsdir) = $self->fixpath($_,1);
1414       push(@m, '        If F$Search("',$vmsdir,'$(MAKEFILE)").nes."" Then $(PERL) -e "chdir ',"'$vmsdir'",
1415            '; print `$(MMS) uninstall`"'."\n");
1416     }
1417     push @m, "\t".'$(PERL) -le "use File::Path; foreach (<>) {s/',"$curtop/$insttop/;",'rmtree($_,1,0);}" <$(INST_ARCHAUTODIR).packlist
1418 ';
1419
1420     join("",@m);
1421 }
1422
1423
1424 sub perldepend {
1425     my($self) = @_;
1426     unless (ref $self){
1427         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1428         $self = $ExtUtils::MakeMaker::Parent[-1];
1429     }
1430     my(@m);
1431
1432     push @m, '
1433 $(OBJECT) : $(PERL_INC)EXTERN.h, $(PERL_INC)INTERN.h, $(PERL_INC)XSUB.h, $(PERL_INC)av.h
1434 $(OBJECT) : $(PERL_INC)cop.h, $(PERL_INC)cv.h, $(PERL_INC)embed.h, $(PERL_INC)form.h
1435 $(OBJECT) : $(PERL_INC)gv.h, $(PERL_INC)handy.h, $(PERL_INC)hv.h, $(PERL_INC)keywords.h
1436 $(OBJECT) : $(PERL_INC)mg.h, $(PERL_INC)op.h, $(PERL_INC)opcode.h, $(PERL_INC)patchlevel.h
1437 $(OBJECT) : $(PERL_INC)perl.h, $(PERL_INC)perly.h, $(PERL_INC)pp.h, $(PERL_INC)proto.h
1438 $(OBJECT) : $(PERL_INC)regcomp.h, $(PERL_INC)regexp.h, $(PERL_INC)scope.h, $(PERL_INC)sv.h
1439 $(OBJECT) : $(PERL_INC)vmsish.h, $(PERL_INC)util.h, $(PERL_INC)config.h
1440
1441 ' if $self->{OBJECT}; 
1442
1443     push(@m,'
1444 # Check for unpropagated config.sh changes. Should never happen.
1445 # We do NOT just update config.h because that is not sufficient.
1446 # An out of date config.h is not fatal but complains loudly!
1447 #$(PERL_INC)config.h : $(PERL_SRC)config.sh
1448 $(PERL_INC)config.h : $(PERL_VMS)config.vms
1449         @ Write Sys$Error "Warning: $(PERL_INC)config.h out of date with $(PERL_VMS)config.vms"
1450
1451 #$(PERL_ARCHLIB)Config.pm : $(PERL_SRC)config.sh
1452 $(PERL_ARCHLIB)Config.pm : $(PERL_VMS)config.vms $(PERL_VMS)genconfig.pl
1453         @ Write Sys$Error "$(PERL_ARCHLIB)Config.pm may be out of date with config.vms or genconfig.pl"
1454         olddef = F$Environment("Default")
1455         Set Default $(PERL_SRC)
1456         $(MMS) $(USEMAKEFILE)[.VMS]$(MAKEFILE) [.lib.',$Config{'arch'},']config.pm
1457         Set Default \'olddef\'
1458 ') if $self->{PERL_SRC};
1459
1460     push(@m, join(" ", map($self->fixpath($_),values %{$self->{XS}}))." : \$(XSUBPPDEPS)\n")
1461       if %{$self->{XS}};
1462
1463     join('',@m);
1464 }
1465
1466 sub makefile {
1467     my($self) = @_;
1468     unless (ref $self){
1469         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1470         $self = $ExtUtils::MakeMaker::Parent[-1];
1471     }
1472     my(@m,@cmd);
1473     # We do not know what target was originally specified so we
1474     # must force a manual rerun to be sure. But as it should only
1475     # happen very rarely it is not a significant problem.
1476     push @m, '
1477 $(OBJECT) : $(FIRST_MAKEFILE)
1478 ' if $self->{OBJECT};
1479
1480     push @m,'
1481 # We take a very conservative approach here, but it\'s worth it.
1482 # We move $(MAKEFILE) to $(MAKEFILE)_old here to avoid gnu make looping.
1483 $(MAKEFILE) : Makefile.PL $(CONFIGDEP)
1484         @ Write Sys$Output "$(MAKEFILE) out-of-date with respect to $(MMS$SOURCE_LIST)"
1485         @ Write Sys$Output "Cleaning current config before rebuilding $(MAKEFILE) ..."
1486         - $(MV) $(MAKEFILE) $(MAKEFILE)_old
1487         - $(MMS) $(USEMAKEFILE)$(MAKEFILE)_old clean
1488         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" Makefile.PL ',join(' ',@ARGV),'
1489         @ Write Sys$Output "$(MAKEFILE) has been rebuilt."
1490         @ Write Sys$Output "Please run $(MMS) to build the extension."
1491 ';
1492
1493     join('',@m);
1494 }
1495
1496
1497 sub test {
1498     my($self, %attribs) = @_;
1499     unless (ref $self){
1500         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1501         $self = $ExtUtils::MakeMaker::Parent[-1];
1502     }
1503     my($tests) = $attribs{TESTS} || ( -d 't' ? 't/*.t' : '');
1504     my(@m);
1505     push @m,"
1506 TEST_VERBOSE = 0
1507 TEST_TYPE=test_\$(LINKTYPE)
1508
1509 test : \$(TEST_TYPE)
1510         \$(NOOP)
1511 ";
1512     foreach(@{$self->{DIR}}){
1513       my($vmsdir) = $self->fixpath($_,1);
1514       push(@m, '        If F$Search("',$vmsdir,'$(MAKEFILE)").nes."" Then $(PERL) -e "chdir ',"'$vmsdir'",
1515            '; print `$(MMS) $(PASTHRU2) test`'."\n");
1516     }
1517     push(@m, "\t\@ Write Sys\$Output 'No tests defined for \$(NAME) extension.'\n")
1518         unless $tests or -f "test.pl" or @{$self->{DIR}};
1519     push(@m, "\n");
1520
1521     push(@m, "test_dynamic :: all\n");
1522     push(@m, $self->test_via_harness('$(FULLPERL)', $tests)) if $tests;
1523     push(@m, $self->test_via_script('$(FULLPERL)', 'test.pl')) if -f "test.pl";
1524     push(@m, "\n");
1525
1526     # Occasionally we may face this degenerate target:
1527     push @m, "test_ : test_dynamic\n\n";
1528  
1529         if ($self->needs_linking()) {
1530         push(@m, "test_static :: all \$(MAP_TARGET)\n");
1531         push(@m, $self->test_via_harness('$(MAP_TARGET)', $tests)) if $tests;
1532         push(@m, $self->test_via_script('$(MAP_TARGET)', 'test.pl')) if -f "test.pl";
1533         push(@m, "\n");
1534     }
1535     else {
1536         push @m, "test_static :: test_dynamic\n";
1537     }
1538
1539     join('',@m);
1540 }
1541
1542
1543 sub test_via_harness {
1544     my($self,$perl,$tests) = @_;
1545     unless (ref $self){
1546         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1547         $self = $ExtUtils::MakeMaker::Parent[-1];
1548     }
1549     "   $perl".' "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)" \\'."\n\t".
1550     '-e "use Test::Harness qw(&runtests $verbose); $verbose=$(TEST_VERBOSE); runtests @ARGV;" \\'."\n\t$tests\n";
1551 }
1552
1553
1554 sub test_via_script {
1555     my($self,$perl,$script) = @_;
1556     unless (ref $self){
1557         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1558         $self = $ExtUtils::MakeMaker::Parent[-1];
1559     }
1560     "   $perl".' "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" test.pl
1561 ';
1562 }
1563
1564
1565 sub makeaperl {
1566     my($self, %attribs) = @_;
1567     unless (ref $self){
1568         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1569         $self = $ExtUtils::MakeMaker::Parent[-1];
1570     }
1571     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) = 
1572       @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
1573     my(@m);
1574     push @m, "
1575 # --- MakeMaker makeaperl section ---
1576 MAP_TARGET    = $target
1577 ";
1578     return join '', @m if $self->{PARENT};
1579
1580     my($dir) = join ":", @{$self->{DIR}};
1581
1582     unless ($self->{MAKEAPERL}) {
1583         push @m, q{
1584 $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE)
1585         @ Write Sys$Output "Writing ""$(MMS$TARGET)"" for this $(MAP_TARGET)"
1586         @ $(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" \
1587                 Makefile.PL DIR=}, $dir, q{ \
1588                 MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
1589                 MAKEAPERL=1 NORECURS=1
1590
1591 $(MAP_TARGET) :: $(MAKE_APERL_FILE)
1592         $(MMS)$(USEMAKEFILE)$(MAKE_APERL_FILE) static $(MMS$TARGET)
1593 };
1594         push @m, map( " \\\n\t\t$_", @ARGV );
1595         push @m, "\n";
1596
1597         return join '', @m;
1598     }
1599
1600
1601     my($linkcmd,@staticopts,@staticpkgs,$extralist,$target,$targdir,$libperldir);
1602
1603     # The front matter of the linkcommand...
1604     $linkcmd = join ' ', $Config{'ld'},
1605             grep($_, @Config{qw(large split ldflags ccdlflags)});
1606     $linkcmd =~ s/\s+/ /g;
1607
1608     # Which *.olb files could we make use of...
1609     local(%olbs);
1610     $olbs{$self->{INST_ARCHAUTODIR}} = "$self->{BASEEXT}\$(LIB_EXT)";
1611     File::Find::find(sub {
1612         return unless m/\Q$self->{LIB_EXT}\E$/;
1613         return if m/^libperl/;
1614         $olbs{$ENV{DEFAULT}} = $_;
1615     }, grep( -d $_, @{$searchdirs || []}));
1616
1617     # We trust that what has been handed in as argument will be buildable
1618     $static = [] unless $static;
1619     @olbs{@{$static}} = (1) x @{$static};
1620  
1621     $extra = [] unless $extra && ref $extra eq 'ARRAY';
1622     # Sort the object libraries in inverse order of
1623     # filespec length to try to insure that dependent extensions
1624     # will appear before their parents, so the linker will
1625     # search the parent library to resolve references.
1626     # (e.g. Intuit::DWIM will precede Intuit, so unresolved
1627     # references from [.intuit.dwim]dwim.obj can be found
1628     # in [.intuit]intuit.olb).
1629     for (sort keys %olbs) {
1630         next unless $olbs{$_} =~ /\Q$self->{LIB_EXT}\E$/;
1631         my($dir) = $self->fixpath($_,1);
1632         my($extralibs) = $dir . "extralibs.ld";
1633         my($extopt) = $dir . $olbs{$_};
1634         $extopt =~ s/$self->{LIB_EXT}$/.opt/;
1635         if (-f $extralibs ) {
1636             open LIST,$extralibs or warn $!,next;
1637             push @$extra, <LIST>;
1638             close LIST;
1639         }
1640         if (-f $extopt) {
1641             open OPT,$extopt or die $!;
1642             while (<OPT>) {
1643                 next unless /(?:UNIVERSAL|VECTOR)=boot_([\w_]+)/;
1644                 # ExtUtils::Miniperl expects Unix paths
1645                 (my($pkg) = "$1_$1$self->{LIB_EXT}") =~ s#_*#/#g;
1646                 push @staticpkgs,$pkg;
1647             }
1648             push @staticopts, $extopt;
1649         }
1650     }
1651
1652     $target = "Perl.Exe" unless $target;
1653     ($shrtarget,$targdir) = fileparse($target);
1654     $shrtarget =~ s/^([^.]*)/$1Shr/;
1655     $shrtarget = $targdir . $shrtarget;
1656     $target = "Perlshr.$Config{'dlext'}" unless $target;
1657     $tmp = "[]" unless $tmp;
1658     $tmp = $self->fixpath($tmp,1);
1659     if (@$extra) {
1660         $extralist = join(' ',@$extra);
1661         $extralist =~ s/[,\s\n]+/, /g;
1662     }
1663     else { $extralist = ''; }
1664     if ($libperl) {
1665         unless (-f $libperl || -f ($libperl = $self->catfile($Config{'installarchlib'},'CORE',$libperl))) {
1666             print STDOUT "Warning: $libperl not found\n";
1667             undef $libperl;
1668         }
1669     }
1670     unless ($libperl) {
1671         if (defined $self->{PERL_SRC}) {
1672             $libperl = $self->catfile($self->{PERL_SRC},"libperl$self->{LIB_EXT}");
1673         } elsif (-f ($libperl = $self->catfile($Config{'installarchlib'},'CORE',"libperl$self->{LIB_EXT}")) ) {
1674         } else {
1675             print STDOUT "Warning: $libperl not found
1676     If you're going to build a static perl binary, make sure perl is installed
1677     otherwise ignore this warning\n";
1678         }
1679     }
1680     $libperldir = $self->fixpath((fileparse($libperl))[1],1);
1681
1682     push @m, '
1683 # Fill in the target you want to produce if it\'s not perl
1684 MAP_TARGET    = ',$self->fixpath($target),'
1685 MAP_SHRTARGET = ',$self->fixpath($shrtarget),"
1686 MAP_LINKCMD   = $linkcmd
1687 MAP_PERLINC   = ", $perlinc ? map('"$_" ',@{$perlinc}) : '','
1688 # We use the linker options files created with each extension, rather than
1689 #specifying the object files directly on the command line.
1690 MAP_STATIC    = ',@staticopts ? join(' ', @staticopts) : '','
1691 MAP_OPTS    = ',@staticopts ? ','.join(',', map($_.'/Option', @staticopts)) : '',"
1692 MAP_EXTRA     = $extralist
1693 MAP_LIBPERL = ",$self->fixpath($libperl),'
1694 ';
1695
1696
1697     push @m,'
1698 $(MAP_SHRTARGET) : $(MAP_LIBPERL) $(MAP_STATIC) ',"${libperldir}Perlshr_Attr.Opt",'
1699         $(MAP_LINKCMD)/Shareable=$(MMS$TARGET) $(MAP_OPTS), $(MAP_EXTRA), $(MAP_LIBPERL) ',"${libperldir}Perlshr_Attr.Opt",'
1700 $(MAP_TARGET) : $(MAP_SHRTARGET) ',"${tmp}perlmain\$(OBJ_EXT) ${tmp}PerlShr.Opt",'
1701         $(MAP_LINKCMD) ',"${tmp}perlmain\$(OBJ_EXT)",', PerlShr.Opt/Option
1702         @ Write Sys$Output "To install the new ""$(MAP_TARGET)"" binary, say"
1703         @ Write Sys$Output "    $(MMS)$(USEMAKEFILE)$(MAKEFILE) inst_perl $(USEMACROS)MAP_TARGET=$(MAP_TARGET)$(ENDMACRO)"
1704         @ Write Sys$Output "To remove the intermediate files, say
1705         @ Write Sys$Output "    $(MMS)$(USEMAKEFILE)$(MAKEFILE) map_clean"
1706 ';
1707     push @m,'
1708 ',"${tmp}perlmain.c",' : $(MAKEFILE)
1709         @ $(PERL) $(MAP_PERLINC) -e "use ExtUtils::Miniperl; writemain(qw|',@staticpkgs,'|)" >$(MMS$TARGET)
1710 ';
1711
1712     push @m, q{
1713 doc_inst_perl :
1714         @ $(PERL) -e "use ExtUtils::MakeMaker; MY->new()->writedoc('Perl binary','$(MAP_TARGET)','MAP_STATIC=$(MAP_STATIC)','MAP_EXTRA=$(MAP_EXTRA)','MAP_LIBPERL=$(MAP_LIBPERL)')"
1715 };
1716
1717     push @m, "
1718 inst_perl : pure_inst_perl doc_inst_perl
1719         \$(NOOP)
1720
1721 pure_inst_perl : \$(MAP_TARGET)
1722         $self->{CP} \$(MAP_SHRTARGET) ",$self->fixpath($Config{'installbin'},1),"
1723         $self->{CP} \$(MAP_TARGET) ",$self->fixpath($Config{'installbin'},1),"
1724
1725 clean :: map_clean
1726         \$(NOOP)
1727
1728 map_clean :
1729         \$(RM_F) ${tmp}perlmain\$(OBJ_EXT) ${tmp}perlmain.c \$(MAKEFILE)
1730         \$(RM_F) ${tmp}PerlShr.Opt \$(MAP_TARGET)
1731 ";
1732
1733     join '', @m;
1734 }
1735   
1736 sub extliblist {
1737     my($self) = @_;
1738     unless (ref $self){
1739         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1740         $self = $ExtUtils::MakeMaker::Parent[-1];
1741     }
1742     '','','';
1743 }
1744
1745
1746 sub mksymlists {
1747     my($self,%attribs) = @_;
1748     unless (ref $self){
1749         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1750         $self = $ExtUtils::MakeMaker::Parent[-1];
1751     }
1752
1753     my($vars) = $attribs{DL_VARS} || $self->{DL_VARS} || [];
1754     my($procs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS};
1755     my($package,$packprefix,$sym,$optname);
1756     local(*OPT);
1757
1758     if (!$procs) {
1759         $package = $self->{NAME};
1760         $package =~ s/\W/_/g;
1761         $procs = { $package => ["boot_$package"] };
1762     }
1763     my($isvax) = $Config{'arch'} =~ /VAX/i;
1764
1765     # Options file declaring universal symbols
1766     # Used when linking shareable image for dynamic extension,
1767     # or when linking PerlShr into which we've added this package
1768     # as a static extension
1769     # We don't do anything to preserve order, so we won't relax
1770     # the GSMATCH criteria for a dynamic extension
1771
1772     # BASEEXT is not available when mksymlists is run, so we
1773     # create the options file name directly from NAME
1774     # May cause trouble if Makefile.PL author specifies NAME
1775     # and BASEEXT directly as unrelated strings.
1776     ($optname = $self->{NAME}) =~ s/.*:://;
1777     open OPT, ">$optname.opt";
1778     foreach $package (keys %$procs) {
1779         ($packprefix = $package) =~ s/\W/_/g;
1780         foreach $sym (@{$$procs{$package}}) {
1781             $sym = "XS_${packprefix}_$sym" unless $sym =~ /^boot_/;
1782             if ($isvax) { print OPT "UNIVERSAL=$sym\n" }
1783             else        { print OPT "SYMBOL_VECTOR=($sym=PROCEDURE)\n"; }
1784         }
1785     }
1786     foreach $sym (@$vars) {
1787         print OPT "PSECT_ATTR=${sym},PIC,OVR,RD,NOEXE,WRT,NOSHR\n";
1788         if ($isvax) { print OPT "UNIVERSAL=$sym\n" }
1789         else        { print OPT "SYMBOL_VECTOR=($sym=DATA)\n"; }
1790     }
1791     close OPT;
1792
1793     # Options file specifying RTLs to which this extension must be linked.
1794     # Eventually, the list of libraries will be supplied by a working
1795     # extliblist routine.
1796     open OPT,'>rtls.opt';
1797     print OPT "PerlShr/Share\n";
1798     foreach $rtl (split(/\s+/,$Config{'libs'})) { print OPT "$rtl\n"; }
1799     close OPT;
1800 }
1801
1802
1803 # --- Make-Directories section (internal method) ---
1804 # dir_target(@array) returns a Makefile entry for the file .exists in each
1805 # named directory. Returns nothing, if the entry has already been processed.
1806 # We're helpless though, if the same directory comes as $(FOO) _and_ as "bar".
1807 # Both of them get an entry, that's why we use "::". I chose '$(PERL)' as the 
1808 # prerequisite, because there has to be one, something that doesn't change 
1809 # too often :)
1810
1811 sub dir_target {
1812     my($self,@dirs) = @_;
1813     unless (ref $self){
1814         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1815         $self = $ExtUtils::MakeMaker::Parent[-1];
1816     }
1817     my(@m,$dir);
1818     foreach $dir (@dirs) {
1819         next if $self->{DIR_TARGET}{$self}{$dir}++;
1820         my($vmsdir) = $self->fixpath($dir,1);
1821         push @m, "
1822 ${vmsdir}.exists :: \$(PERL_INC)perl.h
1823         \@ \$(MKPATH) $vmsdir
1824         \@ \$(TOUCH) ${vmsdir}.exists
1825 ";
1826     }
1827     join "", @m;
1828 }
1829
1830
1831 # --- Output postprocessing section ---
1832
1833 sub nicetext {
1834     # Insure that colons marking targets are preceded by space -
1835     # most Unix Makes don't need this, but it's necessary under VMS
1836     # to distinguish the target delimiter from a colon appearing as
1837     # part of a filespec.
1838
1839     my($self,$text) = @_;
1840     unless (ref $self){
1841         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1842         $self = $ExtUtils::MakeMaker::Parent[-1];
1843     }
1844     $text =~ s/([^\s:])(:+\s)/$1 $2/gs;
1845     $text;
1846 }
1847
1848 1;
1849
1850 __END__