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