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