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