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