Upgrade to ExtUtils-MakeMaker-6.50
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Unix.pm
1 package ExtUtils::MM_Unix;
2
3 require 5.006;
4
5 use strict;
6
7 use Carp;
8 use ExtUtils::MakeMaker::Config;
9 use File::Basename qw(basename dirname);
10 use DirHandle;
11
12 our %Config_Override;
13
14 use ExtUtils::MakeMaker qw($Verbose neatvalue);
15
16 # If we make $VERSION an our variable parse_version() breaks
17 use vars qw($VERSION);
18 $VERSION = '6.50';
19
20 require ExtUtils::MM_Any;
21 our @ISA = qw(ExtUtils::MM_Any);
22
23 my %Is;
24 BEGIN { 
25     $Is{OS2}     = $^O eq 'os2';
26     $Is{Win32}   = $^O eq 'MSWin32' || $Config{osname} eq 'NetWare';
27     $Is{Dos}     = $^O eq 'dos';
28     $Is{VMS}     = $^O eq 'VMS';
29     $Is{OSF}     = $^O eq 'dec_osf';
30     $Is{IRIX}    = $^O eq 'irix';
31     $Is{NetBSD}  = $^O eq 'netbsd';
32     $Is{Interix} = $^O eq 'interix';
33     $Is{SunOS4}  = $^O eq 'sunos';
34     $Is{Solaris} = $^O eq 'solaris';
35     $Is{SunOS}   = $Is{SunOS4} || $Is{Solaris};
36     $Is{BSD}     = ($^O =~ /^(?:free|net|open)bsd$/ or
37                    grep( $^O eq $_, qw(bsdos interix dragonfly) )
38                   );
39 }
40
41 BEGIN {
42     if( $Is{VMS} ) {
43         # For things like vmsify()
44         require VMS::Filespec;
45         VMS::Filespec->import;
46     }
47 }
48
49
50 =head1 NAME
51
52 ExtUtils::MM_Unix - methods used by ExtUtils::MakeMaker
53
54 =head1 SYNOPSIS
55
56 C<require ExtUtils::MM_Unix;>
57
58 =head1 DESCRIPTION
59
60 The methods provided by this package are designed to be used in
61 conjunction with ExtUtils::MakeMaker. When MakeMaker writes a
62 Makefile, it creates one or more objects that inherit their methods
63 from a package C<MM>. MM itself doesn't provide any methods, but it
64 ISA ExtUtils::MM_Unix class. The inheritance tree of MM lets operating
65 specific packages take the responsibility for all the methods provided
66 by MM_Unix. We are trying to reduce the number of the necessary
67 overrides by defining rather primitive operations within
68 ExtUtils::MM_Unix.
69
70 If you are going to write a platform specific MM package, please try
71 to limit the necessary overrides to primitive methods, and if it is not
72 possible to do so, let's work out how to achieve that gain.
73
74 If you are overriding any of these methods in your Makefile.PL (in the
75 MY class), please report that to the makemaker mailing list. We are
76 trying to minimize the necessary method overrides and switch to data
77 driven Makefile.PLs wherever possible. In the long run less methods
78 will be overridable via the MY class.
79
80 =head1 METHODS
81
82 The following description of methods is still under
83 development. Please refer to the code for not suitably documented
84 sections and complain loudly to the makemaker@perl.org mailing list.
85 Better yet, provide a patch.
86
87 Not all of the methods below are overridable in a
88 Makefile.PL. Overridable methods are marked as (o). All methods are
89 overridable by a platform specific MM_*.pm file.
90
91 Cross-platform methods are being moved into MM_Any.  If you can't find
92 something that used to be in here, look in MM_Any.
93
94 =cut
95
96 # So we don't have to keep calling the methods over and over again,
97 # we have these globals to cache the values.  Faster and shrtr.
98 my $Curdir  = __PACKAGE__->curdir;
99 my $Rootdir = __PACKAGE__->rootdir;
100 my $Updir   = __PACKAGE__->updir;
101
102
103 =head2 Methods
104
105 =over 4
106
107 =item os_flavor
108
109 Simply says that we're Unix.
110
111 =cut
112
113 sub os_flavor {
114     return('Unix');
115 }
116
117
118 =item c_o (o)
119
120 Defines the suffix rules to compile different flavors of C files to
121 object files.
122
123 =cut
124
125 sub c_o {
126 # --- Translation Sections ---
127
128     my($self) = shift;
129     return '' unless $self->needs_linking();
130     my(@m);
131     
132     my $command = '$(CCCMD)';
133     my $flags   = '$(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE)';
134     
135     if (my $cpp = $Config{cpprun}) {
136         my $cpp_cmd = $self->const_cccmd;
137         $cpp_cmd =~ s/^CCCMD\s*=\s*\$\(CC\)/$cpp/;
138         push @m, qq{
139 .c.i:
140         $cpp_cmd $flags \$*.c > \$*.i
141 };
142     }
143
144     push @m, qq{
145 .c.s:
146         $command -S $flags \$*.c
147
148 .c\$(OBJ_EXT):
149         $command $flags \$*.c
150
151 .cpp\$(OBJ_EXT):
152         $command $flags \$*.cpp
153
154 .cxx\$(OBJ_EXT):
155         $command $flags \$*.cxx
156
157 .cc\$(OBJ_EXT):
158         $command $flags \$*.cc
159 };
160
161     push @m, qq{
162 .C\$(OBJ_EXT):
163         $command \$*.C
164 } if !$Is{OS2} and !$Is{Win32} and !$Is{Dos}; #Case-specific
165
166     return join "", @m;
167 }
168
169 =item cflags (o)
170
171 Does very much the same as the cflags script in the perl
172 distribution. It doesn't return the whole compiler command line, but
173 initializes all of its parts. The const_cccmd method then actually
174 returns the definition of the CCCMD macro which uses these parts.
175
176 =cut
177
178 #'
179
180 sub cflags {
181     my($self,$libperl)=@_;
182     return $self->{CFLAGS} if $self->{CFLAGS};
183     return '' unless $self->needs_linking();
184
185     my($prog, $uc, $perltype, %cflags);
186     $libperl ||= $self->{LIBPERL_A} || "libperl$self->{LIB_EXT}" ;
187     $libperl =~ s/\.\$\(A\)$/$self->{LIB_EXT}/;
188
189     @cflags{qw(cc ccflags optimize shellflags)}
190         = @Config{qw(cc ccflags optimize shellflags)};
191     my($optdebug) = "";
192
193     $cflags{shellflags} ||= '';
194
195     my(%map) =  (
196                 D =>   '-DDEBUGGING',
197                 E =>   '-DEMBED',
198                 DE =>  '-DDEBUGGING -DEMBED',
199                 M =>   '-DEMBED -DMULTIPLICITY',
200                 DM =>  '-DDEBUGGING -DEMBED -DMULTIPLICITY',
201                 );
202
203     if ($libperl =~ /libperl(\w*)\Q$self->{LIB_EXT}/){
204         $uc = uc($1);
205     } else {
206         $uc = ""; # avoid warning
207     }
208     $perltype = $map{$uc} ? $map{$uc} : "";
209
210     if ($uc =~ /^D/) {
211         $optdebug = "-g";
212     }
213
214
215     my($name);
216     ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
217     if ($prog = $Config{$name}) {
218         # Expand hints for this extension via the shell
219         print STDOUT "Processing $name hint:\n" if $Verbose;
220         my(@o)=`cc=\"$cflags{cc}\"
221           ccflags=\"$cflags{ccflags}\"
222           optimize=\"$cflags{optimize}\"
223           perltype=\"$cflags{perltype}\"
224           optdebug=\"$cflags{optdebug}\"
225           eval '$prog'
226           echo cc=\$cc
227           echo ccflags=\$ccflags
228           echo optimize=\$optimize
229           echo perltype=\$perltype
230           echo optdebug=\$optdebug
231           `;
232         foreach my $line (@o){
233             chomp $line;
234             if ($line =~ /(.*?)=\s*(.*)\s*$/){
235                 $cflags{$1} = $2;
236                 print STDOUT "  $1 = $2\n" if $Verbose;
237             } else {
238                 print STDOUT "Unrecognised result from hint: '$line'\n";
239             }
240         }
241     }
242
243     if ($optdebug) {
244         $cflags{optimize} = $optdebug;
245     }
246
247     for (qw(ccflags optimize perltype)) {
248         $cflags{$_} ||= '';
249         $cflags{$_} =~ s/^\s+//;
250         $cflags{$_} =~ s/\s+/ /g;
251         $cflags{$_} =~ s/\s+$//;
252         $self->{uc $_} ||= $cflags{$_};
253     }
254
255     if ($self->{POLLUTE}) {
256         $self->{CCFLAGS} .= ' -DPERL_POLLUTE ';
257     }
258
259     my $pollute = '';
260     if ($Config{usemymalloc} and not $Config{bincompat5005}
261         and not $Config{ccflags} =~ /-DPERL_POLLUTE_MALLOC\b/
262         and $self->{PERL_MALLOC_OK}) {
263         $pollute = '$(PERL_MALLOC_DEF)';
264     }
265
266     $self->{CCFLAGS}  = quote_paren($self->{CCFLAGS});
267     $self->{OPTIMIZE} = quote_paren($self->{OPTIMIZE});
268
269     return $self->{CFLAGS} = qq{
270 CCFLAGS = $self->{CCFLAGS}
271 OPTIMIZE = $self->{OPTIMIZE}
272 PERLTYPE = $self->{PERLTYPE}
273 MPOLLUTE = $pollute
274 };
275
276 }
277
278
279 =item const_cccmd (o)
280
281 Returns the full compiler call for C programs and stores the
282 definition in CONST_CCCMD.
283
284 =cut
285
286 sub const_cccmd {
287     my($self,$libperl)=@_;
288     return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
289     return '' unless $self->needs_linking();
290     return $self->{CONST_CCCMD} =
291         q{CCCMD = $(CC) -c $(PASTHRU_INC) $(INC) \\
292         $(CCFLAGS) $(OPTIMIZE) \\
293         $(PERLTYPE) $(MPOLLUTE) $(DEFINE_VERSION) \\
294         $(XS_DEFINE_VERSION)};
295 }
296
297 =item const_config (o)
298
299 Defines a couple of constants in the Makefile that are imported from
300 %Config.
301
302 =cut
303
304 sub const_config {
305 # --- Constants Sections ---
306
307     my($self) = shift;
308     my @m = <<"END";
309
310 # These definitions are from config.sh (via $INC{'Config.pm'}).
311 # They may have been overridden via Makefile.PL or on the command line.
312 END
313
314     my(%once_only);
315     foreach my $key (@{$self->{CONFIG}}){
316         # SITE*EXP macros are defined in &constants; avoid duplicates here
317         next if $once_only{$key};
318         $self->{uc $key} = quote_paren($self->{uc $key});
319         push @m, uc($key) , ' = ' , $self->{uc $key}, "\n";
320         $once_only{$key} = 1;
321     }
322     join('', @m);
323 }
324
325 =item const_loadlibs (o)
326
327 Defines EXTRALIBS, LDLOADLIBS, BSLOADLIBS, LD_RUN_PATH. See
328 L<ExtUtils::Liblist> for details.
329
330 =cut
331
332 sub const_loadlibs {
333     my($self) = shift;
334     return "" unless $self->needs_linking;
335     my @m;
336     push @m, qq{
337 # $self->{NAME} might depend on some other libraries:
338 # See ExtUtils::Liblist for details
339 #
340 };
341     for my $tmp (qw/
342          EXTRALIBS LDLOADLIBS BSLOADLIBS
343          /) {
344         next unless defined $self->{$tmp};
345         push @m, "$tmp = $self->{$tmp}\n";
346     }
347     # don't set LD_RUN_PATH if empty
348     for my $tmp (qw/
349          LD_RUN_PATH
350          /) {
351         next unless $self->{$tmp};
352         push @m, "$tmp = $self->{$tmp}\n";
353     }
354     return join "", @m;
355 }
356
357 =item constants (o)
358
359   my $make_frag = $mm->constants;
360
361 Prints out macros for lots of constants.
362
363 =cut
364
365 sub constants {
366     my($self) = @_;
367     my @m = ();
368
369     $self->{DFSEP} = '$(DIRFILESEP)';  # alias for internal use
370
371     for my $macro (qw(
372
373               AR_STATIC_ARGS DIRFILESEP DFSEP
374               NAME NAME_SYM 
375               VERSION    VERSION_MACRO    VERSION_SYM DEFINE_VERSION
376               XS_VERSION XS_VERSION_MACRO             XS_DEFINE_VERSION
377               INST_ARCHLIB INST_SCRIPT INST_BIN INST_LIB
378               INST_MAN1DIR INST_MAN3DIR
379               MAN1EXT      MAN3EXT
380               INSTALLDIRS INSTALL_BASE DESTDIR PREFIX
381               PERLPREFIX      SITEPREFIX      VENDORPREFIX
382                    ),
383                    (map { ("INSTALL".$_,
384                           "DESTINSTALL".$_)
385                         } $self->installvars),
386                    qw(
387               PERL_LIB    
388               PERL_ARCHLIB
389               LIBPERL_A MYEXTLIB
390               FIRST_MAKEFILE MAKEFILE_OLD MAKE_APERL_FILE 
391               PERLMAINCC PERL_SRC PERL_INC 
392               PERL            FULLPERL          ABSPERL
393               PERLRUN         FULLPERLRUN       ABSPERLRUN
394               PERLRUNINST     FULLPERLRUNINST   ABSPERLRUNINST
395               PERL_CORE
396               PERM_RW PERM_RWX
397
398               ) ) 
399     {
400         next unless defined $self->{$macro};
401
402         # pathnames can have sharp signs in them; escape them so
403         # make doesn't think it is a comment-start character.
404         $self->{$macro} =~ s/#/\\#/g;
405         push @m, "$macro = $self->{$macro}\n";
406     }
407
408     push @m, qq{
409 MAKEMAKER   = $self->{MAKEMAKER}
410 MM_VERSION  = $self->{MM_VERSION}
411 MM_REVISION = $self->{MM_REVISION}
412 };
413
414     push @m, q{
415 # FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
416 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
417 # PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
418 # DLBASE  = Basename part of dynamic library. May be just equal BASEEXT.
419 };
420
421     for my $macro (qw/
422               MAKE
423               FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT
424               LDFROM LINKTYPE BOOTDEP
425               / ) 
426     {
427         next unless defined $self->{$macro};
428         push @m, "$macro = $self->{$macro}\n";
429     }
430
431     push @m, "
432 # Handy lists of source code files:
433 XS_FILES = ".$self->wraplist(sort keys %{$self->{XS}})."
434 C_FILES  = ".$self->wraplist(@{$self->{C}})."
435 O_FILES  = ".$self->wraplist(@{$self->{O_FILES}})."
436 H_FILES  = ".$self->wraplist(@{$self->{H}})."
437 MAN1PODS = ".$self->wraplist(sort keys %{$self->{MAN1PODS}})."
438 MAN3PODS = ".$self->wraplist(sort keys %{$self->{MAN3PODS}})."
439 ";
440
441
442     push @m, q{
443 # Where is the Config information that we are using/depend on
444 CONFIGDEP = $(PERL_ARCHLIB)$(DFSEP)Config.pm $(PERL_INC)$(DFSEP)config.h
445 };
446
447
448     push @m, qq{
449 # Where to build things
450 INST_LIBDIR      = $self->{INST_LIBDIR}
451 INST_ARCHLIBDIR  = $self->{INST_ARCHLIBDIR}
452
453 INST_AUTODIR     = $self->{INST_AUTODIR}
454 INST_ARCHAUTODIR = $self->{INST_ARCHAUTODIR}
455
456 INST_STATIC      = $self->{INST_STATIC}
457 INST_DYNAMIC     = $self->{INST_DYNAMIC}
458 INST_BOOT        = $self->{INST_BOOT}
459 };
460
461
462     push @m, qq{
463 # Extra linker info
464 EXPORT_LIST        = $self->{EXPORT_LIST}
465 PERL_ARCHIVE       = $self->{PERL_ARCHIVE}
466 PERL_ARCHIVE_AFTER = $self->{PERL_ARCHIVE_AFTER}
467 };
468
469     push @m, "
470
471 TO_INST_PM = ".$self->wraplist(sort keys %{$self->{PM}})."
472
473 PM_TO_BLIB = ".$self->wraplist(%{$self->{PM}})."
474 ";
475
476     join('',@m);
477 }
478
479
480 =item depend (o)
481
482 Same as macro for the depend attribute.
483
484 =cut
485
486 sub depend {
487     my($self,%attribs) = @_;
488     my(@m,$key,$val);
489     while (($key,$val) = each %attribs){
490         last unless defined $key;
491         push @m, "$key : $val\n";
492     }
493     join "", @m;
494 }
495
496
497 =item init_DEST
498
499   $mm->init_DEST
500
501 Defines the DESTDIR and DEST* variables paralleling the INSTALL*.
502
503 =cut
504
505 sub init_DEST {
506     my $self = shift;
507
508     # Initialize DESTDIR
509     $self->{DESTDIR} ||= '';
510
511     # Make DEST variables.
512     foreach my $var ($self->installvars) {
513         my $destvar = 'DESTINSTALL'.$var;
514         $self->{$destvar} ||= '$(DESTDIR)$(INSTALL'.$var.')';
515     }
516 }
517
518
519 =item init_dist
520
521   $mm->init_dist;
522
523 Defines a lot of macros for distribution support.
524
525   macro         description                     default
526
527   TAR           tar command to use              tar
528   TARFLAGS      flags to pass to TAR            cvf
529
530   ZIP           zip command to use              zip
531   ZIPFLAGS      flags to pass to ZIP            -r
532
533   COMPRESS      compression command to          gzip --best
534                 use for tarfiles
535   SUFFIX        suffix to put on                .gz 
536                 compressed files
537
538   SHAR          shar command to use             shar
539
540   PREOP         extra commands to run before
541                 making the archive 
542   POSTOP        extra commands to run after
543                 making the archive
544
545   TO_UNIX       a command to convert linefeeds
546                 to Unix style in your archive 
547
548   CI            command to checkin your         ci -u
549                 sources to version control
550   RCS_LABEL     command to label your sources   rcs -Nv$(VERSION_SYM): -q
551                 just after CI is run
552
553   DIST_CP       $how argument to manicopy()     best
554                 when the distdir is created
555
556   DIST_DEFAULT  default target to use to        tardist
557                 create a distribution
558
559   DISTVNAME     name of the resulting archive   $(DISTNAME)-$(VERSION)
560                 (minus suffixes)
561
562 =cut
563
564 sub init_dist {
565     my $self = shift;
566
567     $self->{TAR}      ||= 'tar';
568     $self->{TARFLAGS} ||= 'cvf';
569     $self->{ZIP}      ||= 'zip';
570     $self->{ZIPFLAGS} ||= '-r';
571     $self->{COMPRESS} ||= 'gzip --best';
572     $self->{SUFFIX}   ||= '.gz';
573     $self->{SHAR}     ||= 'shar';
574     $self->{PREOP}    ||= '$(NOECHO) $(NOOP)'; # eg update MANIFEST
575     $self->{POSTOP}   ||= '$(NOECHO) $(NOOP)'; # eg remove the distdir
576     $self->{TO_UNIX}  ||= '$(NOECHO) $(NOOP)';
577
578     $self->{CI}       ||= 'ci -u';
579     $self->{RCS_LABEL}||= 'rcs -Nv$(VERSION_SYM): -q';
580     $self->{DIST_CP}  ||= 'best';
581     $self->{DIST_DEFAULT} ||= 'tardist';
582
583     ($self->{DISTNAME} = $self->{NAME}) =~ s{::}{-}g unless $self->{DISTNAME};
584     $self->{DISTVNAME} ||= $self->{DISTNAME}.'-'.$self->{VERSION};
585
586 }
587
588 =item dist (o)
589
590   my $dist_macros = $mm->dist(%overrides);
591
592 Generates a make fragment defining all the macros initialized in
593 init_dist.
594
595 %overrides can be used to override any of the above.
596
597 =cut
598
599 sub dist {
600     my($self, %attribs) = @_;
601
602     my $make = '';
603     foreach my $key (qw( 
604             TAR TARFLAGS ZIP ZIPFLAGS COMPRESS SUFFIX SHAR
605             PREOP POSTOP TO_UNIX
606             CI RCS_LABEL DIST_CP DIST_DEFAULT
607             DISTNAME DISTVNAME
608            ))
609     {
610         my $value = $attribs{$key} || $self->{$key};
611         $make .= "$key = $value\n";
612     }
613
614     return $make;
615 }
616
617 =item dist_basics (o)
618
619 Defines the targets distclean, distcheck, skipcheck, manifest, veryclean.
620
621 =cut
622
623 sub dist_basics {
624     my($self) = shift;
625
626     return <<'MAKE_FRAG';
627 distclean :: realclean distcheck
628         $(NOECHO) $(NOOP)
629
630 distcheck :
631         $(PERLRUN) "-MExtUtils::Manifest=fullcheck" -e fullcheck
632
633 skipcheck :
634         $(PERLRUN) "-MExtUtils::Manifest=skipcheck" -e skipcheck
635
636 manifest :
637         $(PERLRUN) "-MExtUtils::Manifest=mkmanifest" -e mkmanifest
638
639 veryclean : realclean
640         $(RM_F) *~ */*~ *.orig */*.orig *.bak */*.bak *.old */*.old 
641
642 MAKE_FRAG
643
644 }
645
646 =item dist_ci (o)
647
648 Defines a check in target for RCS.
649
650 =cut
651
652 sub dist_ci {
653     my($self) = shift;
654     return q{
655 ci :
656         $(PERLRUN) "-MExtUtils::Manifest=maniread" \\
657           -e "@all = keys %{ maniread() };" \\
658           -e "print(qq{Executing $(CI) @all\n}); system(qq{$(CI) @all});" \\
659           -e "print(qq{Executing $(RCS_LABEL) ...\n}); system(qq{$(RCS_LABEL) @all});"
660 };
661 }
662
663 =item dist_core (o)
664
665   my $dist_make_fragment = $MM->dist_core;
666
667 Puts the targets necessary for 'make dist' together into one make
668 fragment.
669
670 =cut
671
672 sub dist_core {
673     my($self) = shift;
674
675     my $make_frag = '';
676     foreach my $target (qw(dist tardist uutardist tarfile zipdist zipfile 
677                            shdist))
678     {
679         my $method = $target.'_target';
680         $make_frag .= "\n";
681         $make_frag .= $self->$method();
682     }
683
684     return $make_frag;
685 }
686
687
688 =item B<dist_target>
689
690   my $make_frag = $MM->dist_target;
691
692 Returns the 'dist' target to make an archive for distribution.  This
693 target simply checks to make sure the Makefile is up-to-date and
694 depends on $(DIST_DEFAULT).
695
696 =cut
697
698 sub dist_target {
699     my($self) = shift;
700
701     my $date_check = $self->oneliner(<<'CODE', ['-l']);
702 print 'Warning: Makefile possibly out of date with $(VERSION_FROM)'
703     if -e '$(VERSION_FROM)' and -M '$(VERSION_FROM)' < -M '$(FIRST_MAKEFILE)';
704 CODE
705
706     return sprintf <<'MAKE_FRAG', $date_check;
707 dist : $(DIST_DEFAULT) $(FIRST_MAKEFILE)
708         $(NOECHO) %s
709 MAKE_FRAG
710 }
711
712 =item B<tardist_target>
713
714   my $make_frag = $MM->tardist_target;
715
716 Returns the 'tardist' target which is simply so 'make tardist' works.
717 The real work is done by the dynamically named tardistfile_target()
718 method, tardist should have that as a dependency.
719
720 =cut
721
722 sub tardist_target {
723     my($self) = shift;
724
725     return <<'MAKE_FRAG';
726 tardist : $(DISTVNAME).tar$(SUFFIX)
727         $(NOECHO) $(NOOP)
728 MAKE_FRAG
729 }
730
731 =item B<zipdist_target>
732
733   my $make_frag = $MM->zipdist_target;
734
735 Returns the 'zipdist' target which is simply so 'make zipdist' works.
736 The real work is done by the dynamically named zipdistfile_target()
737 method, zipdist should have that as a dependency.
738
739 =cut
740
741 sub zipdist_target {
742     my($self) = shift;
743
744     return <<'MAKE_FRAG';
745 zipdist : $(DISTVNAME).zip
746         $(NOECHO) $(NOOP)
747 MAKE_FRAG
748 }
749
750 =item B<tarfile_target>
751
752   my $make_frag = $MM->tarfile_target;
753
754 The name of this target is the name of the tarball generated by
755 tardist.  This target does the actual work of turning the distdir into
756 a tarball.
757
758 =cut
759
760 sub tarfile_target {
761     my($self) = shift;
762
763     return <<'MAKE_FRAG';
764 $(DISTVNAME).tar$(SUFFIX) : distdir
765         $(PREOP)
766         $(TO_UNIX)
767         $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
768         $(RM_RF) $(DISTVNAME)
769         $(COMPRESS) $(DISTVNAME).tar
770         $(POSTOP)
771 MAKE_FRAG
772 }
773
774 =item zipfile_target
775
776   my $make_frag = $MM->zipfile_target;
777
778 The name of this target is the name of the zip file generated by
779 zipdist.  This target does the actual work of turning the distdir into
780 a zip file.
781
782 =cut
783
784 sub zipfile_target {
785     my($self) = shift;
786
787     return <<'MAKE_FRAG';
788 $(DISTVNAME).zip : distdir
789         $(PREOP)
790         $(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME)
791         $(RM_RF) $(DISTVNAME)
792         $(POSTOP)
793 MAKE_FRAG
794 }
795
796 =item uutardist_target
797
798   my $make_frag = $MM->uutardist_target;
799
800 Converts the tarfile into a uuencoded file
801
802 =cut
803
804 sub uutardist_target {
805     my($self) = shift;
806
807     return <<'MAKE_FRAG';
808 uutardist : $(DISTVNAME).tar$(SUFFIX)
809         uuencode $(DISTVNAME).tar$(SUFFIX) $(DISTVNAME).tar$(SUFFIX) > $(DISTVNAME).tar$(SUFFIX)_uu
810 MAKE_FRAG
811 }
812
813
814 =item shdist_target
815
816   my $make_frag = $MM->shdist_target;
817
818 Converts the distdir into a shell archive.
819
820 =cut
821
822 sub shdist_target {
823     my($self) = shift;
824
825     return <<'MAKE_FRAG';
826 shdist : distdir
827         $(PREOP)
828         $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar
829         $(RM_RF) $(DISTVNAME)
830         $(POSTOP)
831 MAKE_FRAG
832 }
833
834
835 =item dlsyms (o)
836
837 Used by some OS' to define DL_FUNCS and DL_VARS and write the *.exp files.
838
839 Normally just returns an empty string.
840
841 =cut
842
843 sub dlsyms {
844     return '';
845 }
846
847
848 =item dynamic_bs (o)
849
850 Defines targets for bootstrap files.
851
852 =cut
853
854 sub dynamic_bs {
855     my($self, %attribs) = @_;
856     return '
857 BOOTSTRAP =
858 ' unless $self->has_link_code();
859
860     my $target = $Is{VMS} ? '$(MMS$TARGET)' : '$@';
861
862     return sprintf <<'MAKE_FRAG', ($target) x 5;
863 BOOTSTRAP = $(BASEEXT).bs
864
865 # As Mkbootstrap might not write a file (if none is required)
866 # we use touch to prevent make continually trying to remake it.
867 # The DynaLoader only reads a non-empty file.
868 $(BOOTSTRAP) : $(FIRST_MAKEFILE) $(BOOTDEP) $(INST_ARCHAUTODIR)$(DFSEP).exists
869         $(NOECHO) $(ECHO) "Running Mkbootstrap for $(NAME) ($(BSLOADLIBS))"
870         $(NOECHO) $(PERLRUN) \
871                 "-MExtUtils::Mkbootstrap" \
872                 -e "Mkbootstrap('$(BASEEXT)','$(BSLOADLIBS)');"
873         $(NOECHO) $(TOUCH) %s
874         $(CHMOD) $(PERM_RW) %s
875
876 $(INST_BOOT) : $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists
877         $(NOECHO) $(RM_RF) %s
878         - $(CP) $(BOOTSTRAP) %s
879         $(CHMOD) $(PERM_RW) %s
880 MAKE_FRAG
881 }
882
883 =item dynamic_lib (o)
884
885 Defines how to produce the *.so (or equivalent) files.
886
887 =cut
888
889 sub dynamic_lib {
890     my($self, %attribs) = @_;
891     return '' unless $self->needs_linking(); #might be because of a subdir
892
893     return '' unless $self->has_link_code;
894
895     my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
896     my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
897     my($armaybe) = $attribs{ARMAYBE} || $self->{ARMAYBE} || ":";
898     my($ldfrom) = '$(LDFROM)';
899     $armaybe = 'ar' if ($Is{OSF} and $armaybe eq ':');
900     my(@m);
901     my $ld_opt = $Is{OS2} ? '$(OPTIMIZE) ' : '';        # Useful on other systems too?
902     my $ld_fix = $Is{OS2} ? '|| ( $(RM_F) $@ && sh -c false )' : '';
903     push(@m,'
904 # This section creates the dynamically loadable $(INST_DYNAMIC)
905 # from $(OBJECT) and possibly $(MYEXTLIB).
906 ARMAYBE = '.$armaybe.'
907 OTHERLDFLAGS = '.$ld_opt.$otherldflags.'
908 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
909 INST_DYNAMIC_FIX = '.$ld_fix.'
910
911 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP)
912 ');
913     if ($armaybe ne ':'){
914         $ldfrom = 'tmp$(LIB_EXT)';
915         push(@m,'       $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
916         push(@m,'       $(RANLIB) '."$ldfrom\n");
917     }
918     $ldfrom = "-all $ldfrom -none" if $Is{OSF};
919
920     # The IRIX linker doesn't use LD_RUN_PATH
921     my $ldrun = $Is{IRIX} && $self->{LD_RUN_PATH} ?         
922                        qq{-rpath "$self->{LD_RUN_PATH}"} : '';
923
924     # For example in AIX the shared objects/libraries from previous builds
925     # linger quite a while in the shared dynalinker cache even when nobody
926     # is using them.  This is painful if one for instance tries to restart
927     # a failed build because the link command will fail unnecessarily 'cos
928     # the shared object/library is 'busy'.
929     push(@m,'   $(RM_F) $@
930 ');
931
932     my $libs = '$(LDLOADLIBS)';
933
934     if (($Is{NetBSD} || $Is{Interix}) && $Config{'useshrplib'} eq 'true') {
935         # Use nothing on static perl platforms, and to the flags needed
936         # to link against the shared libperl library on shared perl
937         # platforms.  We peek at lddlflags to see if we need -Wl,-R
938         # or -R to add paths to the run-time library search path.
939         if ($Config{'lddlflags'} =~ /-Wl,-R/) {
940             $libs .= ' -L$(PERL_INC) -Wl,-R$(INSTALLARCHLIB)/CORE -Wl,-R$(PERL_ARCHLIB)/CORE -lperl';
941         } elsif ($Config{'lddlflags'} =~ /-R/) {
942             $libs .= ' -L$(PERL_INC) -R$(INSTALLARCHLIB)/CORE -R$(PERL_ARCHLIB)/CORE -lperl';
943         }
944     }
945
946     my $ld_run_path_shell = "";
947     if ($self->{LD_RUN_PATH} ne "") {
948         $ld_run_path_shell = 'LD_RUN_PATH="$(LD_RUN_PATH)" ';
949     }
950
951     push @m, sprintf <<'MAKE', $ld_run_path_shell, $ldrun, $ldfrom, $libs;
952         %s$(LD) %s $(LDDLFLAGS) %s $(OTHERLDFLAGS) -o $@ $(MYEXTLIB)    \
953           $(PERL_ARCHIVE) %s $(PERL_ARCHIVE_AFTER) $(EXPORT_LIST)       \
954           $(INST_DYNAMIC_FIX)
955 MAKE
956
957     push @m, <<'MAKE';
958         $(CHMOD) $(PERM_RWX) $@
959 MAKE
960
961     return join('',@m);
962 }
963
964 =item exescan
965
966 Deprecated method. Use libscan instead.
967
968 =cut
969
970 sub exescan {
971     my($self,$path) = @_;
972     $path;
973 }
974
975 =item extliblist
976
977 Called by init_others, and calls ext ExtUtils::Liblist. See
978 L<ExtUtils::Liblist> for details.
979
980 =cut
981
982 sub extliblist {
983     my($self,$libs) = @_;
984     require ExtUtils::Liblist;
985     $self->ext($libs, $Verbose);
986 }
987
988 =item find_perl
989
990 Finds the executables PERL and FULLPERL
991
992 =cut
993
994 sub find_perl {
995     my($self, $ver, $names, $dirs, $trace) = @_;
996
997     if ($trace >= 2){
998         print "Looking for perl $ver by these names:
999 @$names
1000 in these dirs:
1001 @$dirs
1002 ";
1003     }
1004
1005     my $stderr_duped = 0;
1006     local *STDERR_COPY;
1007
1008     unless ($Is{BSD}) {
1009         # >& and lexical filehandles together give 5.6.2 indigestion
1010         if( open(STDERR_COPY, '>&STDERR') ) {  ## no critic
1011             $stderr_duped = 1;
1012         }
1013         else {
1014             warn <<WARNING;
1015 find_perl() can't dup STDERR: $!
1016 You might see some garbage while we search for Perl
1017 WARNING
1018         }
1019     }
1020
1021     foreach my $name (@$names){
1022         foreach my $dir (@$dirs){
1023             next unless defined $dir; # $self->{PERL_SRC} may be undefined
1024             my ($abs, $val);
1025             if ($self->file_name_is_absolute($name)) {     # /foo/bar
1026                 $abs = $name;
1027             } elsif ($self->canonpath($name) eq 
1028                      $self->canonpath(basename($name))) {  # foo
1029                 $abs = $self->catfile($dir, $name);
1030             } else {                                            # foo/bar
1031                 $abs = $self->catfile($Curdir, $name);
1032             }
1033             print "Checking $abs\n" if ($trace >= 2);
1034             next unless $self->maybe_command($abs);
1035             print "Executing $abs\n" if ($trace >= 2);
1036
1037             my $version_check = qq{$abs -le "require $ver; print qq{VER_OK}"};
1038             $version_check = "$Config{run} $version_check"
1039                 if defined $Config{run} and length $Config{run};
1040
1041             # To avoid using the unportable 2>&1 to suppress STDERR,
1042             # we close it before running the command.
1043             # However, thanks to a thread library bug in many BSDs
1044             # ( http://www.freebsd.org/cgi/query-pr.cgi?pr=51535 )
1045             # we cannot use the fancier more portable way in here
1046             # but instead need to use the traditional 2>&1 construct.
1047             if ($Is{BSD}) {
1048                 $val = `$version_check 2>&1`;
1049             } else {
1050                 close STDERR if $stderr_duped;
1051                 $val = `$version_check`;
1052
1053                 # 5.6.2's 3-arg open doesn't work with >&
1054                 open STDERR, ">&STDERR_COPY"  ## no critic
1055                         if $stderr_duped;
1056             }
1057
1058             if ($val =~ /^VER_OK/m) {
1059                 print "Using PERL=$abs\n" if $trace;
1060                 return $abs;
1061             } elsif ($trace >= 2) {
1062                 print "Result: '$val' ".($? >> 8)."\n";
1063             }
1064         }
1065     }
1066     print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
1067     0; # false and not empty
1068 }
1069
1070
1071 =item fixin
1072
1073   $mm->fixin(@files);
1074
1075 Inserts the sharpbang or equivalent magic number to a set of @files.
1076
1077 =cut
1078
1079 sub fixin {    # stolen from the pink Camel book, more or less
1080     my ( $self, @files ) = @_;
1081
1082     my ($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/;
1083     for my $file (@files) {
1084         my $file_new = "$file.new";
1085         my $file_bak = "$file.bak";
1086
1087         open( my $fixin, '<', $file ) or croak "Can't process '$file': $!";
1088         local $/ = "\n";
1089         chomp( my $line = <$fixin> );
1090         next unless $line =~ s/^\s*\#!\s*//;    # Not a shbang file.
1091         # Now figure out the interpreter name.
1092         my ( $cmd, $arg ) = split ' ', $line, 2;
1093         $cmd =~ s!^.*/!!;
1094
1095         # Now look (in reverse) for interpreter in absolute PATH (unless perl).
1096         my $interpreter;
1097         if ( $cmd eq "perl" ) {
1098             if ( $Config{startperl} =~ m,^\#!.*/perl, ) {
1099                 $interpreter = $Config{startperl};
1100                 $interpreter =~ s,^\#!,,;
1101             }
1102             else {
1103                 $interpreter = $Config{perlpath};
1104             }
1105         }
1106         else {
1107             my (@absdirs)
1108                 = reverse grep { $self->file_name_is_absolute } $self->path;
1109             $interpreter = '';
1110
1111             foreach my $dir (@absdirs) {
1112                 if ( $self->maybe_command($cmd) ) {
1113                     warn "Ignoring $interpreter in $file\n"
1114                         if $Verbose && $interpreter;
1115                     $interpreter = $self->catfile( $dir, $cmd );
1116                 }
1117             }
1118         }
1119
1120         # Figure out how to invoke interpreter on this machine.
1121
1122         my ($shb) = "";
1123         if ($interpreter) {
1124             print STDOUT "Changing sharpbang in $file to $interpreter"
1125                 if $Verbose;
1126
1127             # this is probably value-free on DOSISH platforms
1128             if ($does_shbang) {
1129                 $shb .= "$Config{'sharpbang'}$interpreter";
1130                 $shb .= ' ' . $arg if defined $arg;
1131                 $shb .= "\n";
1132             }
1133             $shb .= qq{
1134 eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}'
1135     if 0; # not running under some shell
1136 } unless $Is{Win32};    # this won't work on win32, so don't
1137         }
1138         else {
1139             warn "Can't find $cmd in PATH, $file unchanged"
1140                 if $Verbose;
1141             next;
1142         }
1143
1144         open( my $fixout, ">", "$file_new" ) or do {
1145             warn "Can't create new $file: $!\n";
1146             next;
1147         };
1148
1149         # Print out the new #! line (or equivalent).
1150         local $\;
1151         local $/;
1152         print $fixout $shb, <$fixin>;
1153         close $fixin;
1154         close $fixout;
1155
1156         chmod 0666, $file_bak;
1157         unlink $file_bak;
1158         unless ( _rename( $file, $file_bak ) ) {
1159             warn "Can't rename $file to $file_bak: $!";
1160             next;
1161         }
1162         unless ( _rename( $file_new, $file ) ) {
1163             warn "Can't rename $file_new to $file: $!";
1164             unless ( _rename( $file_bak, $file ) ) {
1165                 warn "Can't rename $file_bak back to $file either: $!";
1166                 warn "Leaving $file renamed as $file_bak\n";
1167             }
1168             next;
1169         }
1170         unlink $file_bak;
1171     }
1172     continue {
1173         system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
1174     }
1175 }
1176
1177
1178 sub _rename {
1179     my($old, $new) = @_;
1180
1181     foreach my $file ($old, $new) {
1182         if( $Is{VMS} and basename($file) !~ /\./ ) {
1183             # rename() in 5.8.0 on VMS will not rename a file if it
1184             # does not contain a dot yet it returns success.
1185             $file = "$file.";
1186         }
1187     }
1188
1189     return rename($old, $new);
1190 }
1191
1192
1193 =item force (o)
1194
1195 Writes an empty FORCE: target.
1196
1197 =cut
1198
1199 sub force {
1200     my($self) = shift;
1201     '# Phony target to force checking subdirectories.
1202 FORCE :
1203         $(NOECHO) $(NOOP)
1204 ';
1205 }
1206
1207 =item guess_name
1208
1209 Guess the name of this package by examining the working directory's
1210 name. MakeMaker calls this only if the developer has not supplied a
1211 NAME attribute.
1212
1213 =cut
1214
1215 # ';
1216
1217 sub guess_name {
1218     my($self) = @_;
1219     use Cwd 'cwd';
1220     my $name = basename(cwd());
1221     $name =~ s|[\-_][\d\.\-]+\z||;  # this is new with MM 5.00, we
1222                                     # strip minus or underline
1223                                     # followed by a float or some such
1224     print "Warning: Guessing NAME [$name] from current directory name.\n";
1225     $name;
1226 }
1227
1228 =item has_link_code
1229
1230 Returns true if C, XS, MYEXTLIB or similar objects exist within this
1231 object that need a compiler. Does not descend into subdirectories as
1232 needs_linking() does.
1233
1234 =cut
1235
1236 sub has_link_code {
1237     my($self) = shift;
1238     return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE};
1239     if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){
1240         $self->{HAS_LINK_CODE} = 1;
1241         return 1;
1242     }
1243     return $self->{HAS_LINK_CODE} = 0;
1244 }
1245
1246
1247 =item init_dirscan
1248
1249 Scans the directory structure and initializes DIR, XS, XS_FILES,
1250 C, C_FILES, O_FILES, H, H_FILES, PL_FILES, EXE_FILES.
1251
1252 Called by init_main.
1253
1254 =cut
1255
1256 sub init_dirscan {      # --- File and Directory Lists (.xs .pm .pod etc)
1257     my($self) = @_;
1258     my(%dir, %xs, %c, %h, %pl_files, %pm);
1259
1260     my %ignore = map {( $_ => 1 )} qw(Makefile.PL Build.PL test.pl t);
1261
1262     # ignore the distdir
1263     $Is{VMS} ? $ignore{"$self->{DISTVNAME}.dir"} = 1
1264             : $ignore{$self->{DISTVNAME}} = 1;
1265
1266     @ignore{map lc, keys %ignore} = values %ignore if $Is{VMS};
1267
1268     foreach my $name ($self->lsdir($Curdir)){
1269         next if $name =~ /\#/;
1270         next if $name eq $Curdir or $name eq $Updir or $ignore{$name};
1271         next unless $self->libscan($name);
1272         if (-d $name){
1273             next if -l $name; # We do not support symlinks at all
1274             next if $self->{NORECURS};
1275             $dir{$name} = $name if (-f $self->catfile($name,"Makefile.PL"));
1276         } elsif ($name =~ /\.xs\z/){
1277             my($c); ($c = $name) =~ s/\.xs\z/.c/;
1278             $xs{$name} = $c;
1279             $c{$c} = 1;
1280         } elsif ($name =~ /\.c(pp|xx|c)?\z/i){  # .c .C .cpp .cxx .cc
1281             $c{$name} = 1
1282                 unless $name =~ m/perlmain\.c/; # See MAP_TARGET
1283         } elsif ($name =~ /\.h\z/i){
1284             $h{$name} = 1;
1285         } elsif ($name =~ /\.PL\z/) {
1286             ($pl_files{$name} = $name) =~ s/\.PL\z// ;
1287         } elsif (($Is{VMS} || $Is{Dos}) && $name =~ /[._]pl$/i) {
1288             # case-insensitive filesystem, one dot per name, so foo.h.PL
1289             # under Unix appears as foo.h_pl under VMS or fooh.pl on Dos
1290             local($/); open(my $pl, '<', $name); my $txt = <$pl>; close $pl;
1291             if ($txt =~ /Extracting \S+ \(with variable substitutions/) {
1292                 ($pl_files{$name} = $name) =~ s/[._]pl\z//i ;
1293             }
1294             else { 
1295                 $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name); 
1296             }
1297         } elsif ($name =~ /\.(p[ml]|pod)\z/){
1298             $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name);
1299         }
1300     }
1301
1302     $self->{PL_FILES}   ||= \%pl_files;
1303     $self->{DIR}        ||= [sort keys %dir];
1304     $self->{XS}         ||= \%xs;
1305     $self->{C}          ||= [sort keys %c];
1306     $self->{H}          ||= [sort keys %h];
1307     $self->{PM}         ||= \%pm;
1308
1309     my @o_files = @{$self->{C}};
1310     $self->{O_FILES} = [grep s/\.c(pp|xx|c)?\z/$self->{OBJ_EXT}/i, @o_files];
1311 }
1312
1313
1314 =item init_MANPODS
1315
1316 Determines if man pages should be generated and initializes MAN1PODS
1317 and MAN3PODS as appropriate.
1318
1319 =cut
1320
1321 sub init_MANPODS {
1322     my $self = shift;
1323
1324     # Set up names of manual pages to generate from pods
1325     foreach my $man (qw(MAN1 MAN3)) {
1326         if ( $self->{"${man}PODS"}
1327              or $self->{"INSTALL${man}DIR"} =~ /^(none|\s*)$/
1328         ) {
1329             $self->{"${man}PODS"} ||= {};
1330         }
1331         else {
1332             my $init_method = "init_${man}PODS";
1333             $self->$init_method();
1334         }
1335     }
1336 }
1337
1338
1339 sub _has_pod {
1340     my($self, $file) = @_;
1341
1342     my($ispod)=0;
1343     if (open( my $fh, '<', $file )) {
1344         while (<$fh>) {
1345             if (/^=(?:head\d+|item|pod)\b/) {
1346                 $ispod=1;
1347                 last;
1348             }
1349         }
1350         close $fh;
1351     } else {
1352         # If it doesn't exist yet, we assume, it has pods in it
1353         $ispod = 1;
1354     }
1355
1356     return $ispod;
1357 }
1358
1359
1360 =item init_MAN1PODS
1361
1362 Initializes MAN1PODS from the list of EXE_FILES.
1363
1364 =cut
1365
1366 sub init_MAN1PODS {
1367     my($self) = @_;
1368
1369     if ( exists $self->{EXE_FILES} ) {
1370         foreach my $name (@{$self->{EXE_FILES}}) {
1371             next unless $self->_has_pod($name);
1372
1373             $self->{MAN1PODS}->{$name} =
1374                 $self->catfile("\$(INST_MAN1DIR)", 
1375                                basename($name).".\$(MAN1EXT)");
1376         }
1377     }
1378 }
1379
1380
1381 =item init_MAN3PODS
1382
1383 Initializes MAN3PODS from the list of PM files.
1384
1385 =cut
1386
1387 sub init_MAN3PODS {
1388     my $self = shift;
1389
1390     my %manifypods = (); # we collect the keys first, i.e. the files
1391                          # we have to convert to pod
1392
1393     foreach my $name (keys %{$self->{PM}}) {
1394         if ($name =~ /\.pod\z/ ) {
1395             $manifypods{$name} = $self->{PM}{$name};
1396         } elsif ($name =~ /\.p[ml]\z/ ) {
1397             if( $self->_has_pod($name) ) {
1398                 $manifypods{$name} = $self->{PM}{$name};
1399             }
1400         }
1401     }
1402
1403     my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
1404
1405     # Remove "Configure.pm" and similar, if it's not the only pod listed
1406     # To force inclusion, just name it "Configure.pod", or override 
1407     # MAN3PODS
1408     foreach my $name (keys %manifypods) {
1409         if ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) {
1410             delete $manifypods{$name};
1411             next;
1412         }
1413         my($manpagename) = $name;
1414         $manpagename =~ s/\.p(od|m|l)\z//;
1415         # everything below lib is ok
1416         unless($manpagename =~ s!^\W*($parentlibs_re)\W+!!s) {
1417             $manpagename = $self->catfile(
1418                 split(/::/,$self->{PARENT_NAME}),$manpagename
1419             );
1420         }
1421         $manpagename = $self->replace_manpage_separator($manpagename);
1422         $self->{MAN3PODS}->{$name} =
1423             $self->catfile("\$(INST_MAN3DIR)", "$manpagename.\$(MAN3EXT)");
1424     }
1425 }
1426
1427
1428 =item init_PM
1429
1430 Initializes PMLIBDIRS and PM from PMLIBDIRS.
1431
1432 =cut
1433
1434 sub init_PM {
1435     my $self = shift;
1436
1437     # Some larger extensions often wish to install a number of *.pm/pl
1438     # files into the library in various locations.
1439
1440     # The attribute PMLIBDIRS holds an array reference which lists
1441     # subdirectories which we should search for library files to
1442     # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ].  We
1443     # recursively search through the named directories (skipping any
1444     # which don't exist or contain Makefile.PL files).
1445
1446     # For each *.pm or *.pl file found $self->libscan() is called with
1447     # the default installation path in $_[1]. The return value of
1448     # libscan defines the actual installation location.  The default
1449     # libscan function simply returns the path.  The file is skipped
1450     # if libscan returns false.
1451
1452     # The default installation location passed to libscan in $_[1] is:
1453     #
1454     #  ./*.pm           => $(INST_LIBDIR)/*.pm
1455     #  ./xyz/...        => $(INST_LIBDIR)/xyz/...
1456     #  ./lib/...        => $(INST_LIB)/...
1457     #
1458     # In this way the 'lib' directory is seen as the root of the actual
1459     # perl library whereas the others are relative to INST_LIBDIR
1460     # (which includes PARENT_NAME). This is a subtle distinction but one
1461     # that's important for nested modules.
1462
1463     unless( $self->{PMLIBDIRS} ) {
1464         if( $Is{VMS} ) {
1465             # Avoid logical name vs directory collisions
1466             $self->{PMLIBDIRS} = ['./lib', "./$self->{BASEEXT}"];
1467         }
1468         else {
1469             $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}];
1470         }
1471     }
1472
1473     #only existing directories that aren't in $dir are allowed
1474
1475     # Avoid $_ wherever possible:
1476     # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
1477     my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
1478     @{$self->{PMLIBDIRS}} = ();
1479     my %dir = map { ($_ => $_) } @{$self->{DIR}};
1480     foreach my $pmlibdir (@pmlibdirs) {
1481         -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
1482     }
1483
1484     unless( $self->{PMLIBPARENTDIRS} ) {
1485         @{$self->{PMLIBPARENTDIRS}} = ('lib');
1486     }
1487
1488     return if $self->{PM} and $self->{ARGS}{PM};
1489
1490     if (@{$self->{PMLIBDIRS}}){
1491         print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
1492             if ($Verbose >= 2);
1493         require File::Find;
1494         File::Find::find(sub {
1495             if (-d $_){
1496                 unless ($self->libscan($_)){
1497                     $File::Find::prune = 1;
1498                 }
1499                 return;
1500             }
1501             return if /\#/;
1502             return if /~$/;    # emacs temp files
1503             return if /,v$/;   # RCS files
1504
1505             my $path   = $File::Find::name;
1506             my $prefix = $self->{INST_LIBDIR};
1507             my $striplibpath;
1508
1509             my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
1510             $prefix =  $self->{INST_LIB} 
1511                 if ($striplibpath = $path) =~ s{^(\W*)($parentlibs_re)\W}
1512                                                {$1}i;
1513
1514             my($inst) = $self->catfile($prefix,$striplibpath);
1515             local($_) = $inst; # for backwards compatibility
1516             $inst = $self->libscan($inst);
1517             print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
1518             return unless $inst;
1519             $self->{PM}{$path} = $inst;
1520         }, @{$self->{PMLIBDIRS}});
1521     }
1522 }
1523
1524
1525 =item init_DIRFILESEP
1526
1527 Using / for Unix.  Called by init_main.
1528
1529 =cut
1530
1531 sub init_DIRFILESEP {
1532     my($self) = shift;
1533
1534     $self->{DIRFILESEP} = '/';
1535 }
1536     
1537
1538 =item init_main
1539
1540 Initializes AR, AR_STATIC_ARGS, BASEEXT, CONFIG, DISTNAME, DLBASE,
1541 EXE_EXT, FULLEXT, FULLPERL, FULLPERLRUN, FULLPERLRUNINST, INST_*,
1542 INSTALL*, INSTALLDIRS, LIB_EXT, LIBPERL_A, MAP_TARGET, NAME,
1543 OBJ_EXT, PARENT_NAME, PERL, PERL_ARCHLIB, PERL_INC, PERL_LIB,
1544 PERL_SRC, PERLRUN, PERLRUNINST, PREFIX, VERSION,
1545 VERSION_SYM, XS_VERSION.
1546
1547 =cut
1548
1549 sub init_main {
1550     my($self) = @_;
1551
1552     # --- Initialize Module Name and Paths
1553
1554     # NAME    = Foo::Bar::Oracle
1555     # FULLEXT = Foo/Bar/Oracle
1556     # BASEEXT = Oracle
1557     # PARENT_NAME = Foo::Bar
1558 ### Only UNIX:
1559 ###    ($self->{FULLEXT} =
1560 ###     $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket
1561     $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME});
1562
1563
1564     # Copied from DynaLoader:
1565
1566     my(@modparts) = split(/::/,$self->{NAME});
1567     my($modfname) = $modparts[-1];
1568
1569     # Some systems have restrictions on files names for DLL's etc.
1570     # mod2fname returns appropriate file base name (typically truncated)
1571     # It may also edit @modparts if required.
1572     if (defined &DynaLoader::mod2fname) {
1573         $modfname = &DynaLoader::mod2fname(\@modparts);
1574     }
1575
1576     ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!(?:([\w:]+)::)?(\w+)\z! ;
1577     $self->{PARENT_NAME} ||= '';
1578
1579     if (defined &DynaLoader::mod2fname) {
1580         # As of 5.001m, dl_os2 appends '_'
1581         $self->{DLBASE} = $modfname;
1582     } else {
1583         $self->{DLBASE} = '$(BASEEXT)';
1584     }
1585
1586
1587     # --- Initialize PERL_LIB, PERL_SRC
1588
1589     # *Real* information: where did we get these two from? ...
1590     my $inc_config_dir = dirname($INC{'Config.pm'});
1591     my $inc_carp_dir   = dirname($INC{'Carp.pm'});
1592
1593     unless ($self->{PERL_SRC}){
1594         foreach my $dir_count (1..8) { # 8 is the VMS limit for nesting
1595             my $dir = $self->catdir(($Updir) x $dir_count);
1596
1597             if (-f $self->catfile($dir,"config_h.SH")   &&
1598                 -f $self->catfile($dir,"perl.h")        &&
1599                 -f $self->catfile($dir,"lib","strict.pm")
1600             ) {
1601                 $self->{PERL_SRC}=$dir ;
1602                 last;
1603             }
1604         }
1605     }
1606
1607     warn "PERL_CORE is set but I can't find your PERL_SRC!\n" if
1608       $self->{PERL_CORE} and !$self->{PERL_SRC};
1609
1610     if ($self->{PERL_SRC}){
1611         $self->{PERL_LIB}     ||= $self->catdir("$self->{PERL_SRC}","lib");
1612
1613         if (defined $Cross::platform) {
1614             $self->{PERL_ARCHLIB} = 
1615               $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform);
1616             $self->{PERL_INC}     = 
1617               $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform, 
1618                                  $Is{Win32}?("CORE"):());
1619         }
1620         else {
1621             $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
1622             $self->{PERL_INC}     = ($Is{Win32}) ? 
1623               $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
1624         }
1625
1626         # catch a situation that has occurred a few times in the past:
1627         unless (
1628                 -s $self->catfile($self->{PERL_SRC},'cflags')
1629                 or
1630                 $Is{VMS}
1631                 &&
1632                 -s $self->catfile($self->{PERL_SRC},'perlshr_attr.opt')
1633                 or
1634                 $Is{Win32}
1635                ){
1636             warn qq{
1637 You cannot build extensions below the perl source tree after executing
1638 a 'make clean' in the perl source tree.
1639
1640 To rebuild extensions distributed with the perl source you should
1641 simply Configure (to include those extensions) and then build perl as
1642 normal. After installing perl the source tree can be deleted. It is
1643 not needed for building extensions by running 'perl Makefile.PL'
1644 usually without extra arguments.
1645
1646 It is recommended that you unpack and build additional extensions away
1647 from the perl source tree.
1648 };
1649         }
1650     } else {
1651         # we should also consider $ENV{PERL5LIB} here
1652         my $old = $self->{PERL_LIB} || $self->{PERL_ARCHLIB} || $self->{PERL_INC};
1653         $self->{PERL_LIB}     ||= $Config{privlibexp};
1654         $self->{PERL_ARCHLIB} ||= $Config{archlibexp};
1655         $self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
1656         my $perl_h;
1657
1658         if (not -f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))
1659             and not $old){
1660             # Maybe somebody tries to build an extension with an
1661             # uninstalled Perl outside of Perl build tree
1662             my $lib;
1663             for my $dir (@INC) {
1664               $lib = $dir, last if -e $self->catdir($dir, "Config.pm");
1665             }
1666             if ($lib) {
1667               # Win32 puts its header files in /perl/src/lib/CORE.
1668               # Unix leaves them in /perl/src.
1669               my $inc = $Is{Win32} ? $self->catdir($lib, "CORE" )
1670                                   : dirname $lib;
1671               if (-e $self->catdir($inc, "perl.h")) {
1672                 $self->{PERL_LIB}          = $lib;
1673                 $self->{PERL_ARCHLIB}      = $lib;
1674                 $self->{PERL_INC}          = $inc;
1675                 $self->{UNINSTALLED_PERL}  = 1;
1676                 print STDOUT <<EOP;
1677 ... Detected uninstalled Perl.  Trying to continue.
1678 EOP
1679               }
1680             }
1681         }       
1682     }
1683
1684     # We get SITELIBEXP and SITEARCHEXP directly via
1685     # Get_from_Config. When we are running standard modules, these
1686     # won't matter, we will set INSTALLDIRS to "perl". Otherwise we
1687     # set it to "site". I prefer that INSTALLDIRS be set from outside
1688     # MakeMaker.
1689     $self->{INSTALLDIRS} ||= "site";
1690
1691     $self->{MAN1EXT} ||= $Config{man1ext};
1692     $self->{MAN3EXT} ||= $Config{man3ext};
1693
1694     # Get some stuff out of %Config if we haven't yet done so
1695     print STDOUT "CONFIG must be an array ref\n"
1696         if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
1697     $self->{CONFIG} = [] unless (ref $self->{CONFIG});
1698     push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
1699     push(@{$self->{CONFIG}}, 'shellflags') if $Config{shellflags};
1700     my(%once_only);
1701     foreach my $m (@{$self->{CONFIG}}){
1702         next if $once_only{$m};
1703         print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
1704                 unless exists $Config{$m};
1705         $self->{uc $m} ||= $Config{$m};
1706         $once_only{$m} = 1;
1707     }
1708
1709 # This is too dangerous:
1710 #    if ($^O eq "next") {
1711 #       $self->{AR} = "libtool";
1712 #       $self->{AR_STATIC_ARGS} = "-o";
1713 #    }
1714 # But I leave it as a placeholder
1715
1716     $self->{AR_STATIC_ARGS} ||= "cr";
1717
1718     # These should never be needed
1719     $self->{OBJ_EXT} ||= '.o';
1720     $self->{LIB_EXT} ||= '.a';
1721
1722     $self->{MAP_TARGET} ||= "perl";
1723
1724     $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
1725
1726     # make a simple check if we find strict
1727     warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
1728         (strict.pm not found)"
1729         unless -f $self->catfile("$self->{PERL_LIB}","strict.pm") ||
1730                $self->{NAME} eq "ExtUtils::MakeMaker";
1731 }
1732
1733 =item init_others
1734
1735 Initializes EXTRALIBS, BSLOADLIBS, LDLOADLIBS, LIBS, LD_RUN_PATH, LD,
1736 OBJECT, BOOTDEP, PERLMAINCC, LDFROM, LINKTYPE, SHELL, NOOP,
1737 FIRST_MAKEFILE, MAKEFILE_OLD, NOECHO, RM_F, RM_RF, TEST_F,
1738 TOUCH, CP, MV, CHMOD, UMASK_NULL, ECHO, ECHO_N
1739
1740 =cut
1741
1742 sub init_others {       # --- Initialize Other Attributes
1743     my($self) = shift;
1744
1745     $self->{LD} ||= 'ld';
1746
1747     # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
1748     # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
1749     # undefined. In any case we turn it into an anon array:
1750
1751     # May check $Config{libs} too, thus not empty.
1752     $self->{LIBS} = [$self->{LIBS}] unless ref $self->{LIBS};
1753
1754     $self->{LIBS} = [''] unless @{$self->{LIBS}} && defined $self->{LIBS}[0];
1755     $self->{LD_RUN_PATH} = "";
1756
1757     foreach my $libs ( @{$self->{LIBS}} ){
1758         $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
1759         my(@libs) = $self->extliblist($libs);
1760         if ($libs[0] or $libs[1] or $libs[2]){
1761             # LD_RUN_PATH now computed by ExtUtils::Liblist
1762             ($self->{EXTRALIBS},  $self->{BSLOADLIBS}, 
1763              $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
1764             last;
1765         }
1766     }
1767
1768     if ( $self->{OBJECT} ) {
1769         $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
1770     } else {
1771         # init_dirscan should have found out, if we have C files
1772         $self->{OBJECT} = "";
1773         $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
1774     }
1775     $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
1776     $self->{BOOTDEP}  = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
1777     $self->{PERLMAINCC} ||= '$(CC)';
1778     $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
1779
1780     # Sanity check: don't define LINKTYPE = dynamic if we're skipping
1781     # the 'dynamic' section of MM.  We don't have this problem with
1782     # 'static', since we either must use it (%Config says we can't
1783     # use dynamic loading) or the caller asked for it explicitly.
1784     if (!$self->{LINKTYPE}) {
1785        $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
1786                         ? 'static'
1787                         : ($Config{usedl} ? 'dynamic' : 'static');
1788     };
1789
1790     $self->{NOOP}               ||= '$(SHELL) -c true';
1791     $self->{NOECHO}             = '@' unless defined $self->{NOECHO};
1792
1793     $self->{FIRST_MAKEFILE}     ||= $self->{MAKEFILE} || 'Makefile';
1794     $self->{MAKEFILE}           ||= $self->{FIRST_MAKEFILE};
1795     $self->{MAKEFILE_OLD}       ||= $self->{MAKEFILE}.'.old';
1796     $self->{MAKE_APERL_FILE}    ||= $self->{MAKEFILE}.'.aperl';
1797
1798     # Some makes require a wrapper around macros passed in on the command 
1799     # line.
1800     $self->{MACROSTART}         ||= '';
1801     $self->{MACROEND}           ||= '';
1802
1803     # Not everybody uses -f to indicate "use this Makefile instead"
1804     $self->{USEMAKEFILE}        ||= '-f';
1805
1806     $self->{SHELL}              ||= $Config{sh} || '/bin/sh';
1807
1808     $self->{ECHO}       ||= 'echo';
1809     $self->{ECHO_N}     ||= 'echo -n';
1810     $self->{RM_F}       ||= "rm -f";
1811     $self->{RM_RF}      ||= "rm -rf";
1812     $self->{TOUCH}      ||= "touch";
1813     $self->{TEST_F}     ||= "test -f";
1814     $self->{CP}         ||= "cp";
1815     $self->{MV}         ||= "mv";
1816     $self->{CHMOD}      ||= "chmod";
1817     $self->{MKPATH}     ||= '$(ABSPERLRUN) "-MExtUtils::Command" -e mkpath';
1818     $self->{EQUALIZE_TIMESTAMP} ||= 
1819       '$(ABSPERLRUN) "-MExtUtils::Command" -e eqtime';
1820
1821     $self->{UNINST}     ||= 0;
1822     $self->{VERBINST}   ||= 0;
1823     $self->{MOD_INSTALL} ||= 
1824       $self->oneliner(<<'CODE', ['-MExtUtils::Install']);
1825 install({@ARGV}, '$(VERBINST)', 0, '$(UNINST)');
1826 CODE
1827     $self->{DOC_INSTALL}        ||= 
1828       '$(ABSPERLRUN) "-MExtUtils::Command::MM" -e perllocal_install';
1829     $self->{UNINSTALL}          ||= 
1830       '$(ABSPERLRUN) "-MExtUtils::Command::MM" -e uninstall';
1831     $self->{WARN_IF_OLD_PACKLIST} ||= 
1832       '$(ABSPERLRUN) "-MExtUtils::Command::MM" -e warn_if_old_packlist';
1833     $self->{FIXIN}              ||= 
1834       q{$(PERLRUN) "-MExtUtils::MY" -e "MY->fixin(shift)"};
1835
1836     $self->{UMASK_NULL}         ||= "umask 0";
1837     $self->{DEV_NULL}           ||= "> /dev/null 2>&1";
1838
1839     return 1;
1840 }
1841
1842
1843 =item init_linker
1844
1845 Unix has no need of special linker flags.
1846
1847 =cut
1848
1849 sub init_linker {
1850     my($self) = shift;
1851     $self->{PERL_ARCHIVE} ||= '';
1852     $self->{PERL_ARCHIVE_AFTER} ||= '';
1853     $self->{EXPORT_LIST}  ||= '';
1854 }
1855
1856
1857 =begin _protected
1858
1859 =item init_lib2arch
1860
1861     $mm->init_lib2arch
1862
1863 =end _protected
1864
1865 =cut
1866
1867 sub init_lib2arch {
1868     my($self) = shift;
1869
1870     # The user who requests an installation directory explicitly
1871     # should not have to tell us an architecture installation directory
1872     # as well. We look if a directory exists that is named after the
1873     # architecture. If not we take it as a sign that it should be the
1874     # same as the requested installation directory. Otherwise we take
1875     # the found one.
1876     for my $libpair ({l=>"privlib",   a=>"archlib"}, 
1877                      {l=>"sitelib",   a=>"sitearch"},
1878                      {l=>"vendorlib", a=>"vendorarch"},
1879                     )
1880     {
1881         my $lib = "install$libpair->{l}";
1882         my $Lib = uc $lib;
1883         my $Arch = uc "install$libpair->{a}";
1884         if( $self->{$Lib} && ! $self->{$Arch} ){
1885             my($ilib) = $Config{$lib};
1886
1887             $self->prefixify($Arch,$ilib,$self->{$Lib});
1888
1889             unless (-d $self->{$Arch}) {
1890                 print STDOUT "Directory $self->{$Arch} not found\n" 
1891                   if $Verbose;
1892                 $self->{$Arch} = $self->{$Lib};
1893             }
1894             print STDOUT "Defaulting $Arch to $self->{$Arch}\n" if $Verbose;
1895         }
1896     }
1897 }
1898
1899
1900 =item init_PERL
1901
1902     $mm->init_PERL;
1903
1904 Called by init_main.  Sets up ABSPERL, PERL, FULLPERL and all the
1905 *PERLRUN* permutations.
1906
1907     PERL is allowed to be miniperl
1908     FULLPERL must be a complete perl
1909
1910     ABSPERL is PERL converted to an absolute path
1911
1912     *PERLRUN contains everything necessary to run perl, find it's
1913          libraries, etc...
1914
1915     *PERLRUNINST is *PERLRUN + everything necessary to find the
1916          modules being built.
1917
1918 =cut
1919
1920 sub init_PERL {
1921     my($self) = shift;
1922
1923     my @defpath = ();
1924     foreach my $component ($self->{PERL_SRC}, $self->path(), 
1925                            $Config{binexp}) 
1926     {
1927         push @defpath, $component if defined $component;
1928     }
1929
1930     # Build up a set of file names (not command names).
1931     my $thisperl = $self->canonpath($^X);
1932     $thisperl .= $Config{exe_ext} unless 
1933                 # VMS might have a file version # at the end
1934       $Is{VMS} ? $thisperl =~ m/$Config{exe_ext}(;\d+)?$/i
1935               : $thisperl =~ m/$Config{exe_ext}$/i;
1936
1937     # We need a relative path to perl when in the core.
1938     $thisperl = $self->abs2rel($thisperl) if $self->{PERL_CORE};
1939
1940     my @perls = ($thisperl);
1941     push @perls, map { "$_$Config{exe_ext}" }
1942                      ('perl', 'perl5', "perl$Config{version}");
1943
1944     # miniperl has priority over all but the cannonical perl when in the
1945     # core.  Otherwise its a last resort.
1946     my $miniperl = "miniperl$Config{exe_ext}";
1947     if( $self->{PERL_CORE} ) {
1948         splice @perls, 1, 0, $miniperl;
1949     }
1950     else {
1951         push @perls, $miniperl;
1952     }
1953
1954     $self->{PERL} ||=
1955         $self->find_perl(5.0, \@perls, \@defpath, $Verbose );
1956     # don't check if perl is executable, maybe they have decided to
1957     # supply switches with perl
1958
1959     # When built for debugging, VMS doesn't create perl.exe but ndbgperl.exe.
1960     my $perl_name = 'perl';
1961     $perl_name = 'ndbgperl' if $Is{VMS} && 
1962       defined $Config{usevmsdebug} && $Config{usevmsdebug} eq 'define';
1963
1964     # XXX This logic is flawed.  If "miniperl" is anywhere in the path
1965     # it will get confused.  It should be fixed to work only on the filename.
1966     # Define 'FULLPERL' to be a non-miniperl (used in test: target)
1967     ($self->{FULLPERL} = $self->{PERL}) =~ s/miniperl/$perl_name/i
1968         unless $self->{FULLPERL};
1969
1970     # Little hack to get around VMS's find_perl putting "MCR" in front
1971     # sometimes.
1972     $self->{ABSPERL} = $self->{PERL};
1973     my $has_mcr = $self->{ABSPERL} =~ s/^MCR\s*//;
1974     if( $self->file_name_is_absolute($self->{ABSPERL}) ) {
1975         $self->{ABSPERL} = '$(PERL)';
1976     }
1977     else {
1978         $self->{ABSPERL} = $self->rel2abs($self->{ABSPERL});
1979
1980         # Quote the perl command if it contains whitespace
1981         $self->{ABSPERL} = $self->quote_literal($self->{ABSPERL})
1982           if $self->{ABSPERL} =~ /\s/;
1983
1984         $self->{ABSPERL} = 'MCR '.$self->{ABSPERL} if $has_mcr;
1985     }
1986
1987     # Are we building the core?
1988     $self->{PERL_CORE} = $ENV{PERL_CORE} unless exists $self->{PERL_CORE};
1989     $self->{PERL_CORE} = 0               unless defined $self->{PERL_CORE};
1990
1991     # How do we run perl?
1992     foreach my $perl (qw(PERL FULLPERL ABSPERL)) {
1993         my $run  = $perl.'RUN';
1994
1995         $self->{$run}  = "\$($perl)";
1996
1997         # Make sure perl can find itself before it's installed.
1998         $self->{$run} .= q{ "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)"} 
1999           if $self->{UNINSTALLED_PERL} || $self->{PERL_CORE};
2000
2001         $self->{$perl.'RUNINST'} = 
2002           sprintf q{$(%sRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)"}, $perl;
2003     }
2004
2005     return 1;
2006 }
2007
2008
2009 =item init_platform
2010
2011 =item platform_constants
2012
2013 Add MM_Unix_VERSION.
2014
2015 =cut
2016
2017 sub init_platform {
2018     my($self) = shift;
2019
2020     $self->{MM_Unix_VERSION} = $VERSION;
2021     $self->{PERL_MALLOC_DEF} = '-DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc '.
2022                                '-Dfree=Perl_mfree -Drealloc=Perl_realloc '.
2023                                '-Dcalloc=Perl_calloc';
2024
2025 }
2026
2027 sub platform_constants {
2028     my($self) = shift;
2029     my $make_frag = '';
2030
2031     foreach my $macro (qw(MM_Unix_VERSION PERL_MALLOC_DEF))
2032     {
2033         next unless defined $self->{$macro};
2034         $make_frag .= "$macro = $self->{$macro}\n";
2035     }
2036
2037     return $make_frag;
2038 }
2039
2040
2041 =item init_PERM
2042
2043   $mm->init_PERM
2044
2045 Called by init_main.  Initializes PERL_*
2046
2047 =cut
2048
2049 sub init_PERM {
2050     my($self) = shift;
2051
2052     $self->{PERM_RW}  = 644  unless defined $self->{PERM_RW};
2053     $self->{PERM_RWX} = 755  unless defined $self->{PERM_RWX};
2054
2055     return 1;
2056 }
2057
2058
2059 =item init_xs
2060
2061     $mm->init_xs
2062
2063 Sets up macros having to do with XS code.  Currently just INST_STATIC,
2064 INST_DYNAMIC and INST_BOOT.
2065
2066 =cut
2067
2068 sub init_xs {
2069     my $self = shift;
2070
2071     if ($self->has_link_code()) {
2072         $self->{INST_STATIC}  = 
2073           $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT)$(LIB_EXT)');
2074         $self->{INST_DYNAMIC} = 
2075           $self->catfile('$(INST_ARCHAUTODIR)', '$(DLBASE).$(DLEXT)');
2076         $self->{INST_BOOT}    = 
2077           $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT).bs');
2078     } else {
2079         $self->{INST_STATIC}  = '';
2080         $self->{INST_DYNAMIC} = '';
2081         $self->{INST_BOOT}    = '';
2082     }
2083 }    
2084
2085 =item install (o)
2086
2087 Defines the install target.
2088
2089 =cut
2090
2091 sub install {
2092     my($self, %attribs) = @_;
2093     my(@m);
2094
2095     push @m, q{
2096 install :: all pure_install doc_install
2097         $(NOECHO) $(NOOP)
2098
2099 install_perl :: all pure_perl_install doc_perl_install
2100         $(NOECHO) $(NOOP)
2101
2102 install_site :: all pure_site_install doc_site_install
2103         $(NOECHO) $(NOOP)
2104
2105 install_vendor :: all pure_vendor_install doc_vendor_install
2106         $(NOECHO) $(NOOP)
2107
2108 pure_install :: pure_$(INSTALLDIRS)_install
2109         $(NOECHO) $(NOOP)
2110
2111 doc_install :: doc_$(INSTALLDIRS)_install
2112         $(NOECHO) $(NOOP)
2113
2114 pure__install : pure_site_install
2115         $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2116
2117 doc__install : doc_site_install
2118         $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2119
2120 pure_perl_install ::
2121         $(NOECHO) $(MOD_INSTALL) \
2122                 read }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
2123                 write }.$self->catfile('$(DESTINSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
2124                 $(INST_LIB) $(DESTINSTALLPRIVLIB) \
2125                 $(INST_ARCHLIB) $(DESTINSTALLARCHLIB) \
2126                 $(INST_BIN) $(DESTINSTALLBIN) \
2127                 $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \
2128                 $(INST_MAN1DIR) $(DESTINSTALLMAN1DIR) \
2129                 $(INST_MAN3DIR) $(DESTINSTALLMAN3DIR)
2130         $(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2131                 }.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{
2132
2133
2134 pure_site_install ::
2135         $(NOECHO) $(MOD_INSTALL) \
2136                 read }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
2137                 write }.$self->catfile('$(DESTINSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{ \
2138                 $(INST_LIB) $(DESTINSTALLSITELIB) \
2139                 $(INST_ARCHLIB) $(DESTINSTALLSITEARCH) \
2140                 $(INST_BIN) $(DESTINSTALLSITEBIN) \
2141                 $(INST_SCRIPT) $(DESTINSTALLSITESCRIPT) \
2142                 $(INST_MAN1DIR) $(DESTINSTALLSITEMAN1DIR) \
2143                 $(INST_MAN3DIR) $(DESTINSTALLSITEMAN3DIR)
2144         $(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2145                 }.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{
2146
2147 pure_vendor_install ::
2148         $(NOECHO) $(MOD_INSTALL) \
2149                 read }.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
2150                 write }.$self->catfile('$(DESTINSTALLVENDORARCH)','auto','$(FULLEXT)','.packlist').q{ \
2151                 $(INST_LIB) $(DESTINSTALLVENDORLIB) \
2152                 $(INST_ARCHLIB) $(DESTINSTALLVENDORARCH) \
2153                 $(INST_BIN) $(DESTINSTALLVENDORBIN) \
2154                 $(INST_SCRIPT) $(DESTINSTALLVENDORSCRIPT) \
2155                 $(INST_MAN1DIR) $(DESTINSTALLVENDORMAN1DIR) \
2156                 $(INST_MAN3DIR) $(DESTINSTALLVENDORMAN3DIR)
2157
2158 doc_perl_install ::
2159         $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2160         -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
2161         -$(NOECHO) $(DOC_INSTALL) \
2162                 "Module" "$(NAME)" \
2163                 "installed into" "$(INSTALLPRIVLIB)" \
2164                 LINKTYPE "$(LINKTYPE)" \
2165                 VERSION "$(VERSION)" \
2166                 EXE_FILES "$(EXE_FILES)" \
2167                 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
2168
2169 doc_site_install ::
2170         $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2171         -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
2172         -$(NOECHO) $(DOC_INSTALL) \
2173                 "Module" "$(NAME)" \
2174                 "installed into" "$(INSTALLSITELIB)" \
2175                 LINKTYPE "$(LINKTYPE)" \
2176                 VERSION "$(VERSION)" \
2177                 EXE_FILES "$(EXE_FILES)" \
2178                 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
2179
2180 doc_vendor_install ::
2181         $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2182         -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
2183         -$(NOECHO) $(DOC_INSTALL) \
2184                 "Module" "$(NAME)" \
2185                 "installed into" "$(INSTALLVENDORLIB)" \
2186                 LINKTYPE "$(LINKTYPE)" \
2187                 VERSION "$(VERSION)" \
2188                 EXE_FILES "$(EXE_FILES)" \
2189                 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
2190
2191 };
2192
2193     push @m, q{
2194 uninstall :: uninstall_from_$(INSTALLDIRS)dirs
2195         $(NOECHO) $(NOOP)
2196
2197 uninstall_from_perldirs ::
2198         $(NOECHO) $(UNINSTALL) }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{
2199
2200 uninstall_from_sitedirs ::
2201         $(NOECHO) $(UNINSTALL) }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{
2202
2203 uninstall_from_vendordirs ::
2204         $(NOECHO) $(UNINSTALL) }.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{
2205 };
2206
2207     join("",@m);
2208 }
2209
2210 =item installbin (o)
2211
2212 Defines targets to make and to install EXE_FILES.
2213
2214 =cut
2215
2216 sub installbin {
2217     my($self) = shift;
2218
2219     return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
2220     my @exefiles = @{$self->{EXE_FILES}};
2221     return "" unless @exefiles;
2222
2223     @exefiles = map vmsify($_), @exefiles if $Is{VMS};
2224
2225     my %fromto;
2226     for my $from (@exefiles) {
2227         my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
2228
2229         local($_) = $path; # for backwards compatibility
2230         my $to = $self->libscan($path);
2231         print "libscan($from) => '$to'\n" if ($Verbose >=2);
2232
2233         $to = vmsify($to) if $Is{VMS};
2234         $fromto{$from} = $to;
2235     }
2236     my @to   = values %fromto;
2237
2238     my @m;
2239     push(@m, qq{
2240 EXE_FILES = @exefiles
2241
2242 pure_all :: @to
2243         \$(NOECHO) \$(NOOP)
2244
2245 realclean ::
2246 });
2247
2248     # realclean can get rather large.
2249     push @m, map "\t$_\n", $self->split_command('$(RM_F)', @to);
2250     push @m, "\n";
2251
2252
2253     # A target for each exe file.
2254     while (my($from,$to) = each %fromto) {
2255         last unless defined $from;
2256
2257         push @m, sprintf <<'MAKE', $to, $from, $to, $from, $to, $to, $to;
2258 %s : %s $(FIRST_MAKEFILE) $(INST_SCRIPT)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists
2259         $(NOECHO) $(RM_F) %s
2260         $(CP) %s %s
2261         $(FIXIN) %s
2262         -$(NOECHO) $(CHMOD) $(PERM_RWX) %s
2263
2264 MAKE
2265
2266     }
2267
2268     join "", @m;
2269 }
2270
2271
2272 =item linkext (o)
2273
2274 Defines the linkext target which in turn defines the LINKTYPE.
2275
2276 =cut
2277
2278 sub linkext {
2279     my($self, %attribs) = @_;
2280     # LINKTYPE => static or dynamic or ''
2281     my($linktype) = defined $attribs{LINKTYPE} ?
2282       $attribs{LINKTYPE} : '$(LINKTYPE)';
2283     "
2284 linkext :: $linktype
2285         \$(NOECHO) \$(NOOP)
2286 ";
2287 }
2288
2289 =item lsdir
2290
2291 Takes as arguments a directory name and a regular expression. Returns
2292 all entries in the directory that match the regular expression.
2293
2294 =cut
2295
2296 sub lsdir {
2297     my($self) = shift;
2298     my($dir, $regex) = @_;
2299     my(@ls);
2300     my $dh = new DirHandle;
2301     $dh->open($dir || ".") or return ();
2302     @ls = $dh->read;
2303     $dh->close;
2304     @ls = grep(/$regex/, @ls) if $regex;
2305     @ls;
2306 }
2307
2308 =item macro (o)
2309
2310 Simple subroutine to insert the macros defined by the macro attribute
2311 into the Makefile.
2312
2313 =cut
2314
2315 sub macro {
2316     my($self,%attribs) = @_;
2317     my(@m,$key,$val);
2318     while (($key,$val) = each %attribs){
2319         last unless defined $key;
2320         push @m, "$key = $val\n";
2321     }
2322     join "", @m;
2323 }
2324
2325 =item makeaperl (o)
2326
2327 Called by staticmake. Defines how to write the Makefile to produce a
2328 static new perl.
2329
2330 By default the Makefile produced includes all the static extensions in
2331 the perl library. (Purified versions of library files, e.g.,
2332 DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
2333
2334 =cut
2335
2336 sub makeaperl {
2337     my($self, %attribs) = @_;
2338     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
2339         @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
2340     my(@m);
2341     push @m, "
2342 # --- MakeMaker makeaperl section ---
2343 MAP_TARGET    = $target
2344 FULLPERL      = $self->{FULLPERL}
2345 ";
2346     return join '', @m if $self->{PARENT};
2347
2348     my($dir) = join ":", @{$self->{DIR}};
2349
2350     unless ($self->{MAKEAPERL}) {
2351         push @m, q{
2352 $(MAP_TARGET) :: static $(MAKE_APERL_FILE)
2353         $(MAKE) $(USEMAKEFILE) $(MAKE_APERL_FILE) $@
2354
2355 $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE) pm_to_blib
2356         $(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
2357         $(NOECHO) $(PERLRUNINST) \
2358                 Makefile.PL DIR=}, $dir, q{ \
2359                 MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
2360                 MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
2361
2362         foreach (@ARGV){
2363                 if( /\s/ ){
2364                         s/=(.*)/='$1'/;
2365                 }
2366                 push @m, " \\\n\t\t$_";
2367         }
2368 #       push @m, map( " \\\n\t\t$_", @ARGV );
2369         push @m, "\n";
2370
2371         return join '', @m;
2372     }
2373
2374
2375
2376     my($cccmd, $linkcmd, $lperl);
2377
2378
2379     $cccmd = $self->const_cccmd($libperl);
2380     $cccmd =~ s/^CCCMD\s*=\s*//;
2381     $cccmd =~ s/\$\(INC\)/ "-I$self->{PERL_INC}" /;
2382     $cccmd .= " $Config{cccdlflags}"
2383         if ($Config{useshrplib} eq 'true');
2384     $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
2385
2386     # The front matter of the linkcommand...
2387     $linkcmd = join ' ', "\$(CC)",
2388             grep($_, @Config{qw(ldflags ccdlflags)});
2389     $linkcmd =~ s/\s+/ /g;
2390     $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
2391
2392     # Which *.a files could we make use of...
2393     my %static;
2394     require File::Find;
2395     File::Find::find(sub {
2396         return unless m/\Q$self->{LIB_EXT}\E$/;
2397
2398         # Skip perl's libraries.
2399         return if m/^libperl/ or m/^perl\Q$self->{LIB_EXT}\E$/;
2400
2401         # Skip purified versions of libraries 
2402         # (e.g., DynaLoader_pure_p1_c0_032.a)
2403         return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
2404
2405         if( exists $self->{INCLUDE_EXT} ){
2406                 my $found = 0;
2407
2408                 (my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
2409                 $xx =~ s,/?$_,,;
2410                 $xx =~ s,/,::,g;
2411
2412                 # Throw away anything not explicitly marked for inclusion.
2413                 # DynaLoader is implied.
2414                 foreach my $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
2415                         if( $xx eq $incl ){
2416                                 $found++;
2417                                 last;
2418                         }
2419                 }
2420                 return unless $found;
2421         }
2422         elsif( exists $self->{EXCLUDE_EXT} ){
2423                 (my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
2424                 $xx =~ s,/?$_,,;
2425                 $xx =~ s,/,::,g;
2426
2427                 # Throw away anything explicitly marked for exclusion
2428                 foreach my $excl (@{$self->{EXCLUDE_EXT}}){
2429                         return if( $xx eq $excl );
2430                 }
2431         }
2432
2433         # don't include the installed version of this extension. I
2434         # leave this line here, although it is not necessary anymore:
2435         # I patched minimod.PL instead, so that Miniperl.pm won't
2436         # enclude duplicates
2437
2438         # Once the patch to minimod.PL is in the distribution, I can
2439         # drop it
2440         return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}\z:;
2441         use Cwd 'cwd';
2442         $static{cwd() . "/" . $_}++;
2443     }, grep( -d $_, @{$searchdirs || []}) );
2444
2445     # We trust that what has been handed in as argument, will be buildable
2446     $static = [] unless $static;
2447     @static{@{$static}} = (1) x @{$static};
2448
2449     $extra = [] unless $extra && ref $extra eq 'ARRAY';
2450     for (sort keys %static) {
2451         next unless /\Q$self->{LIB_EXT}\E\z/;
2452         $_ = dirname($_) . "/extralibs.ld";
2453         push @$extra, $_;
2454     }
2455
2456     s/^(.*)/"-I$1"/ for @{$perlinc || []};
2457
2458     $target ||= "perl";
2459     $tmp    ||= ".";
2460
2461 # MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
2462 # regenerate the Makefiles, MAP_STATIC and the dependencies for
2463 # extralibs.all are computed correctly
2464     push @m, "
2465 MAP_LINKCMD   = $linkcmd
2466 MAP_PERLINC   = @{$perlinc || []}
2467 MAP_STATIC    = ",
2468 join(" \\\n\t", reverse sort keys %static), "
2469
2470 MAP_PRELIBS   = $Config{perllibs} $Config{cryptlib}
2471 ";
2472
2473     if (defined $libperl) {
2474         ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
2475     }
2476     unless ($libperl && -f $lperl) { # Ilya's code...
2477         my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
2478         $dir = "$self->{PERL_ARCHLIB}/.." if $self->{UNINSTALLED_PERL};
2479         $libperl ||= "libperl$self->{LIB_EXT}";
2480         $libperl   = "$dir/$libperl";
2481         $lperl   ||= "libperl$self->{LIB_EXT}";
2482         $lperl     = "$dir/$lperl";
2483
2484         if (! -f $libperl and ! -f $lperl) {
2485           # We did not find a static libperl. Maybe there is a shared one?
2486           if ($Is{SunOS}) {
2487             $lperl  = $libperl = "$dir/$Config{libperl}";
2488             # SUNOS ld does not take the full path to a shared library
2489             $libperl = '' if $Is{SunOS4};
2490           }
2491         }
2492
2493         print STDOUT "Warning: $libperl not found
2494     If you're going to build a static perl binary, make sure perl is installed
2495     otherwise ignore this warning\n"
2496                 unless (-f $lperl || defined($self->{PERL_SRC}));
2497     }
2498
2499     # SUNOS ld does not take the full path to a shared library
2500     my $llibperl = $libperl ? '$(MAP_LIBPERL)' : '-lperl';
2501
2502     push @m, "
2503 MAP_LIBPERL = $libperl
2504 LLIBPERL    = $llibperl
2505 ";
2506
2507     push @m, '
2508 $(INST_ARCHAUTODIR)/extralibs.all : $(INST_ARCHAUTODIR)$(DFSEP).exists '.join(" \\\n\t", @$extra).'
2509         $(NOECHO) $(RM_F)  $@
2510         $(NOECHO) $(TOUCH) $@
2511 ';
2512
2513     foreach my $catfile (@$extra){
2514         push @m, "\tcat $catfile >> \$\@\n";
2515     }
2516
2517 push @m, "
2518 \$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all
2519         \$(MAP_LINKCMD) -o \$\@ \$(OPTIMIZE) $tmp/perlmain\$(OBJ_EXT) \$(LDFROM) \$(MAP_STATIC) \$(LLIBPERL) `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS)
2520         \$(NOECHO) \$(ECHO) 'To install the new \"\$(MAP_TARGET)\" binary, call'
2521         \$(NOECHO) \$(ECHO) '    \$(MAKE) \$(USEMAKEFILE) $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
2522         \$(NOECHO) \$(ECHO) 'To remove the intermediate files say'
2523         \$(NOECHO) \$(ECHO) '    \$(MAKE) \$(USEMAKEFILE) $makefilename map_clean'
2524
2525 $tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c
2526 ";
2527     push @m, "\t".$self->cd($tmp, qq[$cccmd "-I\$(PERL_INC)" perlmain.c])."\n";
2528
2529     push @m, qq{
2530 $tmp/perlmain.c: $makefilename}, q{
2531         $(NOECHO) $(ECHO) Writing $@
2532         $(NOECHO) $(PERL) $(MAP_PERLINC) "-MExtUtils::Miniperl" \\
2533                 -e "writemain(grep s#.*/auto/##s, split(q| |, q|$(MAP_STATIC)|))" > $@t && $(MV) $@t $@
2534
2535 };
2536     push @m, "\t", q{$(NOECHO) $(PERL) $(INSTALLSCRIPT)/fixpmain
2537 } if (defined (&Dos::UseLFN) && Dos::UseLFN()==0);
2538
2539
2540     push @m, q{
2541 doc_inst_perl :
2542         $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2543         -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
2544         -$(NOECHO) $(DOC_INSTALL) \
2545                 "Perl binary" "$(MAP_TARGET)" \
2546                 MAP_STATIC "$(MAP_STATIC)" \
2547                 MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
2548                 MAP_LIBPERL "$(MAP_LIBPERL)" \
2549                 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
2550
2551 };
2552
2553     push @m, q{
2554 inst_perl : pure_inst_perl doc_inst_perl
2555
2556 pure_inst_perl : $(MAP_TARGET)
2557         }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(DESTINSTALLBIN)','$(MAP_TARGET)').q{
2558
2559 clean :: map_clean
2560
2561 map_clean :
2562         }.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
2563 };
2564
2565     join '', @m;
2566 }
2567
2568 =item makefile (o)
2569
2570 Defines how to rewrite the Makefile.
2571
2572 =cut
2573
2574 sub makefile {
2575     my($self) = shift;
2576     my $m;
2577     # We do not know what target was originally specified so we
2578     # must force a manual rerun to be sure. But as it should only
2579     # happen very rarely it is not a significant problem.
2580     $m = '
2581 $(OBJECT) : $(FIRST_MAKEFILE)
2582
2583 ' if $self->{OBJECT};
2584
2585     my $newer_than_target = $Is{VMS} ? '$(MMS$SOURCE_LIST)' : '$?';
2586     my $mpl_args = join " ", map qq["$_"], @ARGV;
2587
2588     $m .= sprintf <<'MAKE_FRAG', $newer_than_target, $mpl_args;
2589 # We take a very conservative approach here, but it's worth it.
2590 # We move Makefile to Makefile.old here to avoid gnu make looping.
2591 $(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP)
2592         $(NOECHO) $(ECHO) "Makefile out-of-date with respect to %s"
2593         $(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..."
2594         -$(NOECHO) $(RM_F) $(MAKEFILE_OLD)
2595         -$(NOECHO) $(MV)   $(FIRST_MAKEFILE) $(MAKEFILE_OLD)
2596         - $(MAKE) $(USEMAKEFILE) $(MAKEFILE_OLD) clean $(DEV_NULL)
2597         $(PERLRUN) Makefile.PL %s
2598         $(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <=="
2599         $(NOECHO) $(ECHO) "==> Please rerun the $(MAKE) command.  <=="
2600         false
2601
2602 MAKE_FRAG
2603
2604     return $m;
2605 }
2606
2607
2608 =item maybe_command
2609
2610 Returns true, if the argument is likely to be a command.
2611
2612 =cut
2613
2614 sub maybe_command {
2615     my($self,$file) = @_;
2616     return $file if -x $file && ! -d $file;
2617     return;
2618 }
2619
2620
2621 =item needs_linking (o)
2622
2623 Does this module need linking? Looks into subdirectory objects (see
2624 also has_link_code())
2625
2626 =cut
2627
2628 sub needs_linking {
2629     my($self) = shift;
2630
2631     my $caller = (caller(0))[3];
2632     confess("needs_linking called too early") if 
2633       $caller =~ /^ExtUtils::MakeMaker::/;
2634     return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
2635     if ($self->has_link_code or $self->{MAKEAPERL}){
2636         $self->{NEEDS_LINKING} = 1;
2637         return 1;
2638     }
2639     foreach my $child (keys %{$self->{CHILDREN}}) {
2640         if ($self->{CHILDREN}->{$child}->needs_linking) {
2641             $self->{NEEDS_LINKING} = 1;
2642             return 1;
2643         }
2644     }
2645     return $self->{NEEDS_LINKING} = 0;
2646 }
2647
2648
2649 =item parse_abstract
2650
2651 parse a file and return what you think is the ABSTRACT
2652
2653 =cut
2654
2655 sub parse_abstract {
2656     my($self,$parsefile) = @_;
2657     my $result;
2658
2659     local $/ = "\n";
2660     open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
2661     my $inpod = 0;
2662     my $package = $self->{DISTNAME};
2663     $package =~ s/-/::/g;
2664     while (<$fh>) {
2665         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2666         next if !$inpod;
2667         chop;
2668         next unless /^($package\s-\s)(.*)/;
2669         $result = $2;
2670         last;
2671     }
2672     close $fh;
2673
2674     return $result;
2675 }
2676
2677 =item parse_version
2678
2679     my $version = MM->parse_version($file);
2680
2681 Parse a $file and return what $VERSION is set to by the first assignment.
2682 It will return the string "undef" if it can't figure out what $VERSION
2683 is. $VERSION should be for all to see, so C<our $VERSION> or plain $VERSION
2684 are okay, but C<my $VERSION> is not.
2685
2686 parse_version() will try to C<use version> before checking for C<$VERSION> so the following will work.
2687
2688     $VERSION = qv(1.2.3);
2689
2690 =cut
2691
2692 sub parse_version {
2693     my($self,$parsefile) = @_;
2694     my $result;
2695
2696     local $/ = "\n";
2697     local $_;
2698     open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
2699     my $inpod = 0;
2700     while (<$fh>) {
2701         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2702         next if $inpod || /^\s*#/;
2703         chop;
2704         next unless /(?<!\\)([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
2705         my $eval = qq{
2706             package ExtUtils::MakeMaker::_version;
2707             no strict;
2708             BEGIN { eval {
2709                 # Ensure any version() routine which might have leaked
2710                 # into this package has been deleted.  Interferes with
2711                 # version->import()
2712                 undef *version;
2713                 require version;
2714                 "version"->import;
2715             } }
2716
2717             local $1$2;
2718             \$$2=undef;
2719             do {
2720                 $_
2721             };
2722             \$$2;
2723         };
2724         local $^W = 0;
2725         $result = eval($eval);  ## no critic
2726         warn "Could not eval '$eval' in $parsefile: $@" if $@;
2727         last;
2728     }
2729     close $fh;
2730
2731     $result = "undef" unless defined $result;
2732     return $result;
2733 }
2734
2735
2736 =item pasthru (o)
2737
2738 Defines the string that is passed to recursive make calls in
2739 subdirectories.
2740
2741 =cut
2742
2743 sub pasthru {
2744     my($self) = shift;
2745     my(@m);
2746
2747     my(@pasthru);
2748     my($sep) = $Is{VMS} ? ',' : '';
2749     $sep .= "\\\n\t";
2750
2751     foreach my $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE
2752                      PREFIX INSTALL_BASE)
2753                  ) 
2754     {
2755         next unless defined $self->{$key};
2756         push @pasthru, "$key=\"\$($key)\"";
2757     }
2758
2759     foreach my $key (qw(DEFINE INC)) {
2760         next unless defined $self->{$key};
2761         push @pasthru, "PASTHRU_$key=\"\$(PASTHRU_$key)\"";
2762     }
2763
2764     push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
2765     join "", @m;
2766 }
2767
2768 =item perl_script
2769
2770 Takes one argument, a file name, and returns the file name, if the
2771 argument is likely to be a perl script. On MM_Unix this is true for
2772 any ordinary, readable file.
2773
2774 =cut
2775
2776 sub perl_script {
2777     my($self,$file) = @_;
2778     return $file if -r $file && -f _;
2779     return;
2780 }
2781
2782 =item perldepend (o)
2783
2784 Defines the dependency from all *.h files that come with the perl
2785 distribution.
2786
2787 =cut
2788
2789 sub perldepend {
2790     my($self) = shift;
2791     my(@m);
2792
2793     my $make_config = $self->cd('$(PERL_SRC)', '$(MAKE) lib/Config.pm');
2794
2795     push @m, sprintf <<'MAKE_FRAG', $make_config if $self->{PERL_SRC};
2796 # Check for unpropogated config.sh changes. Should never happen.
2797 # We do NOT just update config.h because that is not sufficient.
2798 # An out of date config.h is not fatal but complains loudly!
2799 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
2800         -$(NOECHO) $(ECHO) "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
2801
2802 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
2803         $(NOECHO) $(ECHO) "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
2804         %s
2805 MAKE_FRAG
2806
2807     return join "", @m unless $self->needs_linking;
2808
2809     push @m, q{
2810 PERL_HDRS = \
2811         $(PERL_INC)/EXTERN.h            \
2812         $(PERL_INC)/INTERN.h            \
2813         $(PERL_INC)/XSUB.h              \
2814         $(PERL_INC)/av.h                \
2815         $(PERL_INC)/cc_runtime.h        \
2816         $(PERL_INC)/config.h            \
2817         $(PERL_INC)/cop.h               \
2818         $(PERL_INC)/cv.h                \
2819         $(PERL_INC)/dosish.h            \
2820         $(PERL_INC)/embed.h             \
2821         $(PERL_INC)/embedvar.h          \
2822         $(PERL_INC)/fakethr.h           \
2823         $(PERL_INC)/form.h              \
2824         $(PERL_INC)/gv.h                \
2825         $(PERL_INC)/handy.h             \
2826         $(PERL_INC)/hv.h                \
2827         $(PERL_INC)/intrpvar.h          \
2828         $(PERL_INC)/iperlsys.h          \
2829         $(PERL_INC)/keywords.h          \
2830         $(PERL_INC)/mg.h                \
2831         $(PERL_INC)/nostdio.h           \
2832         $(PERL_INC)/op.h                \
2833         $(PERL_INC)/opcode.h            \
2834         $(PERL_INC)/patchlevel.h        \
2835         $(PERL_INC)/perl.h              \
2836         $(PERL_INC)/perlio.h            \
2837         $(PERL_INC)/perlsdio.h          \
2838         $(PERL_INC)/perlsfio.h          \
2839         $(PERL_INC)/perlvars.h          \
2840         $(PERL_INC)/perly.h             \
2841         $(PERL_INC)/pp.h                \
2842         $(PERL_INC)/pp_proto.h          \
2843         $(PERL_INC)/proto.h             \
2844         $(PERL_INC)/regcomp.h           \
2845         $(PERL_INC)/regexp.h            \
2846         $(PERL_INC)/regnodes.h          \
2847         $(PERL_INC)/scope.h             \
2848         $(PERL_INC)/sv.h                \
2849         $(PERL_INC)/thread.h            \
2850         $(PERL_INC)/unixish.h           \
2851         $(PERL_INC)/util.h
2852
2853 $(OBJECT) : $(PERL_HDRS)
2854 } if $self->{OBJECT};
2855
2856     push @m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
2857
2858     join "\n", @m;
2859 }
2860
2861
2862 =item perm_rw (o)
2863
2864 Returns the attribute C<PERM_RW> or the string C<644>.
2865 Used as the string that is passed
2866 to the C<chmod> command to set the permissions for read/writeable files.
2867 MakeMaker chooses C<644> because it has turned out in the past that
2868 relying on the umask provokes hard-to-track bug reports.
2869 When the return value is used by the perl function C<chmod>, it is
2870 interpreted as an octal value.
2871
2872 =cut
2873
2874 sub perm_rw {
2875     return shift->{PERM_RW};
2876 }
2877
2878 =item perm_rwx (o)
2879
2880 Returns the attribute C<PERM_RWX> or the string C<755>,
2881 i.e. the string that is passed
2882 to the C<chmod> command to set the permissions for executable files.
2883 See also perl_rw.
2884
2885 =cut
2886
2887 sub perm_rwx {
2888     return shift->{PERM_RWX};
2889 }
2890
2891 =item pm_to_blib
2892
2893 Defines target that copies all files in the hash PM to their
2894 destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
2895
2896 =cut
2897
2898 sub pm_to_blib {
2899     my $self = shift;
2900     my($autodir) = $self->catdir('$(INST_LIB)','auto');
2901     my $r = q{
2902 pm_to_blib : $(TO_INST_PM)
2903 };
2904
2905     my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']);
2906 pm_to_blib({\@ARGV}, '$autodir', '\$(PM_FILTER)')
2907 CODE
2908
2909     my @cmds = $self->split_command($pm_to_blib, %{$self->{PM}});
2910
2911     $r .= join '', map { "\t\$(NOECHO) $_\n" } @cmds;
2912     $r .= qq{\t\$(NOECHO) \$(TOUCH) pm_to_blib\n};
2913
2914     return $r;
2915 }
2916
2917 =item post_constants (o)
2918
2919 Returns an empty string per default. Dedicated to overrides from
2920 within Makefile.PL after all constants have been defined.
2921
2922 =cut
2923
2924 sub post_constants{
2925     "";
2926 }
2927
2928 =item post_initialize (o)
2929
2930 Returns an empty string per default. Used in Makefile.PLs to add some
2931 chunk of text to the Makefile after the object is initialized.
2932
2933 =cut
2934
2935 sub post_initialize {
2936     "";
2937 }
2938
2939 =item postamble (o)
2940
2941 Returns an empty string. Can be used in Makefile.PLs to write some
2942 text to the Makefile at the end.
2943
2944 =cut
2945
2946 sub postamble {
2947     "";
2948 }
2949
2950 # transform dot-separated version string into comma-separated quadruple
2951 # examples:  '1.2.3.4.5' => '1,2,3,4'
2952 #            '1.2.3'     => '1,2,3,0'
2953 sub _ppd_version {
2954     my ($self, $string) = @_;
2955     return join ',', ((split /\./, $string), (0) x 4)[0..3];
2956 }
2957
2958 =item ppd
2959
2960 Defines target that creates a PPD (Perl Package Description) file
2961 for a binary distribution.
2962
2963 =cut
2964
2965 sub ppd {
2966     my($self) = @_;
2967
2968     my $pack_ver = $self->_ppd_version($self->{VERSION});
2969
2970     my $abstract = $self->{ABSTRACT} || '';
2971     $abstract =~ s/\n/\\n/sg;
2972     $abstract =~ s/</&lt;/g;
2973     $abstract =~ s/>/&gt;/g;
2974
2975     my $author = $self->{AUTHOR} || '';
2976     $author =~ s/</&lt;/g;
2977     $author =~ s/>/&gt;/g;
2978
2979     my $ppd_xml = sprintf <<'PPD_HTML', $pack_ver, $abstract, $author;
2980 <SOFTPKG NAME="$(DISTNAME)" VERSION="%s">
2981     <TITLE>$(DISTNAME)</TITLE>
2982     <ABSTRACT>%s</ABSTRACT>
2983     <AUTHOR>%s</AUTHOR>
2984 PPD_HTML
2985
2986     $ppd_xml .= "    <IMPLEMENTATION>\n";
2987     if ( $self->{MIN_PERL_VERSION} ) {
2988         my $min_perl_version = $self->_ppd_version($self->{MIN_PERL_VERSION});
2989         $ppd_xml .= sprintf <<'PPD_PERLVERS', $min_perl_version;
2990         <PERLCORE VERSION="%s" />
2991 PPD_PERLVERS
2992
2993     }
2994     foreach my $prereq (sort keys %{$self->{PREREQ_PM}}) {
2995         my $pre_req = $prereq;
2996         $pre_req =~ s/::/-/g;
2997         my $dep_ver = $self->_ppd_version($self->{PREREQ_PM}{$prereq});
2998         $ppd_xml .= sprintf <<'PPD_OUT', $pre_req, $dep_ver;
2999         <DEPENDENCY NAME="%s" VERSION="%s" />
3000 PPD_OUT
3001
3002     }
3003
3004     my $archname = $Config{archname};
3005     if ($] >= 5.008) {
3006         # archname did not change from 5.6 to 5.8, but those versions may
3007         # not be not binary compatible so now we append the part of the
3008         # version that changes when binary compatibility may change
3009         $archname .= "-". substr($Config{version},0,3);
3010     }
3011     $ppd_xml .= sprintf <<'PPD_OUT', $archname;
3012         <OS NAME="$(OSNAME)" />
3013         <ARCHITECTURE NAME="%s" />
3014 PPD_OUT
3015
3016     if ($self->{PPM_INSTALL_SCRIPT}) {
3017         if ($self->{PPM_INSTALL_EXEC}) {
3018             $ppd_xml .= sprintf qq{        <INSTALL EXEC="%s">%s</INSTALL>\n},
3019                   $self->{PPM_INSTALL_EXEC}, $self->{PPM_INSTALL_SCRIPT};
3020         }
3021         else {
3022             $ppd_xml .= sprintf qq{        <INSTALL>%s</INSTALL>\n}, 
3023                   $self->{PPM_INSTALL_SCRIPT};
3024         }
3025     }
3026
3027     my ($bin_location) = $self->{BINARY_LOCATION} || '';
3028     $bin_location =~ s/\\/\\\\/g;
3029
3030     $ppd_xml .= sprintf <<'PPD_XML', $bin_location;
3031         <CODEBASE HREF="%s" />
3032     </IMPLEMENTATION>
3033 </SOFTPKG>
3034 PPD_XML
3035
3036     my @ppd_cmds = $self->echo($ppd_xml, '$(DISTNAME).ppd');
3037
3038     return sprintf <<'PPD_OUT', join "\n\t", @ppd_cmds;
3039 # Creates a PPD (Perl Package Description) for a binary distribution.
3040 ppd :
3041         %s
3042 PPD_OUT
3043
3044 }
3045
3046 =item prefixify
3047
3048   $MM->prefixify($var, $prefix, $new_prefix, $default);
3049
3050 Using either $MM->{uc $var} || $Config{lc $var}, it will attempt to
3051 replace it's $prefix with a $new_prefix.  
3052
3053 Should the $prefix fail to match I<AND> a PREFIX was given as an
3054 argument to WriteMakefile() it will set it to the $new_prefix +
3055 $default.  This is for systems whose file layouts don't neatly fit into
3056 our ideas of prefixes.
3057
3058 This is for heuristics which attempt to create directory structures
3059 that mirror those of the installed perl.
3060
3061 For example:
3062
3063     $MM->prefixify('installman1dir', '/usr', '/home/foo', 'man/man1');
3064
3065 this will attempt to remove '/usr' from the front of the
3066 $MM->{INSTALLMAN1DIR} path (initializing it to $Config{installman1dir}
3067 if necessary) and replace it with '/home/foo'.  If this fails it will
3068 simply use '/home/foo/man/man1'.
3069
3070 =cut
3071
3072 sub prefixify {
3073     my($self,$var,$sprefix,$rprefix,$default) = @_;
3074
3075     my $path = $self->{uc $var} || 
3076                $Config_Override{lc $var} || $Config{lc $var} || '';
3077
3078     $rprefix .= '/' if $sprefix =~ m|/$|;
3079
3080     print STDERR "  prefixify $var => $path\n" if $Verbose >= 2;
3081     print STDERR "    from $sprefix to $rprefix\n" if $Verbose >= 2;
3082
3083     if( $self->{ARGS}{PREFIX} && $self->file_name_is_absolute($path) && 
3084         $path !~ s{^\Q$sprefix\E\b}{$rprefix}s ) 
3085     {
3086
3087         print STDERR "    cannot prefix, using default.\n" if $Verbose >= 2;
3088         print STDERR "    no default!\n" if !$default && $Verbose >= 2;
3089
3090         $path = $self->catdir($rprefix, $default) if $default;
3091     }
3092
3093     print "    now $path\n" if $Verbose >= 2;
3094     return $self->{uc $var} = $path;
3095 }
3096
3097
3098 =item processPL (o)
3099
3100 Defines targets to run *.PL files.
3101
3102 =cut
3103
3104 sub processPL {
3105     my $self = shift;
3106     my $pl_files = $self->{PL_FILES};
3107
3108     return "" unless $pl_files;
3109
3110     my $m = '';
3111     foreach my $plfile (sort keys %$pl_files) {
3112         my $list = ref($pl_files->{$plfile})
3113                      ?  $pl_files->{$plfile}
3114                      : [$pl_files->{$plfile}];
3115
3116         foreach my $target (@$list) {
3117             if( $Is{VMS} ) {
3118                 $plfile = vmsify($self->eliminate_macros($plfile));
3119                 $target = vmsify($self->eliminate_macros($target));
3120             }
3121
3122             # Normally a .PL file runs AFTER pm_to_blib so it can have
3123             # blib in its @INC and load the just built modules.  BUT if
3124             # the generated module is something in $(TO_INST_PM) which
3125             # pm_to_blib depends on then it can't depend on pm_to_blib
3126             # else we have a dependency loop.
3127             my $pm_dep;
3128             my $perlrun;
3129             if( defined $self->{PM}{$target} ) {
3130                 $pm_dep  = '';
3131                 $perlrun = 'PERLRUN';
3132             }
3133             else {
3134                 $pm_dep  = 'pm_to_blib';
3135                 $perlrun = 'PERLRUNINST';
3136             }
3137
3138             $m .= <<MAKE_FRAG;
3139
3140 all :: $target
3141         \$(NOECHO) \$(NOOP)
3142
3143 $target :: $plfile $pm_dep
3144         \$($perlrun) $plfile $target
3145 MAKE_FRAG
3146
3147         }
3148     }
3149
3150     return $m;
3151 }
3152
3153 =item quote_paren
3154
3155 Backslashes parentheses C<()> in command line arguments.
3156 Doesn't handle recursive Makefile C<$(...)> constructs,
3157 but handles simple ones.
3158
3159 =cut
3160
3161 sub quote_paren {
3162     my $arg = shift;
3163     $arg =~ s{\$\((.+?)\)}{\$\\\\($1\\\\)}g;    # protect $(...)
3164     $arg =~ s{(?<!\\)([()])}{\\$1}g;            # quote unprotected
3165     $arg =~ s{\$\\\\\((.+?)\\\\\)}{\$($1)}g;    # unprotect $(...)
3166     return $arg;
3167 }
3168
3169 =item replace_manpage_separator
3170
3171   my $man_name = $MM->replace_manpage_separator($file_path);
3172
3173 Takes the name of a package, which may be a nested package, in the
3174 form 'Foo/Bar.pm' and replaces the slash with C<::> or something else
3175 safe for a man page file name.  Returns the replacement.
3176
3177 =cut
3178
3179 sub replace_manpage_separator {
3180     my($self,$man) = @_;
3181
3182     $man =~ s,/+,::,g;
3183     return $man;
3184 }
3185
3186
3187 =item cd
3188
3189 =cut
3190
3191 sub cd {
3192     my($self, $dir, @cmds) = @_;
3193
3194     # No leading tab and no trailing newline makes for easier embedding
3195     my $make_frag = join "\n\t", map { "cd $dir && $_" } @cmds;
3196
3197     return $make_frag;
3198 }
3199
3200 =item oneliner
3201
3202 =cut
3203
3204 sub oneliner {
3205     my($self, $cmd, $switches) = @_;
3206     $switches = [] unless defined $switches;
3207
3208     # Strip leading and trailing newlines
3209     $cmd =~ s{^\n+}{};
3210     $cmd =~ s{\n+$}{};
3211
3212     my @cmds = split /\n/, $cmd;
3213     $cmd = join " \n\t  -e ", map $self->quote_literal($_), @cmds;
3214     $cmd = $self->escape_newlines($cmd);
3215
3216     $switches = join ' ', @$switches;
3217
3218     return qq{\$(ABSPERLRUN) $switches -e $cmd --};   
3219 }
3220
3221
3222 =item quote_literal
3223
3224 =cut
3225
3226 sub quote_literal {
3227     my($self, $text) = @_;
3228
3229     # I think all we have to quote is single quotes and I think
3230     # this is a safe way to do it.
3231     $text =~ s{'}{'\\''}g;
3232
3233     return "'$text'";
3234 }
3235
3236
3237 =item escape_newlines
3238
3239 =cut
3240
3241 sub escape_newlines {
3242     my($self, $text) = @_;
3243
3244     $text =~ s{\n}{\\\n}g;
3245
3246     return $text;
3247 }
3248
3249
3250 =item max_exec_len
3251
3252 Using POSIX::ARG_MAX.  Otherwise falling back to 4096.
3253
3254 =cut
3255
3256 sub max_exec_len {
3257     my $self = shift;
3258
3259     if (!defined $self->{_MAX_EXEC_LEN}) {
3260         if (my $arg_max = eval { require POSIX;  &POSIX::ARG_MAX }) {
3261             $self->{_MAX_EXEC_LEN} = $arg_max;
3262         }
3263         else {      # POSIX minimum exec size
3264             $self->{_MAX_EXEC_LEN} = 4096;
3265         }
3266     }
3267
3268     return $self->{_MAX_EXEC_LEN};
3269 }
3270
3271
3272 =item static (o)
3273
3274 Defines the static target.
3275
3276 =cut
3277
3278 sub static {
3279 # --- Static Loading Sections ---
3280
3281     my($self) = shift;
3282     '
3283 ## $(INST_PM) has been moved to the all: target.
3284 ## It remains here for awhile to allow for old usage: "make static"
3285 static :: $(FIRST_MAKEFILE) $(INST_STATIC)
3286         $(NOECHO) $(NOOP)
3287 ';
3288 }
3289
3290 =item static_lib (o)
3291
3292 Defines how to produce the *.a (or equivalent) files.
3293
3294 =cut
3295
3296 sub static_lib {
3297     my($self) = @_;
3298     return '' unless $self->has_link_code;
3299
3300     my(@m);
3301     push(@m, <<'END');
3302
3303 $(INST_STATIC) : $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
3304         $(RM_RF) $@
3305 END
3306
3307     # If this extension has its own library (eg SDBM_File)
3308     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
3309     push(@m, <<'MAKE_FRAG') if $self->{MYEXTLIB};
3310         $(CP) $(MYEXTLIB) $@
3311 MAKE_FRAG
3312
3313     my $ar; 
3314     if (exists $self->{FULL_AR} && -x $self->{FULL_AR}) {
3315         # Prefer the absolute pathed ar if available so that PATH
3316         # doesn't confuse us.  Perl itself is built with the full_ar.  
3317         $ar = 'FULL_AR';
3318     } else {
3319         $ar = 'AR';
3320     }
3321     push @m, sprintf <<'MAKE_FRAG', $ar;
3322         $(%s) $(AR_STATIC_ARGS) $@ $(OBJECT) && $(RANLIB) $@
3323         $(CHMOD) $(PERM_RWX) $@
3324         $(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
3325 MAKE_FRAG
3326
3327     # Old mechanism - still available:
3328     push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
3329         $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
3330 MAKE_FRAG
3331
3332     join('', @m);
3333 }
3334
3335 =item staticmake (o)
3336
3337 Calls makeaperl.
3338
3339 =cut
3340
3341 sub staticmake {
3342     my($self, %attribs) = @_;
3343     my(@static);
3344
3345     my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
3346
3347     # And as it's not yet built, we add the current extension
3348     # but only if it has some C code (or XS code, which implies C code)
3349     if (@{$self->{C}}) {
3350         @static = $self->catfile($self->{INST_ARCHLIB},
3351                                  "auto",
3352                                  $self->{FULLEXT},
3353                                  "$self->{BASEEXT}$self->{LIB_EXT}"
3354                                 );
3355     }
3356
3357     # Either we determine now, which libraries we will produce in the
3358     # subdirectories or we do it at runtime of the make.
3359
3360     # We could ask all subdir objects, but I cannot imagine, why it
3361     # would be necessary.
3362
3363     # Instead we determine all libraries for the new perl at
3364     # runtime.
3365     my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
3366
3367     $self->makeaperl(MAKE       => $self->{MAKEFILE},
3368                      DIRS       => \@searchdirs,
3369                      STAT       => \@static,
3370                      INCL       => \@perlinc,
3371                      TARGET     => $self->{MAP_TARGET},
3372                      TMP        => "",
3373                      LIBPERL    => $self->{LIBPERL_A}
3374                     );
3375 }
3376
3377 =item subdir_x (o)
3378
3379 Helper subroutine for subdirs
3380
3381 =cut
3382
3383 sub subdir_x {
3384     my($self, $subdir) = @_;
3385
3386     my $subdir_cmd = $self->cd($subdir, 
3387       '$(MAKE) $(USEMAKEFILE) $(FIRST_MAKEFILE) all $(PASTHRU)'
3388     );
3389     return sprintf <<'EOT', $subdir_cmd;
3390
3391 subdirs ::
3392         $(NOECHO) %s
3393 EOT
3394
3395 }
3396
3397 =item subdirs (o)
3398
3399 Defines targets to process subdirectories.
3400
3401 =cut
3402
3403 sub subdirs {
3404 # --- Sub-directory Sections ---
3405     my($self) = shift;
3406     my(@m);
3407     # This method provides a mechanism to automatically deal with
3408     # subdirectories containing further Makefile.PL scripts.
3409     # It calls the subdir_x() method for each subdirectory.
3410     foreach my $dir (@{$self->{DIR}}){
3411         push(@m, $self->subdir_x($dir));
3412 ####    print "Including $dir subdirectory\n";
3413     }
3414     if (@m){
3415         unshift(@m, "
3416 # The default clean, realclean and test targets in this Makefile
3417 # have automatically been given entries for each subdir.
3418
3419 ");
3420     } else {
3421         push(@m, "\n# none")
3422     }
3423     join('',@m);
3424 }
3425
3426 =item test (o)
3427
3428 Defines the test targets.
3429
3430 =cut
3431
3432 sub test {
3433 # --- Test and Installation Sections ---
3434
3435     my($self, %attribs) = @_;
3436     my $tests = $attribs{TESTS} || '';
3437     if (!$tests && -d 't') {
3438         $tests = $self->find_tests;
3439     }
3440     # note: 'test.pl' name is also hardcoded in init_dirscan()
3441     my(@m);
3442     push(@m,"
3443 TEST_VERBOSE=0
3444 TEST_TYPE=test_\$(LINKTYPE)
3445 TEST_FILE = test.pl
3446 TEST_FILES = $tests
3447 TESTDB_SW = -d
3448
3449 testdb :: testdb_\$(LINKTYPE)
3450
3451 test :: \$(TEST_TYPE) subdirs-test
3452
3453 subdirs-test ::
3454         \$(NOECHO) \$(NOOP)
3455
3456 ");
3457
3458     foreach my $dir (@{ $self->{DIR} }) {
3459         my $test = $self->cd($dir, '$(MAKE) test $(PASTHRU)');
3460
3461         push @m, <<END
3462 subdirs-test ::
3463         \$(NOECHO) $test
3464
3465 END
3466     }
3467
3468     push(@m, "\t\$(NOECHO) \$(ECHO) 'No tests defined for \$(NAME) extension.'\n")
3469         unless $tests or -f "test.pl" or @{$self->{DIR}};
3470     push(@m, "\n");
3471
3472     push(@m, "test_dynamic :: pure_all\n");
3473     push(@m, $self->test_via_harness('$(FULLPERLRUN)', '$(TEST_FILES)')) 
3474       if $tests;
3475     push(@m, $self->test_via_script('$(FULLPERLRUN)', '$(TEST_FILE)')) 
3476       if -f "test.pl";
3477     push(@m, "\n");
3478
3479     push(@m, "testdb_dynamic :: pure_all\n");
3480     push(@m, $self->test_via_script('$(FULLPERLRUN) $(TESTDB_SW)', 
3481                                     '$(TEST_FILE)'));
3482     push(@m, "\n");
3483
3484     # Occasionally we may face this degenerate target:
3485     push @m, "test_ : test_dynamic\n\n";
3486
3487     if ($self->needs_linking()) {
3488         push(@m, "test_static :: pure_all \$(MAP_TARGET)\n");
3489         push(@m, $self->test_via_harness('./$(MAP_TARGET)', '$(TEST_FILES)')) if $tests;
3490         push(@m, $self->test_via_script('./$(MAP_TARGET)', '$(TEST_FILE)')) if -f "test.pl";
3491         push(@m, "\n");
3492         push(@m, "testdb_static :: pure_all \$(MAP_TARGET)\n");
3493         push(@m, $self->test_via_script('./$(MAP_TARGET) $(TESTDB_SW)', '$(TEST_FILE)'));
3494         push(@m, "\n");
3495     } else {
3496         push @m, "test_static :: test_dynamic\n";
3497         push @m, "testdb_static :: testdb_dynamic\n";
3498     }
3499     join("", @m);
3500 }
3501
3502 =item test_via_harness (override)
3503
3504 For some reason which I forget, Unix machines like to have
3505 PERL_DL_NONLAZY set for tests.
3506
3507 =cut
3508
3509 sub test_via_harness {
3510     my($self, $perl, $tests) = @_;
3511     return $self->SUPER::test_via_harness("PERL_DL_NONLAZY=1 $perl", $tests);
3512 }
3513
3514 =item test_via_script (override)
3515
3516 Again, the PERL_DL_NONLAZY thing.
3517
3518 =cut
3519
3520 sub test_via_script {
3521     my($self, $perl, $script) = @_;
3522     return $self->SUPER::test_via_script("PERL_DL_NONLAZY=1 $perl", $script);
3523 }
3524
3525
3526 =item tools_other (o)
3527
3528     my $make_frag = $MM->tools_other;
3529
3530 Returns a make fragment containing definitions for the macros init_others() 
3531 initializes.
3532
3533 =cut
3534
3535 sub tools_other {
3536     my($self) = shift;
3537     my @m;
3538
3539     # We set PM_FILTER as late as possible so it can see all the earlier
3540     # on macro-order sensitive makes such as nmake.
3541     for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH 
3542                       UMASK_NULL DEV_NULL MKPATH EQUALIZE_TIMESTAMP 
3543                       ECHO ECHO_N
3544                       UNINST VERBINST
3545                       MOD_INSTALL DOC_INSTALL UNINSTALL
3546                       WARN_IF_OLD_PACKLIST
3547                       MACROSTART MACROEND
3548                       USEMAKEFILE
3549                       PM_FILTER
3550                       FIXIN
3551                     } ) 
3552     {
3553         next unless defined $self->{$tool};
3554         push @m, "$tool = $self->{$tool}\n";
3555     }
3556
3557     return join "", @m;
3558 }
3559
3560 =item tool_xsubpp (o)
3561
3562 Determines typemaps, xsubpp version, prototype behaviour.
3563
3564 =cut
3565
3566 sub tool_xsubpp {
3567     my($self) = shift;
3568     return "" unless $self->needs_linking;
3569
3570     my $xsdir;
3571     my @xsubpp_dirs = @INC;
3572
3573     # Make sure we pick up the new xsubpp if we're building perl.
3574     unshift @xsubpp_dirs, $self->{PERL_LIB} if $self->{PERL_CORE};
3575
3576     foreach my $dir (@xsubpp_dirs) {
3577         $xsdir = $self->catdir($dir, 'ExtUtils');
3578         if( -r $self->catfile($xsdir, "xsubpp") ) {
3579             last;
3580         }
3581     }
3582
3583     my $tmdir   = File::Spec->catdir($self->{PERL_LIB},"ExtUtils");
3584     my(@tmdeps) = $self->catfile($tmdir,'typemap');
3585     if( $self->{TYPEMAPS} ){
3586         foreach my $typemap (@{$self->{TYPEMAPS}}){
3587             if( ! -f  $typemap ) {
3588                 warn "Typemap $typemap not found.\n";
3589             }
3590             else {
3591                 push(@tmdeps,  $typemap);
3592             }
3593         }
3594     }
3595     push(@tmdeps, "typemap") if -f "typemap";
3596     my(@tmargs) = map("-typemap $_", @tmdeps);
3597     if( exists $self->{XSOPT} ){
3598         unshift( @tmargs, $self->{XSOPT} );
3599     }
3600
3601     if ($Is{VMS}                          &&
3602         $Config{'ldflags'}               && 
3603         $Config{'ldflags'} =~ m!/Debug!i &&
3604         (!exists($self->{XSOPT}) || $self->{XSOPT} !~ /linenumbers/)
3605        ) 
3606     {
3607         unshift(@tmargs,'-nolinenumbers');
3608     }
3609
3610
3611     $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
3612
3613     return qq{
3614 XSUBPPDIR = $xsdir
3615 XSUBPP = \$(XSUBPPDIR)\$(DFSEP)xsubpp
3616 XSUBPPRUN = \$(PERLRUN) \$(XSUBPP)
3617 XSPROTOARG = $self->{XSPROTOARG}
3618 XSUBPPDEPS = @tmdeps \$(XSUBPP)
3619 XSUBPPARGS = @tmargs
3620 XSUBPP_EXTRA_ARGS = 
3621 };
3622 };
3623
3624
3625 =item all_target
3626
3627 Build man pages, too
3628
3629 =cut
3630
3631 sub all_target {
3632     my $self = shift;
3633
3634     return <<'MAKE_EXT';
3635 all :: pure_all manifypods
3636         $(NOECHO) $(NOOP)
3637 MAKE_EXT
3638 }
3639
3640 =item top_targets (o)
3641
3642 Defines the targets all, subdirs, config, and O_FILES
3643
3644 =cut
3645
3646 sub top_targets {
3647 # --- Target Sections ---
3648
3649     my($self) = shift;
3650     my(@m);
3651
3652     push @m, $self->all_target, "\n" unless $self->{SKIPHASH}{'all'};
3653
3654     push @m, '
3655 pure_all :: config pm_to_blib subdirs linkext
3656         $(NOECHO) $(NOOP)
3657
3658 subdirs :: $(MYEXTLIB)
3659         $(NOECHO) $(NOOP)
3660
3661 config :: $(FIRST_MAKEFILE) blibdirs
3662         $(NOECHO) $(NOOP)
3663 ';
3664
3665     push @m, '
3666 $(O_FILES): $(H_FILES)
3667 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
3668
3669     push @m, q{
3670 help :
3671         perldoc ExtUtils::MakeMaker
3672 };
3673
3674     join('',@m);
3675 }
3676
3677 =item writedoc
3678
3679 Obsolete, deprecated method. Not used since Version 5.21.
3680
3681 =cut
3682
3683 sub writedoc {
3684 # --- perllocal.pod section ---
3685     my($self,$what,$name,@attribs)=@_;
3686     my $time = localtime;
3687     print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
3688     print join "\n\n=item *\n\n", map("C<$_>",@attribs);
3689     print "\n\n=back\n\n";
3690 }
3691
3692 =item xs_c (o)
3693
3694 Defines the suffix rules to compile XS files to C.
3695
3696 =cut
3697
3698 sub xs_c {
3699     my($self) = shift;
3700     return '' unless $self->needs_linking();
3701     '
3702 .xs.c:
3703         $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.c
3704 ';
3705 }
3706
3707 =item xs_cpp (o)
3708
3709 Defines the suffix rules to compile XS files to C++.
3710
3711 =cut
3712
3713 sub xs_cpp {
3714     my($self) = shift;
3715     return '' unless $self->needs_linking();
3716     '
3717 .xs.cpp:
3718         $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.cpp
3719 ';
3720 }
3721
3722 =item xs_o (o)
3723
3724 Defines suffix rules to go from XS to object files directly. This is
3725 only intended for broken make implementations.
3726
3727 =cut
3728
3729 sub xs_o {      # many makes are too dumb to use xs_c then c_o
3730     my($self) = shift;
3731     return '' unless $self->needs_linking();
3732     '
3733 .xs$(OBJ_EXT):
3734         $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.c
3735         $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c
3736 ';
3737 }
3738
3739
3740 1;
3741
3742 =back
3743
3744 =head1 SEE ALSO
3745
3746 L<ExtUtils::MakeMaker>
3747
3748 =cut
3749
3750 __END__