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