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