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