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