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