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