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