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