1b4822b475bba209624903c929ddc9c7c91c33d5
[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.5002';
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         $self->{"BUILD${man}PODS"} = 1;
1309
1310         unless ($self->{"${man}PODS"}) {
1311             $self->{"${man}PODS"} = {};
1312             $self->{"BUILD${man}PODS"} = 0 if
1313               $self->{"INSTALL${man}DIR"} =~ /^(none|\s*)$/;
1314         }
1315     }
1316
1317     $self->init_MAN1PODS() if $self->{BUILDMAN1PODS};
1318     $self->init_MAN3PODS() if $self->{BUILDMAN3PODS};
1319 }
1320
1321
1322 sub _has_pod {
1323     my($self, $file) = @_;
1324
1325     local *FH;
1326     my($ispod)=0;
1327     if (open(FH,"<$file")) {
1328         while (<FH>) {
1329             if (/^=(?:head\d+|item|pod)\b/) {
1330                 $ispod=1;
1331                 last;
1332             }
1333         }
1334         close FH;
1335     } else {
1336         # If it doesn't exist yet, we assume, it has pods in it
1337         $ispod = 1;
1338     }
1339
1340     return $ispod;
1341 }
1342
1343
1344 =item init_MAN1PODS
1345
1346 Initializes MAN1PODS from the list of EXE_FILES.
1347
1348 =cut
1349
1350 sub init_MAN1PODS {
1351     my($self) = @_;
1352
1353     if ( exists $self->{EXE_FILES} ) {
1354         foreach my $name (@{$self->{EXE_FILES}}) {
1355             next unless $self->_has_pod($name);
1356
1357             $self->{MAN1PODS}->{$name} =
1358                 $self->catfile("\$(INST_MAN1DIR)", 
1359                                basename($name).".\$(MAN1EXT)");
1360         }
1361     }
1362 }
1363
1364
1365 =item init_MAN3PODS
1366
1367 Initializes MAN3PODS from the list of PM files.
1368
1369 =cut
1370
1371 sub init_MAN3PODS {
1372     my $self = shift;
1373
1374     my %manifypods = (); # we collect the keys first, i.e. the files
1375                          # we have to convert to pod
1376
1377     foreach my $name (keys %{$self->{PM}}) {
1378         if ($name =~ /\.pod\z/ ) {
1379             $manifypods{$name} = $self->{PM}{$name};
1380         } elsif ($name =~ /\.p[ml]\z/ ) {
1381             if( $self->_has_pod($name) ) {
1382                 $manifypods{$name} = $self->{PM}{$name};
1383             }
1384         }
1385     }
1386
1387     my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
1388
1389     # Remove "Configure.pm" and similar, if it's not the only pod listed
1390     # To force inclusion, just name it "Configure.pod", or override 
1391     # MAN3PODS
1392     foreach my $name (keys %manifypods) {
1393         if ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) {
1394             delete $manifypods{$name};
1395             next;
1396         }
1397         my($manpagename) = $name;
1398         $manpagename =~ s/\.p(od|m|l)\z//;
1399         # everything below lib is ok
1400         unless($manpagename =~ s!^\W*($parentlibs_re)\W+!!s) {
1401             $manpagename = $self->catfile(
1402                 split(/::/,$self->{PARENT_NAME}),$manpagename
1403             );
1404         }
1405         $manpagename = $self->replace_manpage_separator($manpagename);
1406         $self->{MAN3PODS}->{$name} =
1407             $self->catfile("\$(INST_MAN3DIR)", "$manpagename.\$(MAN3EXT)");
1408     }
1409 }
1410
1411
1412 =item init_PM
1413
1414 Initializes PMLIBDIRS and PM from PMLIBDIRS.
1415
1416 =cut
1417
1418 sub init_PM {
1419     my $self = shift;
1420
1421     my $pm = $self->{PM};
1422
1423     # Some larger extensions often wish to install a number of *.pm/pl
1424     # files into the library in various locations.
1425
1426     # The attribute PMLIBDIRS holds an array reference which lists
1427     # subdirectories which we should search for library files to
1428     # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ].  We
1429     # recursively search through the named directories (skipping any
1430     # which don't exist or contain Makefile.PL files).
1431
1432     # For each *.pm or *.pl file found $self->libscan() is called with
1433     # the default installation path in $_[1]. The return value of
1434     # libscan defines the actual installation location.  The default
1435     # libscan function simply returns the path.  The file is skipped
1436     # if libscan returns false.
1437
1438     # The default installation location passed to libscan in $_[1] is:
1439     #
1440     #  ./*.pm           => $(INST_LIBDIR)/*.pm
1441     #  ./xyz/...        => $(INST_LIBDIR)/xyz/...
1442     #  ./lib/...        => $(INST_LIB)/...
1443     #
1444     # In this way the 'lib' directory is seen as the root of the actual
1445     # perl library whereas the others are relative to INST_LIBDIR
1446     # (which includes PARENT_NAME). This is a subtle distinction but one
1447     # that's important for nested modules.
1448
1449     unless( $self->{PMLIBDIRS} ) {
1450         if( $Is_VMS ) {
1451             # Avoid logical name vs directory collisions
1452             $self->{PMLIBDIRS} = ['./lib', "./$self->{BASEEXT}"];
1453         }
1454         else {
1455             $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}];
1456         }
1457     }
1458
1459     #only existing directories that aren't in $dir are allowed
1460
1461     # Avoid $_ wherever possible:
1462     # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
1463     my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
1464     @{$self->{PMLIBDIRS}} = ();
1465     my %dir = map { ($_ => $_) } @{$self->{DIR}};
1466     foreach my $pmlibdir (@pmlibdirs) {
1467         -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
1468     }
1469
1470     unless( $self->{PMLIBPARENTDIRS} ) {
1471         @{$self->{PMLIBPARENTDIRS}} = ('lib');
1472     }
1473
1474     if (@{$self->{PMLIBDIRS}}){
1475         print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
1476             if ($Verbose >= 2);
1477         require File::Find;
1478         File::Find::find(sub {
1479             if (-d $_){
1480                 unless ($self->libscan($_)){
1481                     $File::Find::prune = 1;
1482                 }
1483                 return;
1484             }
1485             return if /\#/;
1486             return if /~$/;    # emacs temp files
1487             return if /,v$/;   # RCS files
1488
1489             my $path   = $File::Find::name;
1490             my $prefix = $self->{INST_LIBDIR};
1491             my $striplibpath;
1492
1493             my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
1494             $prefix =  $self->{INST_LIB} 
1495                 if ($striplibpath = $path) =~ s{^(\W*)($parentlibs_re)\W}
1496                                                {$1}i;
1497
1498             my($inst) = $self->catfile($prefix,$striplibpath);
1499             local($_) = $inst; # for backwards compatibility
1500             $inst = $self->libscan($inst);
1501             print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
1502             return unless $inst;
1503             $pm->{$path} = $inst;
1504         }, @{$self->{PMLIBDIRS}});
1505     }
1506 }
1507
1508
1509 =item init_DIRFILESEP
1510
1511 Using / for Unix.  Called by init_main.
1512
1513 =cut
1514
1515 sub init_DIRFILESEP {
1516     my($self) = shift;
1517
1518     $self->{DIRFILESEP} = '/';
1519 }
1520     
1521
1522 =item init_main
1523
1524 Initializes AR, AR_STATIC_ARGS, BASEEXT, CONFIG, DISTNAME, DLBASE,
1525 EXE_EXT, FULLEXT, FULLPERL, FULLPERLRUN, FULLPERLRUNINST, INST_*,
1526 INSTALL*, INSTALLDIRS, LIB_EXT, LIBPERL_A, MAP_TARGET, NAME,
1527 OBJ_EXT, PARENT_NAME, PERL, PERL_ARCHLIB, PERL_INC, PERL_LIB,
1528 PERL_SRC, PERLRUN, PERLRUNINST, PREFIX, VERSION,
1529 VERSION_SYM, XS_VERSION.
1530
1531 =cut
1532
1533 sub init_main {
1534     my($self) = @_;
1535
1536     # --- Initialize Module Name and Paths
1537
1538     # NAME    = Foo::Bar::Oracle
1539     # FULLEXT = Foo/Bar/Oracle
1540     # BASEEXT = Oracle
1541     # PARENT_NAME = Foo::Bar
1542 ### Only UNIX:
1543 ###    ($self->{FULLEXT} =
1544 ###     $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket
1545     $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME});
1546
1547
1548     # Copied from DynaLoader:
1549
1550     my(@modparts) = split(/::/,$self->{NAME});
1551     my($modfname) = $modparts[-1];
1552
1553     # Some systems have restrictions on files names for DLL's etc.
1554     # mod2fname returns appropriate file base name (typically truncated)
1555     # It may also edit @modparts if required.
1556     if (defined &DynaLoader::mod2fname) {
1557         $modfname = &DynaLoader::mod2fname(\@modparts);
1558     }
1559
1560     ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!(?:([\w:]+)::)?(\w+)\z! ;
1561     $self->{PARENT_NAME} ||= '';
1562
1563     if (defined &DynaLoader::mod2fname) {
1564         # As of 5.001m, dl_os2 appends '_'
1565         $self->{DLBASE} = $modfname;
1566     } else {
1567         $self->{DLBASE} = '$(BASEEXT)';
1568     }
1569
1570
1571     # --- Initialize PERL_LIB, PERL_SRC
1572
1573     # *Real* information: where did we get these two from? ...
1574     my $inc_config_dir = dirname($INC{'Config.pm'});
1575     my $inc_carp_dir   = dirname($INC{'Carp.pm'});
1576
1577     unless ($self->{PERL_SRC}){
1578         my($dir);
1579         foreach $dir ($Updir,
1580                   $self->catdir($Updir,$Updir),
1581                   $self->catdir($Updir,$Updir,$Updir),
1582                   $self->catdir($Updir,$Updir,$Updir,$Updir),
1583                   $self->catdir($Updir,$Updir,$Updir,$Updir,$Updir))
1584         {
1585             if (
1586                 -f $self->catfile($dir,"config_h.SH")
1587                 &&
1588                 -f $self->catfile($dir,"perl.h")
1589                 &&
1590                 -f $self->catfile($dir,"lib","Exporter.pm")
1591                ) {
1592                 $self->{PERL_SRC}=$dir ;
1593                 last;
1594             }
1595         }
1596     }
1597
1598     warn "PERL_CORE is set but I can't find your PERL_SRC!\n" if
1599       $self->{PERL_CORE} and !$self->{PERL_SRC};
1600
1601     if ($self->{PERL_SRC}){
1602         $self->{PERL_LIB}     ||= $self->catdir("$self->{PERL_SRC}","lib");
1603
1604         if (defined $Cross::platform) {
1605             $self->{PERL_ARCHLIB} = 
1606               $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform);
1607             $self->{PERL_INC}     = 
1608               $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform, 
1609                                  $Is_Win32?("CORE"):());
1610         }
1611         else {
1612             $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
1613             $self->{PERL_INC}     = ($Is_Win32) ? 
1614               $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
1615         }
1616
1617         # catch a situation that has occurred a few times in the past:
1618         unless (
1619                 -s $self->catfile($self->{PERL_SRC},'cflags')
1620                 or
1621                 $Is_VMS
1622                 &&
1623                 -s $self->catfile($self->{PERL_SRC},'perlshr_attr.opt')
1624                 or
1625                 $Is_Win32
1626                ){
1627             warn qq{
1628 You cannot build extensions below the perl source tree after executing
1629 a 'make clean' in the perl source tree.
1630
1631 To rebuild extensions distributed with the perl source you should
1632 simply Configure (to include those extensions) and then build perl as
1633 normal. After installing perl the source tree can be deleted. It is
1634 not needed for building extensions by running 'perl Makefile.PL'
1635 usually without extra arguments.
1636
1637 It is recommended that you unpack and build additional extensions away
1638 from the perl source tree.
1639 };
1640         }
1641     } else {
1642         # we should also consider $ENV{PERL5LIB} here
1643         my $old = $self->{PERL_LIB} || $self->{PERL_ARCHLIB} || $self->{PERL_INC};
1644         $self->{PERL_LIB}     ||= $Config{privlibexp};
1645         $self->{PERL_ARCHLIB} ||= $Config{archlibexp};
1646         $self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
1647         my $perl_h;
1648
1649         if (not -f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))
1650             and not $old){
1651             # Maybe somebody tries to build an extension with an
1652             # uninstalled Perl outside of Perl build tree
1653             my $lib;
1654             for my $dir (@INC) {
1655               $lib = $dir, last if -e $self->catdir($dir, "Config.pm");
1656             }
1657             if ($lib) {
1658               # Win32 puts its header files in /perl/src/lib/CORE.
1659               # Unix leaves them in /perl/src.
1660               my $inc = $Is_Win32 ? $self->catdir($lib, "CORE" )
1661                                   : dirname $lib;
1662               if (-e $self->catdir($inc, "perl.h")) {
1663                 $self->{PERL_LIB}          = $lib;
1664                 $self->{PERL_ARCHLIB}      = $lib;
1665                 $self->{PERL_INC}          = $inc;
1666                 $self->{UNINSTALLED_PERL}  = 1;
1667                 print STDOUT <<EOP;
1668 ... Detected uninstalled Perl.  Trying to continue.
1669 EOP
1670               }
1671             }
1672         }       
1673     }
1674
1675     # We get SITELIBEXP and SITEARCHEXP directly via
1676     # Get_from_Config. When we are running standard modules, these
1677     # won't matter, we will set INSTALLDIRS to "perl". Otherwise we
1678     # set it to "site". I prefer that INSTALLDIRS be set from outside
1679     # MakeMaker.
1680     $self->{INSTALLDIRS} ||= "site";
1681
1682     $self->{MAN1EXT} ||= $Config{man1ext};
1683     $self->{MAN3EXT} ||= $Config{man3ext};
1684
1685     # Get some stuff out of %Config if we haven't yet done so
1686     print STDOUT "CONFIG must be an array ref\n"
1687         if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
1688     $self->{CONFIG} = [] unless (ref $self->{CONFIG});
1689     push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
1690     push(@{$self->{CONFIG}}, 'shellflags') if $Config{shellflags};
1691     my(%once_only);
1692     foreach my $m (@{$self->{CONFIG}}){
1693         next if $once_only{$m};
1694         print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
1695                 unless exists $Config{$m};
1696         $self->{uc $m} ||= $Config{$m};
1697         $once_only{$m} = 1;
1698     }
1699
1700 # This is too dangerous:
1701 #    if ($^O eq "next") {
1702 #       $self->{AR} = "libtool";
1703 #       $self->{AR_STATIC_ARGS} = "-o";
1704 #    }
1705 # But I leave it as a placeholder
1706
1707     $self->{AR_STATIC_ARGS} ||= "cr";
1708
1709     # These should never be needed
1710     $self->{OBJ_EXT} ||= '.o';
1711     $self->{LIB_EXT} ||= '.a';
1712
1713     $self->{MAP_TARGET} ||= "perl";
1714
1715     $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
1716
1717     # make a simple check if we find Exporter
1718     warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
1719         (Exporter.pm not found)"
1720         unless -f $self->catfile("$self->{PERL_LIB}","Exporter.pm") ||
1721         $self->{NAME} eq "ExtUtils::MakeMaker";
1722 }
1723
1724 =item init_others
1725
1726 Initializes EXTRALIBS, BSLOADLIBS, LDLOADLIBS, LIBS, LD_RUN_PATH, LD,
1727 OBJECT, BOOTDEP, PERLMAINCC, LDFROM, LINKTYPE, SHELL, NOOP,
1728 FIRST_MAKEFILE, MAKEFILE_OLD, NOECHO, RM_F, RM_RF, TEST_F,
1729 TOUCH, CP, MV, CHMOD, UMASK_NULL, ECHO, ECHO_N
1730
1731 =cut
1732
1733 sub init_others {       # --- Initialize Other Attributes
1734     my($self) = shift;
1735
1736     $self->{LD} ||= 'ld';
1737
1738     # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
1739     # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
1740     # undefined. In any case we turn it into an anon array:
1741
1742     # May check $Config{libs} too, thus not empty.
1743     $self->{LIBS} = [$self->{LIBS}] unless ref $self->{LIBS};
1744
1745     $self->{LIBS} = [''] unless @{$self->{LIBS}} && defined $self->{LIBS}[0];
1746     $self->{LD_RUN_PATH} = "";
1747     my($libs);
1748     foreach $libs ( @{$self->{LIBS}} ){
1749         $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
1750         my(@libs) = $self->extliblist($libs);
1751         if ($libs[0] or $libs[1] or $libs[2]){
1752             # LD_RUN_PATH now computed by ExtUtils::Liblist
1753             ($self->{EXTRALIBS},  $self->{BSLOADLIBS}, 
1754              $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
1755             last;
1756         }
1757     }
1758
1759     if ( $self->{OBJECT} ) {
1760         $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
1761     } else {
1762         # init_dirscan should have found out, if we have C files
1763         $self->{OBJECT} = "";
1764         $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
1765     }
1766     $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
1767     $self->{BOOTDEP}  = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
1768     $self->{PERLMAINCC} ||= '$(CC)';
1769     $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
1770
1771     # Sanity check: don't define LINKTYPE = dynamic if we're skipping
1772     # the 'dynamic' section of MM.  We don't have this problem with
1773     # 'static', since we either must use it (%Config says we can't
1774     # use dynamic loading) or the caller asked for it explicitly.
1775     if (!$self->{LINKTYPE}) {
1776        $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
1777                         ? 'static'
1778                         : ($Config{usedl} ? 'dynamic' : 'static');
1779     };
1780
1781     $self->{NOOP}               ||= '$(SHELL) -c true';
1782     $self->{NOECHO}             = '@' unless defined $self->{NOECHO};
1783
1784     $self->{FIRST_MAKEFILE}     ||= $self->{MAKEFILE} || 'Makefile';
1785     $self->{MAKEFILE}           ||= $self->{FIRST_MAKEFILE};
1786     $self->{MAKEFILE_OLD}       ||= $self->{MAKEFILE}.'.old';
1787     $self->{MAKE_APERL_FILE}    ||= $self->{MAKEFILE}.'.aperl';
1788
1789     # Some makes require a wrapper around macros passed in on the command 
1790     # line.
1791     $self->{MACROSTART}         ||= '';
1792     $self->{MACROEND}           ||= '';
1793
1794     # Not everybody uses -f to indicate "use this Makefile instead"
1795     $self->{USEMAKEFILE}        ||= '-f';
1796
1797     $self->{SHELL}              ||= $Config{sh} || '/bin/sh';
1798
1799     $self->{ECHO}       ||= 'echo';
1800     $self->{ECHO_N}     ||= 'echo -n';
1801     $self->{RM_F}       ||= "rm -f";
1802     $self->{RM_RF}      ||= "rm -rf";
1803     $self->{TOUCH}      ||= "touch";
1804     $self->{TEST_F}     ||= "test -f";
1805     $self->{CP}         ||= "cp";
1806     $self->{MV}         ||= "mv";
1807     $self->{CHMOD}      ||= "chmod";
1808     $self->{MKPATH}     ||= '$(ABSPERLRUN) "-MExtUtils::Command" -e mkpath';
1809     $self->{EQUALIZE_TIMESTAMP} ||= 
1810       '$(ABSPERLRUN) "-MExtUtils::Command" -e eqtime';
1811
1812     $self->{UNINST}     ||= 0;
1813     $self->{VERBINST}   ||= 0;
1814     $self->{MOD_INSTALL} ||= 
1815       $self->oneliner(<<'CODE', ['-MExtUtils::Install']);
1816 install({@ARGV}, '$(VERBINST)', 0, '$(UNINST)');
1817 CODE
1818     $self->{DOC_INSTALL}        ||= 
1819       '$(ABSPERLRUN) "-MExtUtils::Command::MM" -e perllocal_install';
1820     $self->{UNINSTALL}          ||= 
1821       '$(ABSPERLRUN) "-MExtUtils::Command::MM" -e uninstall';
1822     $self->{WARN_IF_OLD_PACKLIST} ||= 
1823       '$(ABSPERLRUN) "-MExtUtils::Command::MM" -e warn_if_old_packlist';
1824     $self->{FIXIN}              ||= 
1825       q{$(PERLRUN) "-MExtUtils::MY" -e "MY->fixin(shift)"};
1826
1827     $self->{UMASK_NULL}         ||= "umask 0";
1828     $self->{DEV_NULL}           ||= "> /dev/null 2>&1";
1829
1830     return 1;
1831 }
1832
1833
1834 =item init_linker
1835
1836 Unix has no need of special linker flags.
1837
1838 =cut
1839
1840 sub init_linker {
1841     my($self) = shift;
1842     $self->{PERL_ARCHIVE} ||= '';
1843     $self->{PERL_ARCHIVE_AFTER} ||= '';
1844     $self->{EXPORT_LIST}  ||= '';
1845 }
1846
1847
1848 =begin _protected
1849
1850 =item init_lib2arch
1851
1852     $mm->init_lib2arch
1853
1854 =end _protected
1855
1856 =cut
1857
1858 sub init_lib2arch {
1859     my($self) = shift;
1860
1861     # The user who requests an installation directory explicitly
1862     # should not have to tell us an architecture installation directory
1863     # as well. We look if a directory exists that is named after the
1864     # architecture. If not we take it as a sign that it should be the
1865     # same as the requested installation directory. Otherwise we take
1866     # the found one.
1867     for my $libpair ({l=>"privlib",   a=>"archlib"}, 
1868                      {l=>"sitelib",   a=>"sitearch"},
1869                      {l=>"vendorlib", a=>"vendorarch"},
1870                     )
1871     {
1872         my $lib = "install$libpair->{l}";
1873         my $Lib = uc $lib;
1874         my $Arch = uc "install$libpair->{a}";
1875         if( $self->{$Lib} && ! $self->{$Arch} ){
1876             my($ilib) = $Config{$lib};
1877
1878             $self->prefixify($Arch,$ilib,$self->{$Lib});
1879
1880             unless (-d $self->{$Arch}) {
1881                 print STDOUT "Directory $self->{$Arch} not found\n" 
1882                   if $Verbose;
1883                 $self->{$Arch} = $self->{$Lib};
1884             }
1885             print STDOUT "Defaulting $Arch to $self->{$Arch}\n" if $Verbose;
1886         }
1887     }
1888 }
1889
1890
1891 =item init_PERL
1892
1893     $mm->init_PERL;
1894
1895 Called by init_main.  Sets up ABSPERL, PERL, FULLPERL and all the
1896 *PERLRUN* permutations.
1897
1898     PERL is allowed to be miniperl
1899     FULLPERL must be a complete perl
1900
1901     ABSPERL is PERL converted to an absolute path
1902
1903     *PERLRUN contains everything necessary to run perl, find it's
1904          libraries, etc...
1905
1906     *PERLRUNINST is *PERLRUN + everything necessary to find the
1907          modules being built.
1908
1909 =cut
1910
1911 sub init_PERL {
1912     my($self) = shift;
1913
1914     my @defpath = ();
1915     foreach my $component ($self->{PERL_SRC}, $self->path(), 
1916                            $Config{binexp}) 
1917     {
1918         push @defpath, $component if defined $component;
1919     }
1920
1921     # Build up a set of file names (not command names).
1922     my $thisperl = $self->canonpath($^X);
1923     $thisperl .= $Config{exe_ext} unless 
1924                 # VMS might have a file version # at the end
1925       $Is_VMS ? $thisperl =~ m/$Config{exe_ext}(;\d+)?$/i
1926               : $thisperl =~ m/$Config{exe_ext}$/i;
1927
1928     # We need a relative path to perl when in the core.
1929     $thisperl = $self->abs2rel($thisperl) if $self->{PERL_CORE};
1930
1931     my @perls = ($thisperl);
1932     push @perls, map { "$_$Config{exe_ext}" }
1933                      ('perl', 'perl5', "perl$Config{version}");
1934
1935     # miniperl has priority over all but the cannonical perl when in the
1936     # core.  Otherwise its a last resort.
1937     my $miniperl = "miniperl$Config{exe_ext}";
1938     if( $self->{PERL_CORE} ) {
1939         splice @perls, 1, 0, $miniperl;
1940     }
1941     else {
1942         push @perls, $miniperl;
1943     }
1944
1945     $self->{PERL} ||=
1946         $self->find_perl(5.0, \@perls, \@defpath, $Verbose );
1947     # don't check if perl is executable, maybe they have decided to
1948     # supply switches with perl
1949
1950     # When built for debugging, VMS doesn't create perl.exe but ndbgperl.exe.
1951     my $perl_name = 'perl';
1952     $perl_name = 'ndbgperl' if $Is_VMS && 
1953       defined $Config{usevmsdebug} && $Config{usevmsdebug} eq 'define';
1954
1955     # XXX This logic is flawed.  If "miniperl" is anywhere in the path
1956     # it will get confused.  It should be fixed to work only on the filename.
1957     # Define 'FULLPERL' to be a non-miniperl (used in test: target)
1958     ($self->{FULLPERL} = $self->{PERL}) =~ s/miniperl/$perl_name/i
1959         unless $self->{FULLPERL};
1960
1961     # Little hack to get around VMS's find_perl putting "MCR" in front
1962     # sometimes.
1963     $self->{ABSPERL} = $self->{PERL};
1964     my $has_mcr = $self->{ABSPERL} =~ s/^MCR\s*//;
1965     if( $self->file_name_is_absolute($self->{ABSPERL}) ) {
1966         $self->{ABSPERL} = '$(PERL)';
1967     }
1968     else {
1969         $self->{ABSPERL} = $self->rel2abs($self->{ABSPERL});
1970         $self->{ABSPERL} = 'MCR '.$self->{ABSPERL} if $has_mcr;
1971     }
1972
1973     # Are we building the core?
1974     $self->{PERL_CORE} = $ENV{PERL_CORE} unless exists $self->{PERL_CORE};
1975     $self->{PERL_CORE} = 0               unless defined $self->{PERL_CORE};
1976
1977     # How do we run perl?
1978     foreach my $perl (qw(PERL FULLPERL ABSPERL)) {
1979         my $run  = $perl.'RUN';
1980
1981         $self->{$run}  = "\$($perl)";
1982
1983         # Make sure perl can find itself before it's installed.
1984         $self->{$run} .= q{ "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)"} 
1985           if $self->{UNINSTALLED_PERL} || $self->{PERL_CORE};
1986
1987         $self->{$perl.'RUNINST'} = 
1988           sprintf q{$(%sRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)"}, $perl;
1989     }
1990
1991     return 1;
1992 }
1993
1994
1995 =item init_platform
1996
1997 =item platform_constants
1998
1999 Add MM_Unix_VERSION.
2000
2001 =cut
2002
2003 sub init_platform {
2004     my($self) = shift;
2005
2006     $self->{MM_Unix_VERSION} = $VERSION;
2007     $self->{PERL_MALLOC_DEF} = '-DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc '.
2008                                '-Dfree=Perl_mfree -Drealloc=Perl_realloc '.
2009                                '-Dcalloc=Perl_calloc';
2010
2011 }
2012
2013 sub platform_constants {
2014     my($self) = shift;
2015     my $make_frag = '';
2016
2017     foreach my $macro (qw(MM_Unix_VERSION PERL_MALLOC_DEF))
2018     {
2019         next unless defined $self->{$macro};
2020         $make_frag .= "$macro = $self->{$macro}\n";
2021     }
2022
2023     return $make_frag;
2024 }
2025
2026
2027 =item init_PERM
2028
2029   $mm->init_PERM
2030
2031 Called by init_main.  Initializes PERL_*
2032
2033 =cut
2034
2035 sub init_PERM {
2036     my($self) = shift;
2037
2038     $self->{PERM_RW}  = 644  unless defined $self->{PERM_RW};
2039     $self->{PERM_RWX} = 755  unless defined $self->{PERM_RWX};
2040
2041     return 1;
2042 }
2043
2044
2045 =item init_xs
2046
2047     $mm->init_xs
2048
2049 Sets up macros having to do with XS code.  Currently just INST_STATIC,
2050 INST_DYNAMIC and INST_BOOT.
2051
2052 =cut
2053
2054 sub init_xs {
2055     my $self = shift;
2056
2057     if ($self->has_link_code()) {
2058         $self->{INST_STATIC}  = 
2059           $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT)$(LIB_EXT)');
2060         $self->{INST_DYNAMIC} = 
2061           $self->catfile('$(INST_ARCHAUTODIR)', '$(DLBASE).$(DLEXT)');
2062         $self->{INST_BOOT}    = 
2063           $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT).bs');
2064     } else {
2065         $self->{INST_STATIC}  = '';
2066         $self->{INST_DYNAMIC} = '';
2067         $self->{INST_BOOT}    = '';
2068     }
2069 }    
2070
2071 =item install (o)
2072
2073 Defines the install target.
2074
2075 =cut
2076
2077 sub install {
2078     my($self, %attribs) = @_;
2079     my(@m);
2080
2081     push @m, q{
2082 install :: all pure_install doc_install
2083         $(NOECHO) $(NOOP)
2084
2085 install_perl :: all pure_perl_install doc_perl_install
2086         $(NOECHO) $(NOOP)
2087
2088 install_site :: all pure_site_install doc_site_install
2089         $(NOECHO) $(NOOP)
2090
2091 install_vendor :: all pure_vendor_install doc_vendor_install
2092         $(NOECHO) $(NOOP)
2093
2094 pure_install :: pure_$(INSTALLDIRS)_install
2095         $(NOECHO) $(NOOP)
2096
2097 doc_install :: doc_$(INSTALLDIRS)_install
2098         $(NOECHO) $(NOOP)
2099
2100 pure__install : pure_site_install
2101         $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2102
2103 doc__install : doc_site_install
2104         $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2105
2106 pure_perl_install ::
2107         $(NOECHO) $(MOD_INSTALL) \
2108                 read }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
2109                 write }.$self->catfile('$(DESTINSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
2110                 $(INST_LIB) $(DESTINSTALLPRIVLIB) \
2111                 $(INST_ARCHLIB) $(DESTINSTALLARCHLIB) \
2112                 $(INST_BIN) $(DESTINSTALLBIN) \
2113                 $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \
2114                 $(INST_MAN1DIR) $(DESTINSTALLMAN1DIR) \
2115                 $(INST_MAN3DIR) $(DESTINSTALLMAN3DIR)
2116         $(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2117                 }.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{
2118
2119
2120 pure_site_install ::
2121         $(NOECHO) $(MOD_INSTALL) \
2122                 read }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
2123                 write }.$self->catfile('$(DESTINSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{ \
2124                 $(INST_LIB) $(DESTINSTALLSITELIB) \
2125                 $(INST_ARCHLIB) $(DESTINSTALLSITEARCH) \
2126                 $(INST_BIN) $(DESTINSTALLSITEBIN) \
2127                 $(INST_SCRIPT) $(DESTINSTALLSITESCRIPT) \
2128                 $(INST_MAN1DIR) $(DESTINSTALLSITEMAN1DIR) \
2129                 $(INST_MAN3DIR) $(DESTINSTALLSITEMAN3DIR)
2130         $(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2131                 }.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{
2132
2133 pure_vendor_install ::
2134         $(NOECHO) $(MOD_INSTALL) \
2135                 read }.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
2136                 write }.$self->catfile('$(DESTINSTALLVENDORARCH)','auto','$(FULLEXT)','.packlist').q{ \
2137                 $(INST_LIB) $(DESTINSTALLVENDORLIB) \
2138                 $(INST_ARCHLIB) $(DESTINSTALLVENDORARCH) \
2139                 $(INST_BIN) $(DESTINSTALLVENDORBIN) \
2140                 $(INST_SCRIPT) $(DESTINSTALLVENDORSCRIPT) \
2141                 $(INST_MAN1DIR) $(DESTINSTALLVENDORMAN1DIR) \
2142                 $(INST_MAN3DIR) $(DESTINSTALLVENDORMAN3DIR)
2143
2144 doc_perl_install ::
2145         $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2146         -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
2147         -$(NOECHO) $(DOC_INSTALL) \
2148                 "Module" "$(NAME)" \
2149                 "installed into" "$(INSTALLPRIVLIB)" \
2150                 LINKTYPE "$(LINKTYPE)" \
2151                 VERSION "$(VERSION)" \
2152                 EXE_FILES "$(EXE_FILES)" \
2153                 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
2154
2155 doc_site_install ::
2156         $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2157         -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
2158         -$(NOECHO) $(DOC_INSTALL) \
2159                 "Module" "$(NAME)" \
2160                 "installed into" "$(INSTALLSITELIB)" \
2161                 LINKTYPE "$(LINKTYPE)" \
2162                 VERSION "$(VERSION)" \
2163                 EXE_FILES "$(EXE_FILES)" \
2164                 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
2165
2166 doc_vendor_install ::
2167         $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2168         -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
2169         -$(NOECHO) $(DOC_INSTALL) \
2170                 "Module" "$(NAME)" \
2171                 "installed into" "$(INSTALLVENDORLIB)" \
2172                 LINKTYPE "$(LINKTYPE)" \
2173                 VERSION "$(VERSION)" \
2174                 EXE_FILES "$(EXE_FILES)" \
2175                 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
2176
2177 };
2178
2179     push @m, q{
2180 uninstall :: uninstall_from_$(INSTALLDIRS)dirs
2181         $(NOECHO) $(NOOP)
2182
2183 uninstall_from_perldirs ::
2184         $(NOECHO) $(UNINSTALL) }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{
2185
2186 uninstall_from_sitedirs ::
2187         $(NOECHO) $(UNINSTALL) }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{
2188
2189 uninstall_from_vendordirs ::
2190         $(NOECHO) $(UNINSTALL) }.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{
2191 };
2192
2193     join("",@m);
2194 }
2195
2196 =item installbin (o)
2197
2198 Defines targets to make and to install EXE_FILES.
2199
2200 =cut
2201
2202 sub installbin {
2203     my($self) = shift;
2204
2205     return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
2206     my @exefiles = @{$self->{EXE_FILES}};
2207     return "" unless @exefiles;
2208
2209     @exefiles = map vmsify($_), @exefiles if $Is_VMS;
2210
2211     my %fromto;
2212     for my $from (@exefiles) {
2213         my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
2214
2215         local($_) = $path; # for backwards compatibility
2216         my $to = $self->libscan($path);
2217         print "libscan($from) => '$to'\n" if ($Verbose >=2);
2218
2219         $to = vmsify($to) if $Is_VMS;
2220         $fromto{$from} = $to;
2221     }
2222     my @to   = values %fromto;
2223
2224     my @m;
2225     push(@m, qq{
2226 EXE_FILES = @exefiles
2227
2228 pure_all :: @to
2229         \$(NOECHO) \$(NOOP)
2230
2231 realclean ::
2232 });
2233
2234     # realclean can get rather large.
2235     push @m, map "\t$_\n", $self->split_command('$(RM_F)', @to);
2236     push @m, "\n";
2237
2238
2239     # A target for each exe file.
2240     while (my($from,$to) = each %fromto) {
2241         last unless defined $from;
2242
2243         push @m, sprintf <<'MAKE', $to, $from, $to, $from, $to, $to, $to;
2244 %s : %s $(FIRST_MAKEFILE) $(INST_SCRIPT)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists
2245         $(NOECHO) $(RM_F) %s
2246         $(CP) %s %s
2247         $(FIXIN) %s
2248         -$(NOECHO) $(CHMOD) $(PERM_RWX) %s
2249
2250 MAKE
2251
2252     }
2253
2254     join "", @m;
2255 }
2256
2257
2258 =item linkext (o)
2259
2260 Defines the linkext target which in turn defines the LINKTYPE.
2261
2262 =cut
2263
2264 sub linkext {
2265     my($self, %attribs) = @_;
2266     # LINKTYPE => static or dynamic or ''
2267     my($linktype) = defined $attribs{LINKTYPE} ?
2268       $attribs{LINKTYPE} : '$(LINKTYPE)';
2269     "
2270 linkext :: $linktype
2271         \$(NOECHO) \$(NOOP)
2272 ";
2273 }
2274
2275 =item lsdir
2276
2277 Takes as arguments a directory name and a regular expression. Returns
2278 all entries in the directory that match the regular expression.
2279
2280 =cut
2281
2282 sub lsdir {
2283     my($self) = shift;
2284     my($dir, $regex) = @_;
2285     my(@ls);
2286     my $dh = new DirHandle;
2287     $dh->open($dir || ".") or return ();
2288     @ls = $dh->read;
2289     $dh->close;
2290     @ls = grep(/$regex/, @ls) if $regex;
2291     @ls;
2292 }
2293
2294 =item macro (o)
2295
2296 Simple subroutine to insert the macros defined by the macro attribute
2297 into the Makefile.
2298
2299 =cut
2300
2301 sub macro {
2302     my($self,%attribs) = @_;
2303     my(@m,$key,$val);
2304     while (($key,$val) = each %attribs){
2305         last unless defined $key;
2306         push @m, "$key = $val\n";
2307     }
2308     join "", @m;
2309 }
2310
2311 =item makeaperl (o)
2312
2313 Called by staticmake. Defines how to write the Makefile to produce a
2314 static new perl.
2315
2316 By default the Makefile produced includes all the static extensions in
2317 the perl library. (Purified versions of library files, e.g.,
2318 DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
2319
2320 =cut
2321
2322 sub makeaperl {
2323     my($self, %attribs) = @_;
2324     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
2325         @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
2326     my(@m);
2327     push @m, "
2328 # --- MakeMaker makeaperl section ---
2329 MAP_TARGET    = $target
2330 FULLPERL      = $self->{FULLPERL}
2331 ";
2332     return join '', @m if $self->{PARENT};
2333
2334     my($dir) = join ":", @{$self->{DIR}};
2335
2336     unless ($self->{MAKEAPERL}) {
2337         push @m, q{
2338 $(MAP_TARGET) :: static $(MAKE_APERL_FILE)
2339         $(MAKE) $(USEMAKEFILE) $(MAKE_APERL_FILE) $@
2340
2341 $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE) pm_to_blib
2342         $(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
2343         $(NOECHO) $(PERLRUNINST) \
2344                 Makefile.PL DIR=}, $dir, q{ \
2345                 MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
2346                 MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
2347
2348         foreach (@ARGV){
2349                 if( /\s/ ){
2350                         s/=(.*)/='$1'/;
2351                 }
2352                 push @m, " \\\n\t\t$_";
2353         }
2354 #       push @m, map( " \\\n\t\t$_", @ARGV );
2355         push @m, "\n";
2356
2357         return join '', @m;
2358     }
2359
2360
2361
2362     my($cccmd, $linkcmd, $lperl);
2363
2364
2365     $cccmd = $self->const_cccmd($libperl);
2366     $cccmd =~ s/^CCCMD\s*=\s*//;
2367     $cccmd =~ s/\$\(INC\)/ "-I$self->{PERL_INC}" /;
2368     $cccmd .= " $Config{cccdlflags}"
2369         if ($Config{useshrplib} eq 'true');
2370     $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
2371
2372     # The front matter of the linkcommand...
2373     $linkcmd = join ' ', "\$(CC)",
2374             grep($_, @Config{qw(ldflags ccdlflags)});
2375     $linkcmd =~ s/\s+/ /g;
2376     $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
2377
2378     # Which *.a files could we make use of...
2379     my %static;
2380     require File::Find;
2381     File::Find::find(sub {
2382         return unless m/\Q$self->{LIB_EXT}\E$/;
2383
2384         # Skip perl's libraries.
2385         return if m/^libperl/ or m/^perl\Q$self->{LIB_EXT}\E$/;
2386
2387         # Skip purified versions of libraries 
2388         # (e.g., DynaLoader_pure_p1_c0_032.a)
2389         return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
2390
2391         if( exists $self->{INCLUDE_EXT} ){
2392                 my $found = 0;
2393                 my $incl;
2394                 my $xx;
2395
2396                 ($xx = $File::Find::name) =~ s,.*?/auto/,,s;
2397                 $xx =~ s,/?$_,,;
2398                 $xx =~ s,/,::,g;
2399
2400                 # Throw away anything not explicitly marked for inclusion.
2401                 # DynaLoader is implied.
2402                 foreach $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
2403                         if( $xx eq $incl ){
2404                                 $found++;
2405                                 last;
2406                         }
2407                 }
2408                 return unless $found;
2409         }
2410         elsif( exists $self->{EXCLUDE_EXT} ){
2411                 my $excl;
2412                 my $xx;
2413
2414                 ($xx = $File::Find::name) =~ s,.*?/auto/,,s;
2415                 $xx =~ s,/?$_,,;
2416                 $xx =~ s,/,::,g;
2417
2418                 # Throw away anything explicitly marked for exclusion
2419                 foreach $excl (@{$self->{EXCLUDE_EXT}}){
2420                         return if( $xx eq $excl );
2421                 }
2422         }
2423
2424         # don't include the installed version of this extension. I
2425         # leave this line here, although it is not necessary anymore:
2426         # I patched minimod.PL instead, so that Miniperl.pm won't
2427         # enclude duplicates
2428
2429         # Once the patch to minimod.PL is in the distribution, I can
2430         # drop it
2431         return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}\z:;
2432         use Cwd 'cwd';
2433         $static{cwd() . "/" . $_}++;
2434     }, grep( -d $_, @{$searchdirs || []}) );
2435
2436     # We trust that what has been handed in as argument, will be buildable
2437     $static = [] unless $static;
2438     @static{@{$static}} = (1) x @{$static};
2439
2440     $extra = [] unless $extra && ref $extra eq 'ARRAY';
2441     for (sort keys %static) {
2442         next unless /\Q$self->{LIB_EXT}\E\z/;
2443         $_ = dirname($_) . "/extralibs.ld";
2444         push @$extra, $_;
2445     }
2446
2447     grep(s/^(.*)/"-I$1"/, @{$perlinc || []});
2448
2449     $target ||= "perl";
2450     $tmp    ||= ".";
2451
2452 # MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
2453 # regenerate the Makefiles, MAP_STATIC and the dependencies for
2454 # extralibs.all are computed correctly
2455     push @m, "
2456 MAP_LINKCMD   = $linkcmd
2457 MAP_PERLINC   = @{$perlinc || []}
2458 MAP_STATIC    = ",
2459 join(" \\\n\t", reverse sort keys %static), "
2460
2461 MAP_PRELIBS   = $Config{perllibs} $Config{cryptlib}
2462 ";
2463
2464     if (defined $libperl) {
2465         ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
2466     }
2467     unless ($libperl && -f $lperl) { # Ilya's code...
2468         my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
2469         $dir = "$self->{PERL_ARCHLIB}/.." if $self->{UNINSTALLED_PERL};
2470         $libperl ||= "libperl$self->{LIB_EXT}";
2471         $libperl   = "$dir/$libperl";
2472         $lperl   ||= "libperl$self->{LIB_EXT}";
2473         $lperl     = "$dir/$lperl";
2474
2475         if (! -f $libperl and ! -f $lperl) {
2476           # We did not find a static libperl. Maybe there is a shared one?
2477           if ($Is_SunOS) {
2478             $lperl  = $libperl = "$dir/$Config{libperl}";
2479             # SUNOS ld does not take the full path to a shared library
2480             $libperl = '' if $Is_SunOS4;
2481           }
2482         }
2483
2484         print STDOUT "Warning: $libperl not found
2485     If you're going to build a static perl binary, make sure perl is installed
2486     otherwise ignore this warning\n"
2487                 unless (-f $lperl || defined($self->{PERL_SRC}));
2488     }
2489
2490     # SUNOS ld does not take the full path to a shared library
2491     my $llibperl = $libperl ? '$(MAP_LIBPERL)' : '-lperl';
2492
2493     push @m, "
2494 MAP_LIBPERL = $libperl
2495 LLIBPERL    = $llibperl
2496 ";
2497
2498     push @m, '
2499 $(INST_ARCHAUTODIR)/extralibs.all : $(INST_ARCHAUTODIR)$(DFSEP).exists '.join(" \\\n\t", @$extra).'
2500         $(NOECHO) $(RM_F)  $@
2501         $(NOECHO) $(TOUCH) $@
2502 ';
2503
2504     my $catfile;
2505     foreach $catfile (@$extra){
2506         push @m, "\tcat $catfile >> \$\@\n";
2507     }
2508
2509 push @m, "
2510 \$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all
2511         \$(MAP_LINKCMD) -o \$\@ \$(OPTIMIZE) $tmp/perlmain\$(OBJ_EXT) \$(LDFROM) \$(MAP_STATIC) \$(LLIBPERL) `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS)
2512         \$(NOECHO) \$(ECHO) 'To install the new \"\$(MAP_TARGET)\" binary, call'
2513         \$(NOECHO) \$(ECHO) '    \$(MAKE) \$(USEMAKEFILE) $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
2514         \$(NOECHO) \$(ECHO) 'To remove the intermediate files say'
2515         \$(NOECHO) \$(ECHO) '    \$(MAKE) \$(USEMAKEFILE) $makefilename map_clean'
2516
2517 $tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c
2518 ";
2519     push @m, "\t".$self->cd($tmp, qq[$cccmd "-I\$(PERL_INC)" perlmain.c])."\n";
2520
2521     push @m, qq{
2522 $tmp/perlmain.c: $makefilename}, q{
2523         $(NOECHO) $(ECHO) Writing $@
2524         $(NOECHO) $(PERL) $(MAP_PERLINC) "-MExtUtils::Miniperl" \\
2525                 -e "writemain(grep s#.*/auto/##s, split(q| |, q|$(MAP_STATIC)|))" > $@t && $(MV) $@t $@
2526
2527 };
2528     push @m, "\t", q{$(NOECHO) $(PERL) $(INSTALLSCRIPT)/fixpmain
2529 } if (defined (&Dos::UseLFN) && Dos::UseLFN()==0);
2530
2531
2532     push @m, q{
2533 doc_inst_perl:
2534         $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2535         -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
2536         -$(NOECHO) $(DOC_INSTALL) \
2537                 "Perl binary" "$(MAP_TARGET)" \
2538                 MAP_STATIC "$(MAP_STATIC)" \
2539                 MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
2540                 MAP_LIBPERL "$(MAP_LIBPERL)" \
2541                 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
2542
2543 };
2544
2545     push @m, q{
2546 inst_perl: pure_inst_perl doc_inst_perl
2547
2548 pure_inst_perl: $(MAP_TARGET)
2549         }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(DESTINSTALLBIN)','$(MAP_TARGET)').q{
2550
2551 clean :: map_clean
2552
2553 map_clean :
2554         }.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
2555 };
2556
2557     join '', @m;
2558 }
2559
2560 =item makefile (o)
2561
2562 Defines how to rewrite the Makefile.
2563
2564 =cut
2565
2566 sub makefile {
2567     my($self) = shift;
2568     my $m;
2569     # We do not know what target was originally specified so we
2570     # must force a manual rerun to be sure. But as it should only
2571     # happen very rarely it is not a significant problem.
2572     $m = '
2573 $(OBJECT) : $(FIRST_MAKEFILE)
2574
2575 ' if $self->{OBJECT};
2576
2577     my $newer_than_target = $Is_VMS ? '$(MMS$SOURCE_LIST)' : '$?';
2578     my $mpl_args = join " ", map qq["$_"], @ARGV;
2579
2580     $m .= sprintf <<'MAKE_FRAG', $newer_than_target, $mpl_args;
2581 # We take a very conservative approach here, but it's worth it.
2582 # We move Makefile to Makefile.old here to avoid gnu make looping.
2583 $(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP)
2584         $(NOECHO) $(ECHO) "Makefile out-of-date with respect to %s"
2585         $(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..."
2586         -$(NOECHO) $(RM_F) $(MAKEFILE_OLD)
2587         -$(NOECHO) $(MV)   $(FIRST_MAKEFILE) $(MAKEFILE_OLD)
2588         - $(MAKE) $(USEMAKEFILE) $(MAKEFILE_OLD) clean $(DEV_NULL)
2589         $(PERLRUN) Makefile.PL %s
2590         $(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <=="
2591         $(NOECHO) $(ECHO) "==> Please rerun the $(MAKE) command.  <=="
2592         false
2593
2594 MAKE_FRAG
2595
2596     return $m;
2597 }
2598
2599
2600 =item maybe_command
2601
2602 Returns true, if the argument is likely to be a command.
2603
2604 =cut
2605
2606 sub maybe_command {
2607     my($self,$file) = @_;
2608     return $file if -x $file && ! -d $file;
2609     return;
2610 }
2611
2612
2613 =item needs_linking (o)
2614
2615 Does this module need linking? Looks into subdirectory objects (see
2616 also has_link_code())
2617
2618 =cut
2619
2620 sub needs_linking {
2621     my($self) = shift;
2622     my($child,$caller);
2623     $caller = (caller(0))[3];
2624     confess("needs_linking called too early") if 
2625       $caller =~ /^ExtUtils::MakeMaker::/;
2626     return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
2627     if ($self->has_link_code or $self->{MAKEAPERL}){
2628         $self->{NEEDS_LINKING} = 1;
2629         return 1;
2630     }
2631     foreach $child (keys %{$self->{CHILDREN}}) {
2632         if ($self->{CHILDREN}->{$child}->needs_linking) {
2633             $self->{NEEDS_LINKING} = 1;
2634             return 1;
2635         }
2636     }
2637     return $self->{NEEDS_LINKING} = 0;
2638 }
2639
2640 =item nicetext
2641
2642 misnamed method (will have to be changed). The MM_Unix method just
2643 returns the argument without further processing.
2644
2645 On VMS used to insure that colons marking targets are preceded by
2646 space - most Unix Makes don't need this, but it's necessary under VMS
2647 to distinguish the target delimiter from a colon appearing as part of
2648 a filespec.
2649
2650 =cut
2651
2652 sub nicetext {
2653     my($self,$text) = @_;
2654     $text;
2655 }
2656
2657 =item parse_abstract
2658
2659 parse a file and return what you think is the ABSTRACT
2660
2661 =cut
2662
2663 sub parse_abstract {
2664     my($self,$parsefile) = @_;
2665     my $result;
2666     local *FH;
2667     local $/ = "\n";
2668     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
2669     my $inpod = 0;
2670     my $package = $self->{DISTNAME};
2671     $package =~ s/-/::/g;
2672     while (<FH>) {
2673         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2674         next if !$inpod;
2675         chop;
2676         next unless /^($package\s-\s)(.*)/;
2677         $result = $2;
2678         last;
2679     }
2680     close FH;
2681     return $result;
2682 }
2683
2684 =item parse_version
2685
2686 parse a file and return what you think is $VERSION in this file set to.
2687 It will return the string "undef" if it can't figure out what $VERSION
2688 is. $VERSION should be for all to see, so our $VERSION or plain $VERSION
2689 are okay, but my $VERSION is not.
2690
2691 =cut
2692
2693 sub parse_version {
2694     my($self,$parsefile) = @_;
2695     my $result;
2696     local *FH;
2697     local $/ = "\n";
2698     local $_;
2699     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
2700     my $inpod = 0;
2701     while (<FH>) {
2702         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2703         next if $inpod || /^\s*#/;
2704         chop;
2705         next unless /(?<!\\)([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
2706         my $eval = qq{
2707             package ExtUtils::MakeMaker::_version;
2708             no strict;
2709
2710             local $1$2;
2711             \$$2=undef; do {
2712                 $_
2713             }; \$$2
2714         };
2715         local $^W = 0;
2716         $result = eval($eval);
2717         warn "Could not eval '$eval' in $parsefile: $@" if $@;
2718         last;
2719     }
2720     close FH;
2721
2722     $result = "undef" unless defined $result;
2723     return $result;
2724 }
2725
2726
2727 =item pasthru (o)
2728
2729 Defines the string that is passed to recursive make calls in
2730 subdirectories.
2731
2732 =cut
2733
2734 sub pasthru {
2735     my($self) = shift;
2736     my(@m,$key);
2737
2738     my(@pasthru);
2739     my($sep) = $Is_VMS ? ',' : '';
2740     $sep .= "\\\n\t";
2741
2742     foreach $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE
2743                      PREFIX INSTALL_BASE)
2744                  ) 
2745     {
2746         next unless defined $self->{$key};
2747         push @pasthru, "$key=\"\$($key)\"";
2748     }
2749
2750     foreach $key (qw(DEFINE INC)) {
2751         next unless defined $self->{$key};
2752         push @pasthru, "PASTHRU_$key=\"\$(PASTHRU_$key)\"";
2753     }
2754
2755     push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
2756     join "", @m;
2757 }
2758
2759 =item perl_script
2760
2761 Takes one argument, a file name, and returns the file name, if the
2762 argument is likely to be a perl script. On MM_Unix this is true for
2763 any ordinary, readable file.
2764
2765 =cut
2766
2767 sub perl_script {
2768     my($self,$file) = @_;
2769     return $file if -r $file && -f _;
2770     return;
2771 }
2772
2773 =item perldepend (o)
2774
2775 Defines the dependency from all *.h files that come with the perl
2776 distribution.
2777
2778 =cut
2779
2780 sub perldepend {
2781     my($self) = shift;
2782     my(@m);
2783
2784     my $make_config = $self->cd('$(PERL_SRC)', '$(MAKE) lib/Config.pm');
2785
2786     push @m, sprintf <<'MAKE_FRAG', $make_config if $self->{PERL_SRC};
2787 # Check for unpropogated config.sh changes. Should never happen.
2788 # We do NOT just update config.h because that is not sufficient.
2789 # An out of date config.h is not fatal but complains loudly!
2790 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
2791         -$(NOECHO) $(ECHO) "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
2792
2793 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
2794         $(NOECHO) $(ECHO) "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
2795         %s
2796 MAKE_FRAG
2797
2798     return join "", @m unless $self->needs_linking;
2799
2800     push @m, q{
2801 PERL_HDRS = \
2802         $(PERL_INC)/EXTERN.h            \
2803         $(PERL_INC)/INTERN.h            \
2804         $(PERL_INC)/XSUB.h              \
2805         $(PERL_INC)/av.h                \
2806         $(PERL_INC)/cc_runtime.h        \
2807         $(PERL_INC)/config.h            \
2808         $(PERL_INC)/cop.h               \
2809         $(PERL_INC)/cv.h                \
2810         $(PERL_INC)/dosish.h            \
2811         $(PERL_INC)/embed.h             \
2812         $(PERL_INC)/embedvar.h          \
2813         $(PERL_INC)/fakethr.h           \
2814         $(PERL_INC)/form.h              \
2815         $(PERL_INC)/gv.h                \
2816         $(PERL_INC)/handy.h             \
2817         $(PERL_INC)/hv.h                \
2818         $(PERL_INC)/intrpvar.h          \
2819         $(PERL_INC)/iperlsys.h          \
2820         $(PERL_INC)/keywords.h          \
2821         $(PERL_INC)/mg.h                \
2822         $(PERL_INC)/nostdio.h           \
2823         $(PERL_INC)/op.h                \
2824         $(PERL_INC)/opcode.h            \
2825         $(PERL_INC)/patchlevel.h        \
2826         $(PERL_INC)/perl.h              \
2827         $(PERL_INC)/perlio.h            \
2828         $(PERL_INC)/perlsdio.h          \
2829         $(PERL_INC)/perlsfio.h          \
2830         $(PERL_INC)/perlvars.h          \
2831         $(PERL_INC)/perly.h             \
2832         $(PERL_INC)/pp.h                \
2833         $(PERL_INC)/pp_proto.h          \
2834         $(PERL_INC)/proto.h             \
2835         $(PERL_INC)/regcomp.h           \
2836         $(PERL_INC)/regexp.h            \
2837         $(PERL_INC)/regnodes.h          \
2838         $(PERL_INC)/scope.h             \
2839         $(PERL_INC)/sv.h                \
2840         $(PERL_INC)/thrdvar.h           \
2841         $(PERL_INC)/thread.h            \
2842         $(PERL_INC)/unixish.h           \
2843         $(PERL_INC)/util.h
2844
2845 $(OBJECT) : $(PERL_HDRS)
2846 } if $self->{OBJECT};
2847
2848     push @m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
2849
2850     join "\n", @m;
2851 }
2852
2853
2854 =item perm_rw (o)
2855
2856 Returns the attribute C<PERM_RW> or the string C<644>.
2857 Used as the string that is passed
2858 to the C<chmod> command to set the permissions for read/writeable files.
2859 MakeMaker chooses C<644> because it has turned out in the past that
2860 relying on the umask provokes hard-to-track bug reports.
2861 When the return value is used by the perl function C<chmod>, it is
2862 interpreted as an octal value.
2863
2864 =cut
2865
2866 sub perm_rw {
2867     return shift->{PERM_RW};
2868 }
2869
2870 =item perm_rwx (o)
2871
2872 Returns the attribute C<PERM_RWX> or the string C<755>,
2873 i.e. the string that is passed
2874 to the C<chmod> command to set the permissions for executable files.
2875 See also perl_rw.
2876
2877 =cut
2878
2879 sub perm_rwx {
2880     return shift->{PERM_RWX};
2881 }
2882
2883 =item pm_to_blib
2884
2885 Defines target that copies all files in the hash PM to their
2886 destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
2887
2888 =cut
2889
2890 sub pm_to_blib {
2891     my $self = shift;
2892     my($autodir) = $self->catdir('$(INST_LIB)','auto');
2893     my $r = q{
2894 pm_to_blib : $(TO_INST_PM)
2895 };
2896
2897     my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']);
2898 pm_to_blib({\@ARGV}, '$autodir', '\$(PM_FILTER)')
2899 CODE
2900
2901     my @cmds = $self->split_command($pm_to_blib, %{$self->{PM}});
2902
2903     $r .= join '', map { "\t\$(NOECHO) $_\n" } @cmds;
2904     $r .= qq{\t\$(NOECHO) \$(TOUCH) pm_to_blib\n};
2905
2906     return $r;
2907 }
2908
2909 =item post_constants (o)
2910
2911 Returns an empty string per default. Dedicated to overrides from
2912 within Makefile.PL after all constants have been defined.
2913
2914 =cut
2915
2916 sub post_constants{
2917     "";
2918 }
2919
2920 =item post_initialize (o)
2921
2922 Returns an empty string per default. Used in Makefile.PLs to add some
2923 chunk of text to the Makefile after the object is initialized.
2924
2925 =cut
2926
2927 sub post_initialize {
2928     "";
2929 }
2930
2931 =item postamble (o)
2932
2933 Returns an empty string. Can be used in Makefile.PLs to write some
2934 text to the Makefile at the end.
2935
2936 =cut
2937
2938 sub postamble {
2939     "";
2940 }
2941
2942 =item ppd
2943
2944 Defines target that creates a PPD (Perl Package Description) file
2945 for a binary distribution.
2946
2947 =cut
2948
2949 sub ppd {
2950     my($self) = @_;
2951
2952     my ($pack_ver) = join ",", (split (/\./, $self->{VERSION}), (0)x4)[0..3];
2953
2954     my $abstract = $self->{ABSTRACT} || '';
2955     $abstract =~ s/\n/\\n/sg;
2956     $abstract =~ s/</&lt;/g;
2957     $abstract =~ s/>/&gt;/g;
2958
2959     my $author = $self->{AUTHOR} || '';
2960     $author =~ s/</&lt;/g;
2961     $author =~ s/>/&gt;/g;
2962
2963     my $ppd_xml = sprintf <<'PPD_HTML', $pack_ver, $abstract, $author;
2964 <SOFTPKG NAME="$(DISTNAME)" VERSION="%s">
2965     <TITLE>$(DISTNAME)</TITLE>
2966     <ABSTRACT>%s</ABSTRACT>
2967     <AUTHOR>%s</AUTHOR>
2968 PPD_HTML
2969
2970     $ppd_xml .= "    <IMPLEMENTATION>\n";
2971     foreach my $prereq (sort keys %{$self->{PREREQ_PM}}) {
2972         my $pre_req = $prereq;
2973         $pre_req =~ s/::/-/g;
2974         my ($dep_ver) = join ",", (split (/\./, $self->{PREREQ_PM}{$prereq}), 
2975                                   (0) x 4) [0 .. 3];
2976         $ppd_xml .= sprintf <<'PPD_OUT', $pre_req, $dep_ver;
2977         <DEPENDENCY NAME="%s" VERSION="%s" />
2978 PPD_OUT
2979
2980     }
2981
2982     $ppd_xml .= sprintf <<'PPD_OUT', $Config{archname};
2983         <OS NAME="$(OSNAME)" />
2984         <ARCHITECTURE NAME="%s" />
2985 PPD_OUT
2986
2987     if ($self->{PPM_INSTALL_SCRIPT}) {
2988         if ($self->{PPM_INSTALL_EXEC}) {
2989             $ppd_xml .= sprintf qq{        <INSTALL EXEC="%s">%s</INSTALL>\n},
2990                   $self->{PPM_INSTALL_EXEC}, $self->{PPM_INSTALL_SCRIPT};
2991         }
2992         else {
2993             $ppd_xml .= sprintf qq{        <INSTALL>%s</INSTALL>\n}, 
2994                   $self->{PPM_INSTALL_SCRIPT};
2995         }
2996     }
2997
2998     my ($bin_location) = $self->{BINARY_LOCATION} || '';
2999     $bin_location =~ s/\\/\\\\/g;
3000
3001     $ppd_xml .= sprintf <<'PPD_XML', $bin_location;
3002         <CODEBASE HREF="%s" />
3003     </IMPLEMENTATION>
3004 </SOFTPKG>
3005 PPD_XML
3006
3007     my @ppd_cmds = $self->echo($ppd_xml, '$(DISTNAME).ppd');
3008
3009     return sprintf <<'PPD_OUT', join "\n\t", @ppd_cmds;
3010 # Creates a PPD (Perl Package Description) for a binary distribution.
3011 ppd:
3012         %s
3013 PPD_OUT
3014
3015 }
3016
3017 =item prefixify
3018
3019   $MM->prefixify($var, $prefix, $new_prefix, $default);
3020
3021 Using either $MM->{uc $var} || $Config{lc $var}, it will attempt to
3022 replace it's $prefix with a $new_prefix.  
3023
3024 Should the $prefix fail to match I<AND> a PREFIX was given as an
3025 argument to WriteMakefile() it will set it to the $new_prefix +
3026 $default.  This is for systems whose file layouts don't neatly fit into
3027 our ideas of prefixes.
3028
3029 This is for heuristics which attempt to create directory structures
3030 that mirror those of the installed perl.
3031
3032 For example:
3033
3034     $MM->prefixify('installman1dir', '/usr', '/home/foo', 'man/man1');
3035
3036 this will attempt to remove '/usr' from the front of the
3037 $MM->{INSTALLMAN1DIR} path (initializing it to $Config{installman1dir}
3038 if necessary) and replace it with '/home/foo'.  If this fails it will
3039 simply use '/home/foo/man/man1'.
3040
3041 =cut
3042
3043 sub prefixify {
3044     my($self,$var,$sprefix,$rprefix,$default) = @_;
3045
3046     my $path = $self->{uc $var} || 
3047                $Config_Override{lc $var} || $Config{lc $var} || '';
3048
3049     $rprefix .= '/' if $sprefix =~ m|/$|;
3050
3051     print STDERR "  prefixify $var => $path\n" if $Verbose >= 2;
3052     print STDERR "    from $sprefix to $rprefix\n" if $Verbose >= 2;
3053
3054     if( $self->{ARGS}{PREFIX} && $self->file_name_is_absolute($path) && 
3055         $path !~ s{^\Q$sprefix\E\b}{$rprefix}s ) 
3056     {
3057
3058         print STDERR "    cannot prefix, using default.\n" if $Verbose >= 2;
3059         print STDERR "    no default!\n" if !$default && $Verbose >= 2;
3060
3061         $path = $self->catdir($rprefix, $default) if $default;
3062     }
3063
3064     print "    now $path\n" if $Verbose >= 2;
3065     return $self->{uc $var} = $path;
3066 }
3067
3068
3069 =item processPL (o)
3070
3071 Defines targets to run *.PL files.
3072
3073 =cut
3074
3075 sub processPL {
3076     my $self = shift;
3077     my $pl_files = $self->{PL_FILES};
3078
3079     return "" unless $pl_files;
3080
3081     my $m = '';
3082     foreach my $plfile (sort keys %$pl_files) {
3083         my $list = ref($pl_files->{$plfile})
3084                      ?  $pl_files->{$plfile}
3085                      : [$pl_files->{$plfile}];
3086
3087         foreach my $target (@$list) {
3088             if( $Is_VMS ) {
3089                 $plfile = vmsify($self->eliminate_macros($plfile));
3090                 $target = vmsify($self->eliminate_macros($target));
3091             }
3092
3093             # Normally a .PL file runs AFTER pm_to_blib so it can have
3094             # blib in its @INC and load the just built modules.  BUT if
3095             # the generated module is something in $(TO_INST_PM) which
3096             # pm_to_blib depends on then it can't depend on pm_to_blib
3097             # else we have a dependency loop.
3098             my $pm_dep;
3099             my $perlrun;
3100             if( defined $self->{PM}{$target} ) {
3101                 $pm_dep  = '';
3102                 $perlrun = 'PERLRUN';
3103             }
3104             else {
3105                 $pm_dep  = 'pm_to_blib';
3106                 $perlrun = 'PERLRUNINST';
3107             }
3108
3109             $m .= <<MAKE_FRAG;
3110
3111 all :: $target
3112         \$(NOECHO) \$(NOOP)
3113
3114 $target :: $plfile $pm_dep
3115         \$($perlrun) $plfile $target
3116 MAKE_FRAG
3117
3118         }
3119     }
3120
3121     return $m;
3122 }
3123
3124 =item quote_paren
3125
3126 Backslashes parentheses C<()> in command line arguments.
3127 Doesn't handle recursive Makefile C<$(...)> constructs,
3128 but handles simple ones.
3129
3130 =cut
3131
3132 sub quote_paren {
3133     my $arg = shift;
3134     $arg =~ s{\$\((.+?)\)}{\$\\\\($1\\\\)}g;    # protect $(...)
3135     $arg =~ s{(?<!\\)([()])}{\\$1}g;            # quote unprotected
3136     $arg =~ s{\$\\\\\((.+?)\\\\\)}{\$($1)}g;    # unprotect $(...)
3137     return $arg;
3138 }
3139
3140 =item replace_manpage_separator
3141
3142   my $man_name = $MM->replace_manpage_separator($file_path);
3143
3144 Takes the name of a package, which may be a nested package, in the
3145 form 'Foo/Bar.pm' and replaces the slash with C<::> or something else
3146 safe for a man page file name.  Returns the replacement.
3147
3148 =cut
3149
3150 sub replace_manpage_separator {
3151     my($self,$man) = @_;
3152
3153     $man =~ s,/+,::,g;
3154     return $man;
3155 }
3156
3157
3158 =item cd
3159
3160 =cut
3161
3162 sub cd {
3163     my($self, $dir, @cmds) = @_;
3164
3165     # No leading tab and no trailing newline makes for easier embedding
3166     my $make_frag = join "\n\t", map { "cd $dir && $_" } @cmds;
3167
3168     return $make_frag;
3169 }
3170
3171 =item oneliner
3172
3173 =cut
3174
3175 sub oneliner {
3176     my($self, $cmd, $switches) = @_;
3177     $switches = [] unless defined $switches;
3178
3179     # Strip leading and trailing newlines
3180     $cmd =~ s{^\n+}{};
3181     $cmd =~ s{\n+$}{};
3182
3183     my @cmds = split /\n/, $cmd;
3184     $cmd = join " \n\t  -e ", map $self->quote_literal($_), @cmds;
3185     $cmd = $self->escape_newlines($cmd);
3186
3187     $switches = join ' ', @$switches;
3188
3189     return qq{\$(ABSPERLRUN) $switches -e $cmd --};   
3190 }
3191
3192
3193 =item quote_literal
3194
3195 =cut
3196
3197 sub quote_literal {
3198     my($self, $text) = @_;
3199
3200     # I think all we have to quote is single quotes and I think
3201     # this is a safe way to do it.
3202     $text =~ s{'}{'\\''}g;
3203
3204     return "'$text'";
3205 }
3206
3207
3208 =item escape_newlines
3209
3210 =cut
3211
3212 sub escape_newlines {
3213     my($self, $text) = @_;
3214
3215     $text =~ s{\n}{\\\n}g;
3216
3217     return $text;
3218 }
3219
3220
3221 =item max_exec_len
3222
3223 Using POSIX::ARG_MAX.  Otherwise falling back to 4096.
3224
3225 =cut
3226
3227 sub max_exec_len {
3228     my $self = shift;
3229
3230     if (!defined $self->{_MAX_EXEC_LEN}) {
3231         if (my $arg_max = eval { require POSIX;  &POSIX::ARG_MAX }) {
3232             $self->{_MAX_EXEC_LEN} = $arg_max;
3233         }
3234         else {      # POSIX minimum exec size
3235             $self->{_MAX_EXEC_LEN} = 4096;
3236         }
3237     }
3238
3239     return $self->{_MAX_EXEC_LEN};
3240 }
3241
3242
3243 =item static (o)
3244
3245 Defines the static target.
3246
3247 =cut
3248
3249 sub static {
3250 # --- Static Loading Sections ---
3251
3252     my($self) = shift;
3253     '
3254 ## $(INST_PM) has been moved to the all: target.
3255 ## It remains here for awhile to allow for old usage: "make static"
3256 static :: $(FIRST_MAKEFILE) $(INST_STATIC)
3257         $(NOECHO) $(NOOP)
3258 ';
3259 }
3260
3261 =item static_lib (o)
3262
3263 Defines how to produce the *.a (or equivalent) files.
3264
3265 =cut
3266
3267 sub static_lib {
3268     my($self) = @_;
3269     return '' unless $self->has_link_code;
3270
3271     my(@m);
3272     push(@m, <<'END');
3273
3274 $(INST_STATIC) : $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
3275         $(RM_RF) $@
3276 END
3277
3278     # If this extension has its own library (eg SDBM_File)
3279     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
3280     push(@m, <<'MAKE_FRAG') if $self->{MYEXTLIB};
3281         $(CP) $(MYEXTLIB) $@
3282 MAKE_FRAG
3283
3284     my $ar; 
3285     if (exists $self->{FULL_AR} && -x $self->{FULL_AR}) {
3286         # Prefer the absolute pathed ar if available so that PATH
3287         # doesn't confuse us.  Perl itself is built with the full_ar.  
3288         $ar = 'FULL_AR';
3289     } else {
3290         $ar = 'AR';
3291     }
3292     push @m, sprintf <<'MAKE_FRAG', $ar;
3293         $(%s) $(AR_STATIC_ARGS) $@ $(OBJECT) && $(RANLIB) $@
3294         $(CHMOD) $(PERM_RWX) $@
3295         $(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
3296 MAKE_FRAG
3297
3298     # Old mechanism - still available:
3299     push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
3300         $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
3301 MAKE_FRAG
3302
3303     join('', @m);
3304 }
3305
3306 =item staticmake (o)
3307
3308 Calls makeaperl.
3309
3310 =cut
3311
3312 sub staticmake {
3313     my($self, %attribs) = @_;
3314     my(@static);
3315
3316     my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
3317
3318     # And as it's not yet built, we add the current extension
3319     # but only if it has some C code (or XS code, which implies C code)
3320     if (@{$self->{C}}) {
3321         @static = $self->catfile($self->{INST_ARCHLIB},
3322                                  "auto",
3323                                  $self->{FULLEXT},
3324                                  "$self->{BASEEXT}$self->{LIB_EXT}"
3325                                 );
3326     }
3327
3328     # Either we determine now, which libraries we will produce in the
3329     # subdirectories or we do it at runtime of the make.
3330
3331     # We could ask all subdir objects, but I cannot imagine, why it
3332     # would be necessary.
3333
3334     # Instead we determine all libraries for the new perl at
3335     # runtime.
3336     my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
3337
3338     $self->makeaperl(MAKE       => $self->{MAKEFILE},
3339                      DIRS       => \@searchdirs,
3340                      STAT       => \@static,
3341                      INCL       => \@perlinc,
3342                      TARGET     => $self->{MAP_TARGET},
3343                      TMP        => "",
3344                      LIBPERL    => $self->{LIBPERL_A}
3345                     );
3346 }
3347
3348 =item subdir_x (o)
3349
3350 Helper subroutine for subdirs
3351
3352 =cut
3353
3354 sub subdir_x {
3355     my($self, $subdir) = @_;
3356
3357     my $subdir_cmd = $self->cd($subdir, 
3358       '$(MAKE) $(USEMAKEFILE) $(FIRST_MAKEFILE) all $(PASTHRU)'
3359     );
3360     return sprintf <<'EOT', $subdir_cmd;
3361
3362 subdirs ::
3363         $(NOECHO) %s
3364 EOT
3365
3366 }
3367
3368 =item subdirs (o)
3369
3370 Defines targets to process subdirectories.
3371
3372 =cut
3373
3374 sub subdirs {
3375 # --- Sub-directory Sections ---
3376     my($self) = shift;
3377     my(@m,$dir);
3378     # This method provides a mechanism to automatically deal with
3379     # subdirectories containing further Makefile.PL scripts.
3380     # It calls the subdir_x() method for each subdirectory.
3381     foreach $dir (@{$self->{DIR}}){
3382         push(@m, $self->subdir_x($dir));
3383 ####    print "Including $dir subdirectory\n";
3384     }
3385     if (@m){
3386         unshift(@m, "
3387 # The default clean, realclean and test targets in this Makefile
3388 # have automatically been given entries for each subdir.
3389
3390 ");
3391     } else {
3392         push(@m, "\n# none")
3393     }
3394     join('',@m);
3395 }
3396
3397 =item test (o)
3398
3399 Defines the test targets.
3400
3401 =cut
3402
3403 sub test {
3404 # --- Test and Installation Sections ---
3405
3406     my($self, %attribs) = @_;
3407     my $tests = $attribs{TESTS} || '';
3408     if (!$tests && -d 't') {
3409         $tests = $self->find_tests;
3410     }
3411     # note: 'test.pl' name is also hardcoded in init_dirscan()
3412     my(@m);
3413     push(@m,"
3414 TEST_VERBOSE=0
3415 TEST_TYPE=test_\$(LINKTYPE)
3416 TEST_FILE = test.pl
3417 TEST_FILES = $tests
3418 TESTDB_SW = -d
3419
3420 testdb :: testdb_\$(LINKTYPE)
3421
3422 test :: \$(TEST_TYPE)
3423 ");
3424
3425     foreach my $dir (@{ $self->{DIR} }) {
3426         my $test = $self->oneliner(sprintf <<'CODE', $dir);
3427 chdir '%s';  
3428 system '$(MAKE) test $(PASTHRU)' 
3429     if -f '$(FIRST_MAKEFILE)';
3430 CODE
3431
3432         push(@m, "\t\$(NOECHO) $test\n");
3433     }
3434
3435     push(@m, "\t\$(NOECHO) \$(ECHO) 'No tests defined for \$(NAME) extension.'\n")
3436         unless $tests or -f "test.pl" or @{$self->{DIR}};
3437     push(@m, "\n");
3438
3439     push(@m, "test_dynamic :: pure_all\n");
3440     push(@m, $self->test_via_harness('$(FULLPERLRUN)', '$(TEST_FILES)')) 
3441       if $tests;
3442     push(@m, $self->test_via_script('$(FULLPERLRUN)', '$(TEST_FILE)')) 
3443       if -f "test.pl";
3444     push(@m, "\n");
3445
3446     push(@m, "testdb_dynamic :: pure_all\n");
3447     push(@m, $self->test_via_script('$(FULLPERLRUN) $(TESTDB_SW)', 
3448                                     '$(TEST_FILE)'));
3449     push(@m, "\n");
3450
3451     # Occasionally we may face this degenerate target:
3452     push @m, "test_ : test_dynamic\n\n";
3453
3454     if ($self->needs_linking()) {
3455         push(@m, "test_static :: pure_all \$(MAP_TARGET)\n");
3456         push(@m, $self->test_via_harness('./$(MAP_TARGET)', '$(TEST_FILES)')) if $tests;
3457         push(@m, $self->test_via_script('./$(MAP_TARGET)', '$(TEST_FILE)')) if -f "test.pl";
3458         push(@m, "\n");
3459         push(@m, "testdb_static :: pure_all \$(MAP_TARGET)\n");
3460         push(@m, $self->test_via_script('./$(MAP_TARGET) $(TESTDB_SW)', '$(TEST_FILE)'));
3461         push(@m, "\n");
3462     } else {
3463         push @m, "test_static :: test_dynamic\n";
3464         push @m, "testdb_static :: testdb_dynamic\n";
3465     }
3466     join("", @m);
3467 }
3468
3469 =item test_via_harness (override)
3470
3471 For some reason which I forget, Unix machines like to have
3472 PERL_DL_NONLAZY set for tests.
3473
3474 =cut
3475
3476 sub test_via_harness {
3477     my($self, $perl, $tests) = @_;
3478     return $self->SUPER::test_via_harness("PERL_DL_NONLAZY=1 $perl", $tests);
3479 }
3480
3481 =item test_via_script (override)
3482
3483 Again, the PERL_DL_NONLAZY thing.
3484
3485 =cut
3486
3487 sub test_via_script {
3488     my($self, $perl, $script) = @_;
3489     return $self->SUPER::test_via_script("PERL_DL_NONLAZY=1 $perl", $script);
3490 }
3491
3492
3493 =item tools_other (o)
3494
3495     my $make_frag = $MM->tools_other;
3496
3497 Returns a make fragment containing definitions for the macros init_others() 
3498 initializes.
3499
3500 =cut
3501
3502 sub tools_other {
3503     my($self) = shift;
3504     my @m;
3505
3506     # We set PM_FILTER as late as possible so it can see all the earlier
3507     # on macro-order sensitive makes such as nmake.
3508     for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH 
3509                       UMASK_NULL DEV_NULL MKPATH EQUALIZE_TIMESTAMP 
3510                       ECHO ECHO_N
3511                       UNINST VERBINST
3512                       MOD_INSTALL DOC_INSTALL UNINSTALL
3513                       WARN_IF_OLD_PACKLIST
3514                       MACROSTART MACROEND
3515                       USEMAKEFILE
3516                       PM_FILTER
3517                       FIXIN
3518                     } ) 
3519     {
3520         next unless defined $self->{$tool};
3521         push @m, "$tool = $self->{$tool}\n";
3522     }
3523
3524     return join "", @m;
3525 }
3526
3527 =item tool_xsubpp (o)
3528
3529 Determines typemaps, xsubpp version, prototype behaviour.
3530
3531 =cut
3532
3533 sub tool_xsubpp {
3534     my($self) = shift;
3535     return "" unless $self->needs_linking;
3536
3537     my $xsdir;
3538     my @xsubpp_dirs = @INC;
3539
3540     # Make sure we pick up the new xsubpp if we're building perl.
3541     unshift @xsubpp_dirs, $self->{PERL_LIB} if $self->{PERL_CORE};
3542
3543     foreach my $dir (@xsubpp_dirs) {
3544         $xsdir = $self->catdir($dir, 'ExtUtils');
3545         if( -r $self->catfile($xsdir, "xsubpp") ) {
3546             last;
3547         }
3548     }
3549
3550     my $tmdir   = File::Spec->catdir($self->{PERL_LIB},"ExtUtils");
3551     my(@tmdeps) = $self->catfile($tmdir,'typemap');
3552     if( $self->{TYPEMAPS} ){
3553         my $typemap;
3554         foreach $typemap (@{$self->{TYPEMAPS}}){
3555                 if( ! -f  $typemap ){
3556                         warn "Typemap $typemap not found.\n";
3557                 }
3558                 else{
3559                         push(@tmdeps,  $typemap);
3560                 }
3561         }
3562     }
3563     push(@tmdeps, "typemap") if -f "typemap";
3564     my(@tmargs) = map("-typemap $_", @tmdeps);
3565     if( exists $self->{XSOPT} ){
3566         unshift( @tmargs, $self->{XSOPT} );
3567     }
3568
3569     if ($Is_VMS                          &&
3570         $Config{'ldflags'}               && 
3571         $Config{'ldflags'} =~ m!/Debug!i &&
3572         (!exists($self->{XSOPT}) || $self->{XSOPT} !~ /linenumbers/)
3573        ) 
3574     {
3575         unshift(@tmargs,'-nolinenumbers');
3576     }
3577
3578
3579     $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
3580
3581     return qq{
3582 XSUBPPDIR = $xsdir
3583 XSUBPP = \$(XSUBPPDIR)\$(DFSEP)xsubpp
3584 XSUBPPRUN = \$(PERLRUN) \$(XSUBPP)
3585 XSPROTOARG = $self->{XSPROTOARG}
3586 XSUBPPDEPS = @tmdeps \$(XSUBPP)
3587 XSUBPPARGS = @tmargs
3588 XSUBPP_EXTRA_ARGS = 
3589 };
3590 };
3591
3592
3593 =item all_target
3594
3595 Build man pages, too
3596
3597 =cut
3598
3599 sub all_target {
3600     my $self = shift;
3601
3602     return <<'MAKE_EXT';
3603 all :: pure_all manifypods
3604         $(NOECHO) $(NOOP)
3605 MAKE_EXT
3606 }
3607
3608 =item top_targets (o)
3609
3610 Defines the targets all, subdirs, config, and O_FILES
3611
3612 =cut
3613
3614 sub top_targets {
3615 # --- Target Sections ---
3616
3617     my($self) = shift;
3618     my(@m);
3619
3620     push @m, $self->all_target, "\n" unless $self->{SKIPHASH}{'all'};
3621
3622     push @m, '
3623 pure_all :: config pm_to_blib subdirs linkext
3624         $(NOECHO) $(NOOP)
3625
3626 subdirs :: $(MYEXTLIB)
3627         $(NOECHO) $(NOOP)
3628
3629 config :: $(FIRST_MAKEFILE) blibdirs
3630         $(NOECHO) $(NOOP)
3631 ';
3632
3633     push @m, '
3634 $(O_FILES): $(H_FILES)
3635 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
3636
3637     push @m, q{
3638 help :
3639         perldoc ExtUtils::MakeMaker
3640 };
3641
3642     join('',@m);
3643 }
3644
3645 =item writedoc
3646
3647 Obsolete, deprecated method. Not used since Version 5.21.
3648
3649 =cut
3650
3651 sub writedoc {
3652 # --- perllocal.pod section ---
3653     my($self,$what,$name,@attribs)=@_;
3654     my $time = localtime;
3655     print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
3656     print join "\n\n=item *\n\n", map("C<$_>",@attribs);
3657     print "\n\n=back\n\n";
3658 }
3659
3660 =item xs_c (o)
3661
3662 Defines the suffix rules to compile XS files to C.
3663
3664 =cut
3665
3666 sub xs_c {
3667     my($self) = shift;
3668     return '' unless $self->needs_linking();
3669     '
3670 .xs.c:
3671         $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.c
3672 ';
3673 }
3674
3675 =item xs_cpp (o)
3676
3677 Defines the suffix rules to compile XS files to C++.
3678
3679 =cut
3680
3681 sub xs_cpp {
3682     my($self) = shift;
3683     return '' unless $self->needs_linking();
3684     '
3685 .xs.cpp:
3686         $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.cpp
3687 ';
3688 }
3689
3690 =item xs_o (o)
3691
3692 Defines suffix rules to go from XS to object files directly. This is
3693 only intended for broken make implementations.
3694
3695 =cut
3696
3697 sub xs_o {      # many makes are too dumb to use xs_c then c_o
3698     my($self) = shift;
3699     return '' unless $self->needs_linking();
3700     '
3701 .xs$(OBJ_EXT):
3702         $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.c
3703         $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c
3704 ';
3705 }
3706
3707
3708 1;
3709
3710 =back
3711
3712 =head1 SEE ALSO
3713
3714 L<ExtUtils::MakeMaker>
3715
3716 =cut
3717
3718 __END__