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