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