New file. Incorporates VMS-specific items into MakeMaker.
[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.12
7 #   Author:  Charles Bailey  bailey@genetics.upenn.edu
8 #   Revised: 12-Dec-1995
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 # AFS users will want to set the installation directories for
304 # the final 'make install' early without setting INST_LIB,
305 # INST_ARCHLIB, and INST_EXE for the testing phase
306 INSTALLPRIVLIB = ",$self->fixpath($self->{INSTALLPRIVLIB},1),'
307 INSTALLARCHLIB = ',$self->fixpath($self->{INSTALLARCHLIB},1),'
308 INSTALLBIN = ',$self->fixpath($self->{INSTALLBIN},1),'
309
310 # Perl library to use when building the extension
311 PERL_LIB = ',$self->fixpath($self->{PERL_LIB},1),'
312 PERL_ARCHLIB = ',$self->fixpath($self->{PERL_ARCHLIB},1),'
313 LIBPERL_A = ',$self->fixpath($self->{LIBPERL_A}),'
314
315 MAKEMAKER = ',$self->catfile($self->{PERL_LIB},'ExtUtils','MakeMaker.pm'),"
316 MM_VERSION = $ExtUtils::MakeMaker::VERSION
317 FIRST_MAKEFILE  = ",$self->fixpath($self->{FIRST_MAKEFILE}),'
318 MAKE_APERL_FILE = ',$self->fixpath($self->{MAKE_APERL_FILE}),"
319
320 PERLMAINCC = $self->{PERLMAINCC}
321 ";
322
323     if ($self->{PERL_SRC}) {
324          push @m, "
325 # Where is the perl source code located?
326 PERL_SRC = ",$self->fixpath($self->{PERL_SRC},1);
327         push @m, "
328 PERL_VMS = ",$self->catdir($self->{PERL_SRC},q(VMS));
329     }
330     push @m,"
331 # Perl header files (will eventually be under PERL_LIB)
332 PERL_INC = ",$self->fixpath($self->{PERL_INC},1),"
333 # Perl binaries
334 PERL = $self->{PERL}
335 FULLPERL = $self->{FULLPERL}
336
337 # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
338 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
339 # ROOTEXT = Directory part of FULLEXT with leading slash (e.g /DBD)
340 FULLEXT = ",$self->fixpath($self->{FULLEXT},1),"
341 BASEEXT = $self->{BASEEXT}
342 ROOTEXT = ",($self->{ROOTEXT} eq '') ? '[]' : $self->fixpath($self->{ROOTEXT},1),"
343 DLBASE  = $self->{DLBASE}
344 INC = ";
345
346     if ($self->{'INC'}) {
347         push @m,'/Include=(';
348         my(@includes) = split(/\s+/,$self->{INC});
349         my($plural);
350         foreach (@includes) {
351             s/^-I//;
352             push @m,', ' if $plural++;
353             push @m,$self->fixpath($_,1);
354         }
355         push @m, ")\n";
356     }
357
358     if ($self->{DEFINE} ne '') {
359         my(@defs) = split(/\s+/,$self->{DEFINE});
360         foreach $def (@defs) {
361             next unless $def;
362             $def =~ s/^-D//;
363             $def = "\"$def\"" if $def =~ /=/;
364         }
365         $self->{DEFINE} = join ',',@defs;
366     }
367
368     if ($self->{OBJECT} =~ /\s/) {
369         $self->{OBJECT} =~ s/(\\)?\n+\s+/ /g;
370         $self->{OBJECT} = map($self->fixpath($_),split(/,?\s+/,$self->{OBJECT}));
371     }
372     $self->{LDFROM} = join(' ',map($self->fixpath($_),split(/,?\s+/,$self->{LDFROM})));
373
374     push @m,"
375 DEFINE = $self->{DEFINE}
376 OBJECT = $self->{OBJECT}
377 LDFROM = $self->{LDFROM}
378 LINKTYPE = $self->{LINKTYPE}
379
380 # Handy lists of source code files:
381 XS_FILES = ",join(', ', sort keys %{$self->{XS}}),'
382 C_FILES  = ',join(', ', @{$self->{C}}),'
383 O_FILES  = ',join(', ', @{$self->{O_FILES}} ),'
384 H_FILES  = ',join(', ', @{$self->{H}}),'
385 MAN1PODS = ',join(" \\\n\t", sort keys %{$self->{MAN1PODS}}),'
386 MAN3PODS = ',join(" \\\n\t", sort keys %{$self->{MAN3PODS}}),'
387
388 # Man installation stuff:
389 INST_MAN1DIR = ',$self->fixpath($self->{INST_MAN1DIR},1),'
390 INSTALLMAN1DIR = ',$self->fixpath($self->{INSTALLMAN1DIR},1),"
391 MAN1EXT = $self->{MAN1EXT}
392
393 INST_MAN3DIR = ",$self->fixpath($self->{INST_MAN3DIR},1),'
394 INSTALLMAN3DIR = ',$self->fixpath($self->{INSTALLMAN3DIR},1),"
395 MAN3EXT = $self->{MAN3EXT}
396
397
398 .SUFFIXES : .xs .c \$(OBJ_EXT)
399
400 # This extension may link to it's own library (see SDBM_File)";
401     push @m,"
402 MYEXTLIB = ",$self->fixpath($self->{MYEXTLIB}),"
403
404 # Here is the Config.pm that we are using/depend on
405 CONFIGDEP = \$(PERL_ARCHLIB)Config.pm, \$(PERL_INC)config.h
406
407 # Where to put things:
408 INST_LIBDIR = ",($self->{'INST_LIBDIR'} = $self->catdir($self->{INST_LIB},$self->{ROOTEXT})),"
409 INST_ARCHLIBDIR = ",($self->{'INST_ARCHLIBDIR'} = $self->catdir($self->{INST_ARCHLIB},$self->{ROOTEXT})),"
410
411 INST_AUTODIR = ",($self->{'INST_AUTODIR'} = $self->catdir($self->{INST_LIB},'auto',$self->{FULLEXT})),'
412 INST_ARCHAUTODIR = ',($self->{'INST_ARCHAUTODIR'} = $self->catdir($self->{INST_ARCHLIB},'auto',$self->{FULLEXT})),'
413 ';
414
415     if ($self->has_link_code()) {
416         push @m,'
417 INST_STATIC = $(INST_ARCHAUTODIR)$(BASEEXT)$(LIB_EXT)
418 INST_DYNAMIC = $(INST_ARCHAUTODIR)$(BASEEXT).$(DLEXT)
419 INST_BOOT = $(INST_ARCHAUTODIR)$(BASEEXT).bs
420 ';
421     } else {
422         push @m,'
423 INST_STATIC =
424 INST_DYNAMIC =
425 INST_BOOT =
426 ';
427     }
428
429     push @m,'
430 INST_PM = ',join(', ',map($self->fixpath($_),sort values %{$self->{PM}})),'
431 ';
432
433     join('',@m);
434 }
435
436
437 sub const_loadlibs{
438     my($self) = @_;
439     unless (ref $self){
440         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
441         $self = $ExtUtils::MakeMaker::Parent[-1];
442     }
443     my (@m);
444     push @m, "
445 # $self->{NAME} might depend on some other libraries.
446 # (These comments may need revising:)
447 #
448 # Dependent libraries can be linked in one of three ways:
449 #
450 #  1.  (For static extensions) by the ld command when the perl binary
451 #      is linked with the extension library. See EXTRALIBS below.
452 #
453 #  2.  (For dynamic extensions) by the ld command when the shared
454 #      object is built/linked. See LDLOADLIBS below.
455 #
456 #  3.  (For dynamic extensions) by the DynaLoader when the shared
457 #      object is loaded. See BSLOADLIBS below.
458 #
459 # EXTRALIBS =   List of libraries that need to be linked with when
460 #               linking a perl binary which includes this extension
461 #               Only those libraries that actually exist are included.
462 #               These are written to a file and used when linking perl.
463 #
464 # LDLOADLIBS =  List of those libraries which can or must be linked into
465 #               the shared library when created using ld. These may be
466 #               static or dynamic libraries.
467 #               LD_RUN_PATH is a colon separated list of the directories
468 #               in LDLOADLIBS. It is passed as an environment variable to
469 #               the process that links the shared library.
470 #
471 # BSLOADLIBS =  List of those libraries that are needed but can be
472 #               linked in dynamically at run time on this platform.
473 #               SunOS/Solaris does not need this because ld records
474 #               the information (from LDLOADLIBS) into the object file.
475 #               This list is used to create a .bs (bootstrap) file.
476 #
477 EXTRALIBS  = ",map($self->fixpath($_) . ' ',$self->{'EXTRALIBS'}),"
478 BSLOADLIBS = ",map($self->fixpath($_) . ' ',$self->{'BSLOADLIBS'}),"
479 LDLOADLIBS = ",map($self->fixpath($_) . ' ',$self->{'LDLOADLIBS'}),"\n";
480
481     join('',@m);
482 }
483
484
485 sub const_cccmd {
486     my($self,$libperl) = @_;
487     unless (ref $self){
488         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
489         $self = $ExtUtils::MakeMaker::Parent[-1];
490     }
491     my($cmd) = $Config{'cc'};
492     my($name,$sys,@m);
493
494     ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
495     print STDOUT "Unix shell script ".$Config{"$self->{'BASEEXT'}_cflags"}.
496          " required to modify CC command for $self->{'BASEEXT'}\n"
497     if ($Config{$name});
498
499     # Deal with $self->{DEFINE} here since some C compilers pay attention
500     # to only one /Define clause on command line, so we have to
501     # conflate the ones from $Config{'cc'} and $self->{DEFINE}
502     if ($cmd =~ m:(.*)/define=\(?([^\(\/\)\s]+)\)?(.*)?:i) {
503         $cmd = "$1/Define=($2," . ($self->{DEFINE} ? "$self->{DEFINE}," : '') .
504                "\$(DEFINE_VERSION))$3";
505 #              "\$(DEFINE_VERSION),\$(XS_DEFINE_VERSION))$3";
506     }
507     else {
508         $cmd .= '/Define=(' . ($self->{DEFINE} ? "$self->{DEFINE}," : '') .
509                 '$(DEFINE_VERSION))';
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         $cmd =~ 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 ($cmd =~ m:(.*)/include=\(?([^\(\/\)\s]+)\)?(.*):i) {
532         $cmd = "$1$incstr,$2)$3";
533     }
534     else { $cmd .= "$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\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 LD = $self->{LD}
690 TOUCH = $self->{TOUCH}
691 CHMOD = $self->{CHMOD}
692 CP = $self->{CP}
693 MV = $self->{MV}
694 RM_F  = $self->{RM_F}
695 RM_RF = $self->{RM_RF}
696 UMASK_NULL = $self->{UMASK_NULL}
697 MKPATH = Create/Directory
698 ";
699 }
700
701
702 sub dist {
703     my($self, %attribs) = @_;
704     unless (ref $self){
705         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
706         $self = $ExtUtils::MakeMaker::Parent[-1];
707     }
708     # VERSION should be sanitised before use as a file name
709     my($name)         = $attribs{NAME}          || '$(DISTVNAME)';
710     my($zip)          = $attribs{ZIP}           || 'zip';
711     my($zipflags)     = $attribs{ZIPFLAGS}      || '-Vu';
712     my($suffix)       = $attribs{SUFFIX}        || '';
713     my($shar)         = $attribs{SHAR}          || 'vms_share';
714     my($preop)        = $attribs{PREOP}         || '!'; # e.g., update MANIFEST
715     my($postop)       = $attribs{POSTOP}        || '!';
716     my($dist_cp)  = $attribs{DIST_CP}  || 'best';
717     my($dist_default) = $attribs{DIST_DEFAULT}  || 'zipdist';
718
719     my($src) = $name;
720     $src = "[.$src]" unless $src =~ /\[/;
721     $src =~ s#\]#...]#;
722     $src .= '*.*' if $src =~ /\]$/;
723     $suffix =~ s#\.#_#g;
724 "
725 DISTVNAME = \$(DISTNAME)-\$(VERSION_SYM)
726 SRC = $src
727 ZIP = $zip
728 ZIPFLAGS = $zipflags
729 SUFFIX = $suffix
730 SHARE = $shar
731 PREOP = $preop
732 POSTOP = $postop
733 DIST_CP = $dist_cp
734 DIST_DEFAULT = $dist_default
735 ";
736 }
737
738
739 # --- Translation Sections ---
740
741 sub c_o {
742     my($self) = @_;
743     unless (ref $self){
744         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
745         $self = $ExtUtils::MakeMaker::Parent[-1];
746     }
747     return '' unless $self->needs_linking();
748     '
749 .c$(OBJ_EXT) :
750         $(CCCMD) $(CCCDLFLAGS) $(MMS$TARGET_NAME).c
751 ';
752 }
753
754 sub xs_c {
755     my($self) = @_;
756     unless (ref $self){
757         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
758         $self = $ExtUtils::MakeMaker::Parent[-1];
759     }
760     return '' unless $self->needs_linking();
761     '
762 .xs.c :
763         $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $(MMS$TARGET_NAME).xs >$(MMS$TARGET)
764 ';
765 }
766
767 sub xs_o {      # many makes are too dumb to use xs_c then c_o
768     my($self) = @_;
769     unless (ref $self){
770         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
771         $self = $ExtUtils::MakeMaker::Parent[-1];
772     }
773     return '' unless $self->needs_linking();
774     '
775 .xs$(OBJ_EXT) :
776         $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $(MMS$TARGET_NAME).xs >$(MMS$TARGET_NAME).c
777         $(CCCMD) $(CCCDLFLAGS) $(MMS$TARGET_NAME).c
778 ';
779 }
780
781
782 # --- Target Sections ---
783
784
785 sub top_targets {
786     my($self) = shift;
787     unless (ref $self){
788         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
789         $self = $ExtUtils::MakeMaker::Parent[-1];
790     }
791     my(@m);
792     push @m, '
793 all ::  config $(INST_PM) subdirs linkext manifypods
794         $(NOOP)
795
796 subdirs :: $(MYEXTLIB)
797         $(NOOP)
798
799 config :: $(MAKEFILE) $(INST_LIBDIR).exists
800
801 config :: $(INST_ARCHAUTODIR).exists Version_check
802
803 config :: $(INST_AUTODIR).exists
804 ';
805
806
807     push @m, $self->dir_target(qw[$(INST_AUTODIR) $(INST_LIBDIR) $(INST_ARCHAUTODIR)]);
808     if (%{$self->{MAN1PODS}}) {
809         push @m, q[
810 config :: $(INST_MAN1DIR)/.exists
811 ];
812         push @m, $self->dir_target(qw[$(INST_MAN1DIR)]);
813     }
814     if (%{$self->{MAN3PODS}}) {
815         push @m, q[
816 config :: $(INST_MAN3DIR).exists
817 ];
818         push @m, $self->dir_target(qw[$(INST_MAN3DIR)]);
819     }
820
821     push @m, '
822 $(O_FILES) : $(H_FILES)
823 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
824
825     push @m, q{
826 help :
827         perldoc ExtUtils::MakeMaker
828 };
829
830     push @m, q{
831 Version_check :
832         @ $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -
833                 -e "use ExtUtils::MakeMaker qw($Version &Version_check);" -
834                 -e "&Version_check('$(MM_VERSION)')"
835 };
836
837     join('',@m);
838 }
839
840
841 sub dlsyms {
842     my($self,%attribs) = @_;
843     unless (ref $self){
844         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
845         $self = $ExtUtils::MakeMaker::Parent[-1];
846     }
847     my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
848     my($vars)  = $attribs{DL_VARS} || $self->{DL_VARS} || [];
849     my(@m);
850
851     push(@m,'
852 dynamic :: rtls.opt $(INST_ARCHAUTODIR)$(BASEEXT).opt
853         $(NOOP)
854
855 # rtls.opt is built in the same step as $(BASEEXT).opt
856 rtls.opt : $(BASEEXT).opt
857         $(TOUCH) $(MMS$TARGET)
858 ') unless $self->{SKIPHASH}{'dynamic'};
859
860     push(@m,'
861 static :: $(INST_ARCHAUTODIR)$(BASEEXT).opt
862         $(NOOP)
863 ') unless $self->{SKIPHASH}{'static'};
864
865     push(@m,'
866 $(INST_ARCHAUTODIR)$(BASEEXT).opt : $(BASEEXT).opt
867         $(CP) $(MMS$SOURCE) $(MMS$TARGET)
868         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
869
870 $(BASEEXT).opt : makefile.PL
871         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::MakeMaker qw(&mksymlists);" -
872                 -e "MM->new()->mksymlists({DL_FUNCS => ',neatvalue($self->{DL_FUNCS}),', DL_VARS => ',neatvalue($self->{DL_VARS}),',NAME => \'',$self->{NAME},'\'})"
873         $(PERL) -e "open OPT,\'>>$(MMS$TARGET)\'; print OPT ""$(INST_STATIC)/Include=$(BASEEXT)\n$(INST_STATIC)/Library\n"";close OPT"
874 ');
875
876     join('',@m);
877 }
878
879
880 # --- Dynamic Loading Sections ---
881
882 sub dynamic_lib {
883     my($self, %attribs) = @_;
884     unless (ref $self){
885         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
886         $self = $ExtUtils::MakeMaker::Parent[-1];
887     }
888     return '' unless $self->needs_linking(); #might be because of a subdir
889
890
891     return '
892 $(INST_DYNAMIC) :
893         $(NOOP)
894 ' unless ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB});
895
896     ($otherldflags) = $attribs{OTHERLDFLAGS} || "";
897     my(@m);
898     push @m,"
899
900 OTHERLDFLAGS = $otherldflags
901
902 ";
903     push @m, '
904 $(INST_DYNAMIC) : $(INST_STATIC) $(PERL_INC)perlshr_attr.opt rtls.opt $(BASEEXT).opt $(INST_ARCHAUTODIR).exists
905         @ $(MKPATH) $(INST_ARCHAUTODIR)
906         Link $(LDFLAGS) /Shareable=$(MMS$TARGET)$(OTHERLDFLAGS) $(BASEEXT).opt/Option,rtls.opt/Option,$(PERL_INC)perlshr_attr.opt/Option
907         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
908 ';
909
910     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
911     join('',@m);
912 }
913
914 sub dynamic_bs {
915     my($self, %attribs) = @_;
916     unless (ref $self){
917         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
918         $self = $ExtUtils::MakeMaker::Parent[-1];
919     }
920     return '' unless $self->needs_linking();
921     '
922 BOOTSTRAP = '."$self->{BASEEXT}.bs".'
923
924 # As MakeMaker mkbootstrap might not write a file (if none is required)
925 # we use touch to prevent make continually trying to remake it.
926 # The DynaLoader only reads a non-empty file.
927 $(BOOTSTRAP) : $(MAKEFILE) '."$self->{BOOTDEP}".'
928         @ Write Sys$Output "Running mkbootstrap for $(NAME) ($(BSLOADLIBS))"
929         @ $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -
930         -e "use ExtUtils::Mkbootstrap; Mkbootstrap(\'$(BASEEXT)\',\'$(BSLOADLIBS)\');"
931         @ $(TOUCH) $(MMS$TARGET)
932         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
933
934 $(INST_BOOT) : $(BOOTSTRAP)
935         @ $(RM_RF) $(INST_BOOT)
936         - $(CP) $(BOOTSTRAP) $(INST_BOOT)
937         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
938 ';
939 }
940 # --- Static Loading Sections ---
941
942 sub static_lib {
943     my($self) = @_;
944     unless (ref $self){
945         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
946         $self = $ExtUtils::MakeMaker::Parent[-1];
947     }
948     return '' unless $self->needs_linking();
949
950     return '
951 $(INST_STATIC) :
952         $(NOOP)
953 ' unless ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB});
954
955     my(@m);
956     push @m,'
957 # Rely on suffix rule for update action
958 $(OBJECT) : $(INST_ARCHAUTODIR).exists
959
960 $(INST_STATIC) : $(OBJECT) $(MYEXTLIB)
961 ';
962     # If this extension has it's own library (eg SDBM_File)
963     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
964     push(@m, '  $(CP) $(MYEXTLIB) $(MMS$TARGET)',"\n") if $self->{MYEXTLIB};
965
966     push(@m,'
967         If F$Search("$(MMS$TARGET)").eqs."" Then Library/Object/Create $(MMS$TARGET)
968         Library/Object/Replace $(MMS$TARGET) $(MMS$SOURCE_LIST)
969         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR)extralibs.ld\';print F qq[$(EXTRALIBS)\n];close F;"
970         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
971 ');
972     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
973     join('',@m);
974 }
975
976
977 sub installpm_x { # called by installpm perl file
978     my($self, $dist, $inst, $splitlib) = @_;
979     unless (ref $self){
980         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
981         $self = $ExtUtils::MakeMaker::Parent[-1];
982     }
983     warn "Warning: Most probably 'make' will have problems processing this file: $inst\n"
984         if $inst =~ m!#!;
985     $inst = $self->fixpath($inst);
986     $dist = $self->fixpath($dist);
987     my($instdir) = $inst =~ /([^\)]+\))[^\)]*$/ ? $1 : dirname($inst);
988     my(@m);
989
990     push(@m, "
991 $inst : $dist \$(MAKEFILE) ${instdir}.exists
992 ",'     @ $(RM_F) $(MMS$TARGET)
993         @ $(CP) ',"$dist $inst",'
994         $(CHMOD) 644 $(MMS$TARGET)
995         @ $(PERL) -e "open F,\'>>$(INST_ARCHAUTODIR).packlist\';print F qq[$(MMS$TARGET)\n];close F;"
996 ');
997     push(@m, '  $(AUTOSPLITFILE) $(MMS$TARGET) ',
998               $self->catdir($splitlib,'auto')."\n\n")
999         if ($splitlib and $inst =~ /\.pm$/);
1000     push(@m,$self->dir_target($instdir));
1001
1002     join('',@m);
1003 }
1004
1005
1006 sub manifypods {
1007     my($self, %attribs) = @_;
1008     unless (ref $self){
1009         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1010         $self = $ExtUtils::MakeMaker::Parent[-1];
1011     }
1012     return "\nmanifypods :\n\t\$(NOOP)\n" unless %{$self->{MAN3PODS}};
1013     my($dist);
1014     my($pod2man_exe,$found_pod2man);
1015     if (defined $self->{PERL_SRC}) {
1016         $pod2man_exe = $self->catfile($self->{PERL_SRC},'pod','pod2man');
1017     } else {
1018         $pod2man_exe = $self->catfile($Config{bin},'pod2man');
1019     }
1020     if ($pod2man_exe = $self->perl_script($pod2man_exe)) { $found_pod2man = 1; }
1021     else {
1022         # No pod2man but some MAN3PODS to be installed
1023         print <<END;
1024
1025 Warning: I could not locate your pod2man program.  As a last choice,
1026          I will look for the file to which the logical name POD2MAN
1027          points when MMK is invoked.
1028
1029 END
1030         $pod2man_exe = "pod2man";
1031     }
1032     my(@m);
1033     push @m,
1034 qq[POD2MAN_EXE = $pod2man_exe\n],
1035 q[POD2MAN = $(PERL) -we "%m=@ARGV;for (keys %m){" -
1036 -e "system(""$(PERL) $(POD2MAN_EXE) $_ >$m{$_}"");}"
1037 ];
1038     push @m, "\nmanifypods : ";
1039     push @m, join " ", keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}};
1040     push(@m,"\n");
1041     if (%{$self->{MAN1PODS}} || %{$self->{MAN3PODS}}) {
1042         my($pod);
1043         foreach $pod (sort keys %{$self->{MAN1PODS}}) {
1044             push @m, qq[\t\@- If F\$Search("\$(POD2MAN_EXE)").nes."" Then \$(POD2MAN) ];
1045             push @m, "$pod $self->{MAN1PODS}{$pod}\n";
1046         }
1047         foreach $pod (sort keys %{$self->{MAN3PODS}}) {
1048             push @m, qq[\t\@- If F\$Search("\$(POD2MAN_EXE)").nes."" Then \$(POD2MAN) ];
1049             push @m, "$pod $self->{MAN3PODS}{$pod}\n";
1050         }
1051     }
1052     join('', @m);
1053 }
1054
1055
1056 sub processPL {
1057     my($self) = @_;
1058     unless (ref $self){
1059         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1060         $self = $ExtUtils::MakeMaker::Parent[-1];
1061     }
1062     return "" unless $self->{PL_FILES};
1063     my(@m, $plfile);
1064     foreach $plfile (sort keys %{$self->{PL_FILES}}) {
1065         push @m, "
1066 all :: $self->{PL_FILES}->{$plfile}
1067         \$(NOOP)
1068
1069 $self->{PL_FILES}->{$plfile} :: $plfile
1070 ",'     $(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" '," $plfile
1071 ";
1072     }
1073     join "", @m;
1074 }
1075
1076
1077 sub installbin {
1078     my($self) = @_;
1079     unless (ref $self){
1080         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1081         $self = $ExtUtils::MakeMaker::Parent[-1];
1082     }
1083     return '' unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
1084     return '' unless @{$self->{EXE_FILES}};
1085     my(@m, $from, $to, %fromto, @to, $line);
1086     for $from (@{$self->{EXE_FILES}}) {
1087         my($path) = '$(INST_EXE)' . basename($from);
1088         local($_) = $path;  # backward compatibility
1089         $to = $self->exescan($path);
1090         print "exescan($from) => '$to'\n" if ($Verbose >=2);
1091         $fromto{$from}=$to;
1092     }
1093     @to   = values %fromto;
1094     push @m, "
1095 EXE_FILES = @{$self->{EXE_FILES}}
1096
1097 all :: @to
1098         \$(NOOP)
1099
1100 realclean ::
1101 ";
1102     $line = '';  #avoid unitialized var warning
1103     foreach $to (@to) {
1104         if (length($line) + length($to) > 80) {
1105             push @m, "\t\$(RM_F) $line\n";
1106             $line = $to;
1107         }
1108         else { $line .= " $to"; }
1109     }
1110     push @m, "\t\$(RM_F) $line\n\n";
1111
1112     while (($from,$to) = each %fromto) {
1113         my $todir;
1114         if ($to =~ m#[/>:\]]#) { $todir = dirname($to); }
1115         else                   { ($todir = $to) =~ s/[^\)]+$//; }
1116         $todir = $self->fixpath($todir,1);
1117         push @m, "
1118 $to : $from \$(MAKEFILE) ${todir}.exists
1119         \$(CP) $from $to
1120
1121 ", $self->dir_target($todir);
1122     }
1123     join "", @m;
1124 }
1125
1126
1127 # --- Sub-directory Sections ---
1128
1129 sub pasthru {
1130     my($self) = @_;
1131     unless (ref $self){
1132         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1133         $self = $ExtUtils::MakeMaker::Parent[-1];
1134     }
1135     my(@m,$key);
1136     my(@pasthru);
1137
1138     foreach $key (qw(INSTALLPRIVLIB INSTALLARCHLIB INSTALLBIN 
1139                      INSTALLMAN1DIR INSTALLMAN3DIR LIBPERL_A LINKTYPE)){
1140         push @pasthru, "$key=\"$self->{$key}\"";
1141     }
1142
1143     push @m, "\nPASTHRU = \\\n ", join (",\\\n ", @pasthru), "\n";
1144     join "", @m;
1145 }
1146
1147
1148 sub subdir_x {
1149     my($self, $subdir) = @_;
1150     unless (ref $self){
1151         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1152         $self = $ExtUtils::MakeMaker::Parent[-1];
1153     }
1154     my(@m,$key);
1155     $subdir = $self->fixpath($subdir,1);
1156     push @m, '
1157
1158 subdirs ::
1159         olddef = F$Environment("Default")
1160         Set Default ',$subdir,'
1161         - $(MMS) all $(USEMACROS)$(PASTHRU)$(MACROEND)
1162         Set Default \'olddef\'
1163 ';
1164     join('',@m);
1165 }
1166
1167
1168 # --- Cleanup and Distribution Sections ---
1169
1170 sub clean {
1171     my($self, %attribs) = @_;
1172     unless (ref $self){
1173         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1174         $self = $ExtUtils::MakeMaker::Parent[-1];
1175     }
1176     my(@m,$dir);
1177     push @m, '
1178 # Delete temporary files but do not touch installed files. We don\'t delete
1179 # the Descrip.MMS here so that a later make realclean still has it to use.
1180 clean ::
1181 ';
1182     foreach $dir (@{$self->{DIR}}) { # clean subdirectories first
1183         my($vmsdir) = $self->fixpath($dir,1);
1184         push( @m, '     If F$Search("'.$vmsdir.'$(MAKEFILE)") Then \\',"\n\t",
1185               '$(PERL) -e "chdir ',"'$vmsdir'",'; print `$(MMS) clean`;"',"\n");
1186     }
1187     push @m, '  $(RM_F) *.Map *.lis *.cpp *$(OBJ_EXT) *$(LIB_EXT) *.Opt $(BOOTSTRAP) $(BASEEXT).bso
1188 ';
1189
1190     my(@otherfiles) = values %{$self->{XS}}; # .c files from *.xs files
1191     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1192     push(@otherfiles, 'blib.dir', 'Makeaperl.MMS', 'extralibs.ld', 'perlmain.c');
1193     push(@otherfiles,$self->catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
1194     my($file,$line);
1195     $line = '';  #avoid unitialized var warning
1196     foreach $file (@otherfiles) {
1197         $file = $self->fixpath($file);
1198         if (length($line) + length($file) > 80) {
1199             push @m, "\t\$(RM_RF) $line\n";
1200             $line = "$file";
1201         }
1202         else { $line .= " $file"; }
1203     }
1204     push @m, "\t\$(RM_RF) $line\n\n";
1205     push(@m, "  $attribs{POSTOP}\n") if $attribs{POSTOP};
1206     join('', @m);
1207 }
1208
1209
1210 sub realclean {
1211     my($self, %attribs) = @_;
1212     unless (ref $self){
1213         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1214         $self = $ExtUtils::MakeMaker::Parent[-1];
1215     }
1216     my(@m);
1217     push(@m,'
1218 # Delete temporary files (via clean) and also delete installed files
1219 realclean :: clean
1220 ');
1221     foreach(@{$self->{DIR}}){
1222         my($vmsdir) = $self->fixpath($_,1);
1223         push(@m, '      If F$Search("'."$vmsdir".'$(MAKEFILE)").nes."" Then \\',"\n\t",
1224               '$(PERL) -e "chdir ',"'$vmsdir'",'; print `$(MMS) realclean`;"',"\n");
1225     }
1226     push @m,'   $(RM_RF) $(INST_AUTODIR) $(INST_ARCHAUTODIR)
1227 ';
1228     # We can't expand several of the MMS macros here, since they don't have
1229     # corresponding %$self keys (i.e. they're defined in Descrip.MMS as a
1230     # combination of macros).  In order to stay below DCL's 255 char limit,
1231     # we put only 2 on a line.
1232     my($file,$line,$fcnt);
1233     my(@files) = qw{ *.Opt $(INST_DYNAMIC) $(INST_STATIC) $(INST_BOOT) $(INST_PM) $(OBJECT) $(MAKEFILE) $(MAKEFILE)_old };
1234     $line = '';  #avoid unitialized var warning
1235     foreach $file (@files) {
1236         $file = $self->fixpath($file);
1237         if (length($line) + length($file) > 80 || ++$fcnt >= 2) {
1238             push @m, "\t\$(RM_F) $line\n";
1239             $line = "$file";
1240             $fcnt = 0;
1241         }
1242         else { $line .= " $file"; }
1243     }
1244     push @m, "\t\$(RM_F) $line\n";
1245     if ($attribs{FILES} && ref $attribs{FILES} eq 'ARRAY') {
1246         $line = '';
1247         foreach $file (@{$attribs{'FILES'}}) {
1248             $file = $self->fixpath($file);
1249             if (length($line) + length($file) > 80) {
1250                 push @m, "\t\$(RM_RF) $line\n";
1251                 $line = "$file";
1252             }
1253             else { $line .= " $file"; }
1254         }
1255         push @m, "\t\$(RM_RF) $line\n";
1256     }
1257     push(@m, "  $attribs{POSTOP}\n")                     if $attribs{POSTOP};
1258     join('', @m);
1259 }
1260
1261
1262 sub dist_basics {
1263     my($self) = @_;
1264     unless (ref $self){
1265         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1266         $self = $ExtUtils::MakeMaker::Parent[-1];
1267     }
1268 '
1269 distclean :: realclean distcheck
1270         $(NOOP)
1271
1272 distcheck :
1273         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::Manifest \'&fullcheck\'; fullcheck()"
1274
1275 skipcheck :
1276         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::Manifest \'&fullcheck\'; skipcheck()"
1277
1278 manifest :
1279         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::Manifest \'&mkmanifest\'; mkmanifest()"
1280 ';
1281 }
1282
1283
1284 sub dist_core {
1285     my($self) = @_;
1286     unless (ref $self){
1287         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1288         $self = $ExtUtils::MakeMaker::Parent[-1];
1289     }
1290 '
1291 dist : $(DIST_DEFAULT)
1292         $(NOOP)
1293
1294 zipdist : $(DISTVNAME).zip$(SUFFIX)
1295         $(NOOP)
1296
1297 $(DISTVNAME).zip$(SUFFIX) : distdir
1298         $(PREOP)
1299         $(ZIP) "$(ZIPFLAGS)" $(MMS$TARGET) $(SRC)
1300         $(RM_RF) $(DISTVNAME)
1301         $(POSTOP)
1302
1303 shdist : distdir
1304         $(PREOP)
1305         $(SHARE) $(SRC) $(DISTVNAME).share$(SUFFIX)
1306         $(RM_RF) $(DISTVNAME)
1307         $(POSTOP)
1308 ';
1309 }
1310
1311
1312 sub dist_dir {
1313     my($self) = @_;
1314     unless (ref $self){
1315         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1316         $self = $ExtUtils::MakeMaker::Parent[-1];
1317     }
1318 q{
1319 distdir :
1320         $(RM_RF) $(DISTVNAME)
1321         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e "use ExtUtils::Manifest '/mani/';" \\
1322         -e "manicopy(maniread(),'$(DISTVNAME)','$(DIST_CP)');"
1323 };
1324 }
1325
1326
1327 sub dist_test {
1328     my($self) = @_;
1329     unless (ref $self){
1330         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1331         $self = $ExtUtils::MakeMaker::Parent[-1];
1332     }
1333 q{
1334 disttest : distdir
1335         startdir = F$Environment("Default")
1336         Set Default [.$(DISTVNAME)]
1337         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" Makefile.PL
1338         $(MMS)
1339         $(MMS) test
1340         Set Default 'startdir'
1341 };
1342 }
1343
1344 sub dist_ci {
1345     my($self) = @_;
1346     unless (ref $self){
1347         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1348         $self = $ExtUtils::MakeMaker::Parent[-1];
1349     }
1350 '';
1351 }
1352
1353
1354 # --- Test and Installation Sections ---
1355
1356
1357
1358 sub install {
1359     my($self, %attribs) = @_;
1360     unless (ref $self){
1361         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1362         $self = $ExtUtils::MakeMaker::Parent[-1];
1363     }
1364     my(@m);
1365     push @m, q{
1366 doc_install ::
1367         @ Write Sys$Output "Appending installation info to $(INST_ARCHLIB)perllocal.pod"
1368         @ $(PERL) "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)"  \\
1369                 -e "use ExtUtils::MakeMaker; MY->new({})->writedoc('Module', '$(NAME)', \\
1370                 'LINKTYPE=$(LINKTYPE)', 'VERSION=$(VERSION)', 'EXE_FILES=$(EXE_FILES)')" \\
1371                 >>$(INSTALLARCHLIB)perllocal.pod
1372 };
1373
1374     push(@m, "
1375 install :: pure_install doc_install
1376         \$(NOOP)
1377
1378 # Interim solution for VMS; assumes directory tree of same structure under
1379 # both \$(INST_LIB) and \$(INSTALLPRIVLIB).  This operation will be assumed
1380 # into MakeMaker in a (near) future version.
1381 pure_install :: all
1382 ");
1383 #    # install subdirectories first
1384 #    foreach(@{$self->{DIR}}){
1385 #      my($vmsdir) = $self->fixpath($_,1);
1386 #      push(@m, '       If F$Search("',$vmsdir,'$(MAKEFILE)").nes."" Then $(PERL) -e "chdir ',"'$vmsdir'",
1387 #           '; print `$(MMS) install`"'."\n");
1388 #    }
1389 #
1390 #    push(@m, ' @ $(PERL) "-I$(PERL_LIB)" -e "use File::Path; mkpath(\@ARGV)" $(INSTALLPRIVLIB) $(INSTALLARCHLIB)
1391 #       @ $(PERL) -e "die qq{You do not have permissions to install into $ARGV[0]\n} unless -w VMS::Filespec::fileify($ARGV[0])" $(INSTALLPRIVLIB)
1392 #       @ $(PERL) -e "die qq{You do not have permissions to install into $ARGV[0]\n} unless -w VMS::Filespec::fileify($ARGV[0])" $(INSTALLARCHLIB)',"
1393 #       # Can't install manpages here -- INST_MAN%DIR macros make line >255 chars
1394 #       \$(MMS) \$(USEMACROS)INST_LIB=$self->{INSTALLPRIVLIB},INST_ARCHLIB=$self->{INSTALLARCHLIB},INST_EXE=$self->{INSTALLBIN}\$(MACROEND)",'
1395 #       @ $(PERL) -i_bak -lne "print unless $seen{$_}++" $(INST_ARCHAUTODIR).packlist
1396 #');
1397
1398     my($curtop,$insttop);
1399     ($curtop = $self->fixpath($self->{INST_LIB},1)) =~ s/]$//;
1400     ($insttop = $self->fixpath($self->{INSTALLPRIVLIB},1)) =~ s/]$//;
1401     push(@m,"   Backup/Log ${curtop}...]*.*; ${insttop}...]/New_Version/By_Owner=Parent\n");
1402
1403     push @m, '
1404 ##### UNINSTALL IS STILL EXPERIMENTAL ####
1405 uninstall ::
1406 ';
1407     foreach(@{$self->{DIR}}){
1408       my($vmsdir) = $self->fixpath($_,1);
1409       push(@m, '        If F$Search("',$vmsdir,'$(MAKEFILE)").nes."" Then $(PERL) -e "chdir ',"'$vmsdir'",
1410            '; print `$(MMS) uninstall`"'."\n");
1411     }
1412     push @m, "\t".'$(PERL) -le "use File::Path; foreach (<>) {s/',"$curtop/$insttop/;",'rmtree($_,1,0);}" <$(INST_ARCHAUTODIR).packlist
1413 ';
1414
1415     join("",@m);
1416 }
1417
1418
1419 sub perldepend {
1420     my($self) = @_;
1421     unless (ref $self){
1422         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1423         $self = $ExtUtils::MakeMaker::Parent[-1];
1424     }
1425     my(@m);
1426
1427     push @m, '
1428 $(OBJECT) : $(PERL_INC)EXTERN.h, $(PERL_INC)INTERN.h, $(PERL_INC)XSUB.h, $(PERL_INC)av.h
1429 $(OBJECT) : $(PERL_INC)cop.h, $(PERL_INC)cv.h, $(PERL_INC)embed.h, $(PERL_INC)form.h
1430 $(OBJECT) : $(PERL_INC)gv.h, $(PERL_INC)handy.h, $(PERL_INC)hv.h, $(PERL_INC)keywords.h
1431 $(OBJECT) : $(PERL_INC)mg.h, $(PERL_INC)op.h, $(PERL_INC)opcode.h, $(PERL_INC)patchlevel.h
1432 $(OBJECT) : $(PERL_INC)perl.h, $(PERL_INC)perly.h, $(PERL_INC)pp.h, $(PERL_INC)proto.h
1433 $(OBJECT) : $(PERL_INC)regcomp.h, $(PERL_INC)regexp.h, $(PERL_INC)scope.h, $(PERL_INC)sv.h
1434 $(OBJECT) : $(PERL_INC)vmsish.h, $(PERL_INC)util.h, $(PERL_INC)config.h
1435
1436 ' if $self->{OBJECT}; 
1437
1438     push(@m,'
1439 # Check for unpropagated config.sh changes. Should never happen.
1440 # We do NOT just update config.h because that is not sufficient.
1441 # An out of date config.h is not fatal but complains loudly!
1442 #$(PERL_INC)config.h : $(PERL_SRC)config.sh
1443 $(PERL_INC)config.h : $(PERL_VMS)config.vms
1444         @ Write Sys$Error "Warning: $(PERL_INC)config.h out of date with $(PERL_VMS)config.vms"
1445
1446 #$(PERL_ARCHLIB)Config.pm : $(PERL_SRC)config.sh
1447 $(PERL_ARCHLIB)Config.pm : $(PERL_VMS)config.vms $(PERL_VMS)genconfig.pl
1448         @ Write Sys$Error "$(PERL_ARCHLIB)Config.pm may be out of date with config.vms or genconfig.pl"
1449         olddef = F$Environment("Default")
1450         Set Default $(PERL_SRC)
1451         $(MMS) $(USEMAKEFILE)[.VMS]$(MAKEFILE) [.lib.',$Config{'arch'},']config.pm
1452         Set Default \'olddef\'
1453 ') if $self->{PERL_SRC};
1454
1455     push(@m, join(" ", map($self->fixpath($_),values %{$self->{XS}}))." : \$(XSUBPPDEPS)\n")
1456       if %{$self->{XS}};
1457
1458     join('',@m);
1459 }
1460
1461 sub makefile {
1462     my($self) = @_;
1463     unless (ref $self){
1464         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1465         $self = $ExtUtils::MakeMaker::Parent[-1];
1466     }
1467     my(@m,@cmd);
1468     # We do not know what target was originally specified so we
1469     # must force a manual rerun to be sure. But as it should only
1470     # happen very rarely it is not a significant problem.
1471     push @m, '
1472 $(OBJECT) : $(FIRST_MAKEFILE)
1473 ' if $self->{OBJECT};
1474
1475     push @m,'
1476 # We take a very conservative approach here, but it\'s worth it.
1477 # We move $(MAKEFILE) to $(MAKEFILE)_old here to avoid gnu make looping.
1478 $(MAKEFILE) : Makefile.PL $(CONFIGDEP)
1479         @ Write Sys$Output "$(MAKEFILE) out-of-date with respect to $(MMS$SOURCE_LIST)"
1480         @ Write Sys$Output "Cleaning current config before rebuilding $(MAKEFILE) ..."
1481         - $(MV) $(MAKEFILE) $(MAKEFILE)_old
1482         - $(MMS) $(USEMAKEFILE)$(MAKEFILE)_old clean
1483         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" Makefile.PL ',join(' ',@ARGV),'
1484         @ Write Sys$Output "$(MAKEFILE) has been rebuilt."
1485         @ Write Sys$Output "Please run $(MMS) to build the extension."
1486 ';
1487
1488     join('',@m);
1489 }
1490
1491
1492 sub test {
1493     my($self, %attribs) = @_;
1494     unless (ref $self){
1495         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1496         $self = $ExtUtils::MakeMaker::Parent[-1];
1497     }
1498     my($tests) = $attribs{TESTS} || ( -d 't' ? 't/*.t' : '');
1499     my(@m);
1500     push @m,"
1501 TEST_VERBOSE = 0
1502 TEST_TYPE=test_\$(LINKTYPE)
1503
1504 test : \$(TEST_TYPE)
1505         \$(NOOP)
1506 ";
1507     foreach(@{$self->{DIR}}){
1508       my($vmsdir) = $self->fixpath($_,1);
1509       push(@m, '        If F$Search("',$vmsdir,'$(MAKEFILE)").nes."" Then $(PERL) -e "chdir ',"'$vmsdir'",
1510            '; print `$(MMS) $(PASTHRU2) test`'."\n");
1511     }
1512     push(@m, "\t\@ Write Sys\$Output 'No tests defined for \$(NAME) extension.'\n")
1513         unless $tests or -f "test.pl" or @{$self->{DIR}};
1514     push(@m, "\n");
1515
1516     push(@m, "test_dynamic :: all\n");
1517     push(@m, $self->test_via_harness('$(FULLPERL)', $tests)) if $tests;
1518     push(@m, $self->test_via_script('$(FULLPERL)', 'test.pl')) if -f "test.pl";
1519     push(@m, "\n");
1520
1521     # Occasionally we may face this degenerate target:
1522     push @m, "test_ : test_dynamic\n\n";
1523  
1524         if ($self->needs_linking()) {
1525         push(@m, "test_static :: all \$(MAP_TARGET)\n");
1526         push(@m, $self->test_via_harness('$(MAP_TARGET)', $tests)) if $tests;
1527         push(@m, $self->test_via_script('$(MAP_TARGET)', 'test.pl')) if -f "test.pl";
1528         push(@m, "\n");
1529     }
1530     else {
1531         push @m, "test_static :: test_dynamic\n";
1532     }
1533
1534     join('',@m);
1535 }
1536
1537
1538 sub test_via_harness {
1539     my($self,$perl,$tests) = @_;
1540     unless (ref $self){
1541         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1542         $self = $ExtUtils::MakeMaker::Parent[-1];
1543     }
1544     "   $perl".' "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)" \\'."\n\t".
1545     '-e "use Test::Harness qw(&runtests $verbose); $verbose=$(TEST_VERBOSE); runtests @ARGV;" \\'."\n\t$tests\n";
1546 }
1547
1548
1549 sub test_via_script {
1550     my($self,$perl,$script) = @_;
1551     unless (ref $self){
1552         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1553         $self = $ExtUtils::MakeMaker::Parent[-1];
1554     }
1555     "   $perl".' "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" test.pl
1556 ';
1557 }
1558
1559
1560 sub makeaperl {
1561     my($self, %attribs) = @_;
1562     unless (ref $self){
1563         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1564         $self = $ExtUtils::MakeMaker::Parent[-1];
1565     }
1566     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) = 
1567       @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
1568     my(@m);
1569     push @m, "
1570 # --- MakeMaker makeaperl section ---
1571 MAP_TARGET    = $target
1572 FULLPERL      = $self->{FULLPERL}
1573 ";
1574     return join '', @m if $self->{PARENT};
1575
1576     my($dir) = join ":", @{$self->{DIR}};
1577
1578     unless ($self->{MAKEAPERL}) {
1579         push @m, q{
1580 $(MAP_TARGET) :: $(MAKE_APERL_FILE)
1581         $(MMS)$(USEMAKEFILE)$(MAKE_APERL_FILE) static $(MMS$TARGET)
1582
1583 $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE)
1584         @ Write Sys$Output "Writing ""$(MMS$TARGET)"" for this $(MAP_TARGET)"
1585         @ $(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" \
1586                 Makefile.PL DIR=}, $dir, q{ \
1587                 MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
1588                 MAKEAPERL=1 NORECURS=1};
1589
1590         push @m, map( " \\\n\t\t$_", @ARGV );
1591         push @m, "\n";
1592
1593         return join '', @m;
1594     }
1595
1596
1597     my($linkcmd,@staticopts,@staticpkgs,$extralist,$target,$targdir,$libperldir);
1598
1599     # The front matter of the linkcommand...
1600     $linkcmd = join ' ', $Config{'ld'},
1601             grep($_, @Config{qw(large split ldflags ccdlflags)});
1602     $linkcmd =~ s/\s+/ /g;
1603
1604     # Which *.olb files could we make use of...
1605     local(%olbs);
1606     $olbs{$self->{INST_ARCHAUTODIR}} = "$self->{BASEEXT}\$(LIB_EXT)";
1607     File::Find::find(sub {
1608         return unless m/\Q$self->{LIB_EXT}\E$/;
1609         return if m/^libperl/;
1610         $olbs{$ENV{DEFAULT}} = $_;
1611     }, grep( -d $_, @{$searchdirs || []}));
1612
1613     # We trust that what has been handed in as argument will be buildable
1614     $static = [] unless $static;
1615     @olbs{@{$static}} = (1) x @{$static};
1616  
1617     $extra = [] unless $extra && ref $extra eq 'ARRAY';
1618     # Sort the object libraries in inverse order of
1619     # filespec length to try to insure that dependent extensions
1620     # will appear before their parents, so the linker will
1621     # search the parent library to resolve references.
1622     # (e.g. Intuit::DWIM will precede Intuit, so unresolved
1623     # references from [.intuit.dwim]dwim.obj can be found
1624     # in [.intuit]intuit.olb).
1625     for (sort keys %olbs) {
1626         next unless $olbs{$_} =~ /\Q$self->{LIB_EXT}\E$/;
1627         my($dir) = $self->fixpath($_,1);
1628         my($extralibs) = $dir . "extralibs.ld";
1629         my($extopt) = $dir . $olbs{$_};
1630         $extopt =~ s/$self->{LIB_EXT}$/.opt/;
1631         if (-f $extralibs ) {
1632             open LIST,$extralibs or warn $!,next;
1633             push @$extra, <LIST>;
1634             close LIST;
1635         }
1636         if (-f $extopt) {
1637             open OPT,$extopt or die $!;
1638             while (<OPT>) {
1639                 next unless /(?:UNIVERSAL|VECTOR)=boot_([\w_]+)/;
1640                 # ExtUtils::Miniperl expects Unix paths
1641                 (my($pkg) = "$1_$1$self->{LIB_EXT}") =~ s#_*#/#g;
1642                 push @staticpkgs,$pkg;
1643             }
1644             push @staticopts, $extopt;
1645         }
1646     }
1647
1648     $target = "Perl.Exe" unless $target;
1649     ($shrtarget,$targdir) = fileparse($target);
1650     $shrtarget =~ s/^([^.]*)/$1Shr/;
1651     $shrtarget = $targdir . $shrtarget;
1652     $target = "Perlshr.$Config{'dlext'}" unless $target;
1653     $tmp = "[]" unless $tmp;
1654     $tmp = $self->fixpath($tmp,1);
1655     if (@$extra) {
1656         $extralist = join(' ',@$extra);
1657         $extralist =~ s/[,\s\n]+/, /g;
1658     }
1659     else { $extralist = ''; }
1660     if ($libperl) {
1661         unless (-f $libperl || -f ($libperl = $self->catfile($Config{'installarchlib'},'CORE',$libperl))) {
1662             print STDOUT "Warning: $libperl not found\n";
1663             undef $libperl;
1664         }
1665     }
1666     unless ($libperl) {
1667         if (defined $self->{PERL_SRC}) {
1668             $libperl = $self->catfile($self->{PERL_SRC},"libperl$self->{LIB_EXT}");
1669         } elsif (-f ($libperl = $self->catfile($Config{'installarchlib'},'CORE',"libperl$self->{LIB_EXT}")) ) {
1670         } else {
1671             print STDOUT "Warning: $libperl not found
1672     If you're going to build a static perl binary, make sure perl is installed
1673     otherwise ignore this warning\n";
1674         }
1675     }
1676     $libperldir = $self->fixpath((fileparse($libperl))[1],1);
1677
1678     push @m, '
1679 # Fill in the target you want to produce if it\'s not perl
1680 MAP_TARGET    = ',$self->fixpath($target),'
1681 MAP_SHRTARGET = ',$self->fixpath($shrtarget),"
1682 MAP_LINKCMD   = $linkcmd
1683 MAP_PERLINC   = ", $perlinc ? map('"$_" ',@{$perlinc}) : '','
1684 # We use the linker options files created with each extension, rather than
1685 #specifying the object files directly on the command line.
1686 MAP_STATIC    = ',@staticopts ? join(' ', @staticopts) : '','
1687 MAP_OPTS    = ',@staticopts ? ','.join(',', map($_.'/Option', @staticopts)) : '',"
1688 MAP_EXTRA     = $extralist
1689 MAP_LIBPERL = ",$self->fixpath($libperl),'
1690 ';
1691
1692
1693     push @m,'
1694 $(MAP_SHRTARGET) : $(MAP_LIBPERL) $(MAP_STATIC) ',"${libperldir}Perlshr_Attr.Opt",'
1695         $(MAP_LINKCMD)/Shareable=$(MMS$TARGET) $(MAP_OPTS), $(MAP_EXTRA), $(MAP_LIBPERL) ',"${libperldir}Perlshr_Attr.Opt",'
1696 $(MAP_TARGET) : $(MAP_SHRTARGET) ',"${tmp}perlmain\$(OBJ_EXT) ${tmp}PerlShr.Opt",'
1697         $(MAP_LINKCMD) ',"${tmp}perlmain\$(OBJ_EXT)",', PerlShr.Opt/Option
1698         @ Write Sys$Output "To install the new ""$(MAP_TARGET)"" binary, say"
1699         @ Write Sys$Output "    $(MMS)$(USEMAKEFILE)$(MAKEFILE) inst_perl $(USEMACROS)MAP_TARGET=$(MAP_TARGET)$(ENDMACRO)"
1700         @ Write Sys$Output "To remove the intermediate files, say
1701         @ Write Sys$Output "    $(MMS)$(USEMAKEFILE)$(MAKEFILE) map_clean"
1702 ';
1703     push @m,'
1704 ',"${tmp}perlmain.c",' : $(MAKEFILE)
1705         @ $(PERL) $(MAP_PERLINC) -e "use ExtUtils::Miniperl; writemain(qw|',@staticpkgs,'|)" >$(MMS$TARGET)
1706 ';
1707
1708     push @m, q{
1709 doc_inst_perl :
1710         @ $(PERL) -e "use ExtUtils::MakeMaker; MY->new()->writedoc('Perl binary','$(MAP_TARGET)','MAP_STATIC=$(MAP_STATIC)','MAP_EXTRA=$(MAP_EXTRA)','MAP_LIBPERL=$(MAP_LIBPERL)')"
1711 };
1712
1713     push @m, "
1714 inst_perl : pure_inst_perl doc_inst_perl
1715         \$(NOOP)
1716
1717 pure_inst_perl : \$(MAP_TARGET)
1718         $self->{CP} \$(MAP_SHRTARGET) ",$self->fixpath($Config{'installbin'},1),"
1719         $self->{CP} \$(MAP_TARGET) ",$self->fixpath($Config{'installbin'},1),"
1720
1721 clean :: map_clean
1722         \$(NOOP)
1723
1724 map_clean :
1725         \$(RM_F) ${tmp}perlmain\$(OBJ_EXT) ${tmp}perlmain.c \$(MAKEFILE)
1726         \$(RM_F) ${tmp}PerlShr.Opt \$(MAP_TARGET)
1727 ";
1728
1729     join '', @m;
1730 }
1731   
1732 sub extliblist {
1733     my($self) = @_;
1734     unless (ref $self){
1735         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1736         $self = $ExtUtils::MakeMaker::Parent[-1];
1737     }
1738     '','','';
1739 }
1740
1741
1742 sub mksymlists {
1743     my($self,%attribs) = @_;
1744     unless (ref $self){
1745         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1746         $self = $ExtUtils::MakeMaker::Parent[-1];
1747     }
1748
1749     my($vars) = $attribs{DL_VARS} || $self->{DL_VARS} || [];
1750     my($procs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS};
1751     my($package,$packprefix,$sym,$optname);
1752     local(*OPT);
1753
1754     if (!$procs) {
1755         $package = $self->{NAME};
1756         $package =~ s/\W/_/g;
1757         $procs = { $package => ["boot_$package"] };
1758     }
1759     my($isvax) = $Config{'arch'} =~ /VAX/i;
1760
1761     # Options file declaring universal symbols
1762     # Used when linking shareable image for dynamic extension,
1763     # or when linking PerlShr into which we've added this package
1764     # as a static extension
1765     # We don't do anything to preserve order, so we won't relax
1766     # the GSMATCH criteria for a dynamic extension
1767
1768     # BASEEXT is not available when mksymlists is run, so we
1769     # create the options file name directly from NAME
1770     # May cause trouble if Makefile.PL author specifies NAME
1771     # and BASEEXT directly as unrelated strings.
1772     ($optname = $self->{NAME}) =~ s/.*:://;
1773     open OPT, ">$optname.opt";
1774     foreach $package (keys %$procs) {
1775         ($packprefix = $package) =~ s/\W/_/g;
1776         foreach $sym (@{$$procs{$package}}) {
1777             $sym = "XS_${packprefix}_$sym" unless $sym =~ /^boot_/;
1778             if ($isvax) { print OPT "UNIVERSAL=$sym\n" }
1779             else        { print OPT "SYMBOL_VECTOR=($sym=PROCEDURE)\n"; }
1780         }
1781     }
1782     foreach $sym (@$vars) {
1783         print OPT "PSECT_ATTR=${sym},PIC,OVR,RD,NOEXE,WRT,NOSHR\n";
1784         if ($isvax) { print OPT "UNIVERSAL=$sym\n" }
1785         else        { print OPT "SYMBOL_VECTOR=($sym=DATA)\n"; }
1786     }
1787     close OPT;
1788
1789     # Options file specifying RTLs to which this extension must be linked.
1790     # Eventually, the list of libraries will be supplied by a working
1791     # extliblist routine.
1792     open OPT,'>rtls.opt';
1793     print OPT "PerlShr/Share\n";
1794     foreach $rtl (split(/\s+/,$Config{'libs'})) { print OPT "$rtl\n"; }
1795     close OPT;
1796 }
1797
1798
1799 # --- Make-Directories section (internal method) ---
1800 # dir_target(@array) returns a Makefile entry for the file .exists in each
1801 # named directory. Returns nothing, if the entry has already been processed.
1802 # We're helpless though, if the same directory comes as $(FOO) _and_ as "bar".
1803 # Both of them get an entry, that's why we use "::". I chose '$(PERL)' as the 
1804 # prerequisite, because there has to be one, something that doesn't change 
1805 # too often :)
1806
1807 sub dir_target {
1808     my($self,@dirs) = @_;
1809     unless (ref $self){
1810         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1811         $self = $ExtUtils::MakeMaker::Parent[-1];
1812     }
1813     my(@m,$dir);
1814     foreach $dir (@dirs) {
1815         next if $self->{DIR_TARGET}{$self}{$dir}++;
1816         my($vmsdir) = $self->fixpath($dir,1);
1817         push @m, "
1818 ${vmsdir}.exists :: \$(PERL_INC)perl.h
1819         \@ \$(MKPATH) $vmsdir
1820         \@ \$(TOUCH) ${vmsdir}.exists
1821 ";
1822     }
1823     join "", @m;
1824 }
1825
1826
1827 # --- Output postprocessing section ---
1828
1829 sub nicetext {
1830     # Insure that colons marking targets are preceded by space -
1831     # most Unix Makes don't need this, but it's necessary under VMS
1832     # to distinguish the target delimiter from a colon appearing as
1833     # part of a filespec.
1834
1835     my($self,$text) = @_;
1836     unless (ref $self){
1837         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1838         $self = $ExtUtils::MakeMaker::Parent[-1];
1839     }
1840     $text =~ s/([^\s:])(:+\s)/$1 $2/gs;
1841     $text;
1842 }
1843
1844 1;
1845
1846 __END__