8e61fe07035efda0a22e1a60f299de790a7da16e
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Unix.pm
1 package ExtUtils::MM_Unix;
2
3 use Exporter ();
4 use Config;
5 use File::Basename qw(basename dirname fileparse);
6 use DirHandle;
7 use strict;
8 use vars qw($VERSION $Is_Mac $Is_OS2 $Is_VMS $Is_Win32 $Is_Dos
9             $Verbose %pm %static $Xsubpp_Version);
10
11 $VERSION = substr q$Revision: 1.118 $, 10;
12 # $Id: MM_Unix.pm,v 1.118 1997/08/01 09:42:52 k Exp $
13
14 Exporter::import('ExtUtils::MakeMaker',
15         qw( $Verbose &neatvalue));
16
17 $Is_OS2 = $^O eq 'os2';
18 $Is_Mac = $^O eq 'MacOS';
19 $Is_Win32 = $^O eq 'MSWin32';
20 $Is_Dos = $^O eq 'dos';
21
22 if ($Is_VMS = $^O eq 'VMS') {
23     require VMS::Filespec;
24     import VMS::Filespec qw( &vmsify );
25 }
26
27 =head1 NAME
28
29 ExtUtils::MM_Unix - methods used by ExtUtils::MakeMaker
30
31 =head1 SYNOPSIS
32
33 C<require ExtUtils::MM_Unix;>
34
35 =head1 DESCRIPTION
36
37 The methods provided by this package are designed to be used in
38 conjunction with ExtUtils::MakeMaker. When MakeMaker writes a
39 Makefile, it creates one or more objects that inherit their methods
40 from a package C<MM>. MM itself doesn't provide any methods, but it
41 ISA ExtUtils::MM_Unix class. The inheritance tree of MM lets operating
42 specific packages take the responsibility for all the methods provided
43 by MM_Unix. We are trying to reduce the number of the necessary
44 overrides by defining rather primitive operations within
45 ExtUtils::MM_Unix.
46
47 If you are going to write a platform specific MM package, please try
48 to limit the necessary overrides to primitive methods, and if it is not
49 possible to do so, let's work out how to achieve that gain.
50
51 If you are overriding any of these methods in your Makefile.PL (in the
52 MY class), please report that to the makemaker mailing list. We are
53 trying to minimize the necessary method overrides and switch to data
54 driven Makefile.PLs wherever possible. In the long run less methods
55 will be overridable via the MY class.
56
57 =head1 METHODS
58
59 The following description of methods is still under
60 development. Please refer to the code for not suitably documented
61 sections and complain loudly to the makemaker mailing list.
62
63 Not all of the methods below are overridable in a
64 Makefile.PL. Overridable methods are marked as (o). All methods are
65 overridable by a platform specific MM_*.pm file (See
66 L<ExtUtils::MM_VMS>) and L<ExtUtils::MM_OS2>).
67
68 =head2 Preloaded methods
69
70 =over 2
71
72 =item canonpath
73
74 No physical check on the filesystem, but a logical cleanup of a
75 path. On UNIX eliminated successive slashes and successive "/.".
76
77 =cut
78
79 sub canonpath {
80     my($self,$path) = @_;
81     $path =~ s|/+|/|g ;                            # xx////xx  -> xx/xx
82     $path =~ s|(/\.)+/|/|g ;                       # xx/././xx -> xx/xx
83     $path =~ s|^(\./)+|| unless $path eq "./";     # ./xx      -> xx
84     $path =~ s|/$|| unless $path eq "/";           # xx/       -> xx
85     $path;
86 }
87
88 =item catdir
89
90 Concatenate two or more directory names to form a complete path ending
91 with a directory. But remove the trailing slash from the resulting
92 string, because it doesn't look good, isn't necessary and confuses
93 OS2. Of course, if this is the root directory, don't cut off the
94 trailing slash :-)
95
96 =cut
97
98 # ';
99
100 sub catdir {
101     my $self = shift @_;
102     my @args = @_;
103     for (@args) {
104         # append a slash to each argument unless it has one there
105         $_ .= "/" if $_ eq '' or substr($_,-1) ne "/";
106     }
107     $self->canonpath(join('', @args));
108 }
109
110 =item catfile
111
112 Concatenate one or more directory names and a filename to form a
113 complete path ending with a filename
114
115 =cut
116
117 sub catfile {
118     my $self = shift @_;
119     my $file = pop @_;
120     return $self->canonpath($file) unless @_;
121     my $dir = $self->catdir(@_);
122     for ($dir) {
123         $_ .= "/" unless substr($_,length($_)-1,1) eq "/";
124     }
125     return $self->canonpath($dir.$file);
126 }
127
128 =item curdir
129
130 Returns a string representing of the current directory.  "." on UNIX.
131
132 =cut
133
134 sub curdir {
135     return "." ;
136 }
137
138 =item rootdir
139
140 Returns a string representing of the root directory.  "/" on UNIX.
141
142 =cut
143
144 sub rootdir {
145     return "/";
146 }
147
148 =item updir
149
150 Returns a string representing of the parent directory.  ".." on UNIX.
151
152 =cut
153
154 sub updir {
155     return "..";
156 }
157
158 sub ExtUtils::MM_Unix::c_o ;
159 sub ExtUtils::MM_Unix::clean ;
160 sub ExtUtils::MM_Unix::const_cccmd ;
161 sub ExtUtils::MM_Unix::const_config ;
162 sub ExtUtils::MM_Unix::const_loadlibs ;
163 sub ExtUtils::MM_Unix::constants ;
164 sub ExtUtils::MM_Unix::depend ;
165 sub ExtUtils::MM_Unix::dir_target ;
166 sub ExtUtils::MM_Unix::dist ;
167 sub ExtUtils::MM_Unix::dist_basics ;
168 sub ExtUtils::MM_Unix::dist_ci ;
169 sub ExtUtils::MM_Unix::dist_core ;
170 sub ExtUtils::MM_Unix::dist_dir ;
171 sub ExtUtils::MM_Unix::dist_test ;
172 sub ExtUtils::MM_Unix::dlsyms ;
173 sub ExtUtils::MM_Unix::dynamic ;
174 sub ExtUtils::MM_Unix::dynamic_bs ;
175 sub ExtUtils::MM_Unix::dynamic_lib ;
176 sub ExtUtils::MM_Unix::exescan ;
177 sub ExtUtils::MM_Unix::export_list ;
178 sub ExtUtils::MM_Unix::extliblist ;
179 sub ExtUtils::MM_Unix::file_name_is_absolute ;
180 sub ExtUtils::MM_Unix::find_perl ;
181 sub ExtUtils::MM_Unix::fixin ;
182 sub ExtUtils::MM_Unix::force ;
183 sub ExtUtils::MM_Unix::guess_name ;
184 sub ExtUtils::MM_Unix::has_link_code ;
185 sub ExtUtils::MM_Unix::init_dirscan ;
186 sub ExtUtils::MM_Unix::init_main ;
187 sub ExtUtils::MM_Unix::init_others ;
188 sub ExtUtils::MM_Unix::install ;
189 sub ExtUtils::MM_Unix::installbin ;
190 sub ExtUtils::MM_Unix::libscan ;
191 sub ExtUtils::MM_Unix::linkext ;
192 sub ExtUtils::MM_Unix::lsdir ;
193 sub ExtUtils::MM_Unix::macro ;
194 sub ExtUtils::MM_Unix::makeaperl ;
195 sub ExtUtils::MM_Unix::makefile ;
196 sub ExtUtils::MM_Unix::manifypods ;
197 sub ExtUtils::MM_Unix::maybe_command ;
198 sub ExtUtils::MM_Unix::maybe_command_in_dirs ;
199 sub ExtUtils::MM_Unix::needs_linking ;
200 sub ExtUtils::MM_Unix::nicetext ;
201 sub ExtUtils::MM_Unix::parse_version ;
202 sub ExtUtils::MM_Unix::pasthru ;
203 sub ExtUtils::MM_Unix::path ;
204 sub ExtUtils::MM_Unix::perl_archive;
205 sub ExtUtils::MM_Unix::perl_script ;
206 sub ExtUtils::MM_Unix::perldepend ;
207 sub ExtUtils::MM_Unix::pm_to_blib ;
208 sub ExtUtils::MM_Unix::post_constants ;
209 sub ExtUtils::MM_Unix::post_initialize ;
210 sub ExtUtils::MM_Unix::postamble ;
211 sub ExtUtils::MM_Unix::prefixify ;
212 sub ExtUtils::MM_Unix::processPL ;
213 sub ExtUtils::MM_Unix::realclean ;
214 sub ExtUtils::MM_Unix::replace_manpage_separator ;
215 sub ExtUtils::MM_Unix::static ;
216 sub ExtUtils::MM_Unix::static_lib ;
217 sub ExtUtils::MM_Unix::staticmake ;
218 sub ExtUtils::MM_Unix::subdir_x ;
219 sub ExtUtils::MM_Unix::subdirs ;
220 sub ExtUtils::MM_Unix::test ;
221 sub ExtUtils::MM_Unix::test_via_harness ;
222 sub ExtUtils::MM_Unix::test_via_script ;
223 sub ExtUtils::MM_Unix::tool_autosplit ;
224 sub ExtUtils::MM_Unix::tool_xsubpp ;
225 sub ExtUtils::MM_Unix::tools_other ;
226 sub ExtUtils::MM_Unix::top_targets ;
227 sub ExtUtils::MM_Unix::writedoc ;
228 sub ExtUtils::MM_Unix::xs_c ;
229 sub ExtUtils::MM_Unix::xs_o ;
230 sub ExtUtils::MM_Unix::xsubpp_version ;
231
232 package ExtUtils::MM_Unix;
233
234 use SelfLoader;
235
236 1;
237
238 __DATA__
239
240 =back
241
242 =head2 SelfLoaded methods
243
244 =over 2
245
246 =item c_o (o)
247
248 Defines the suffix rules to compile different flavors of C files to
249 object files.
250
251 =cut
252
253 sub c_o {
254 # --- Translation Sections ---
255
256     my($self) = shift;
257     return '' unless $self->needs_linking();
258     my(@m);
259     push @m, '
260 .c$(OBJ_EXT):
261         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
262 ';
263     push @m, '
264 .C$(OBJ_EXT):
265         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.C
266 ' if $^O ne 'os2' and $^O ne 'MSWin32' and $^O ne 'dos'; #Case-specific
267     push @m, '
268 .cpp$(OBJ_EXT):
269         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.cpp
270
271 .cxx$(OBJ_EXT):
272         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.cxx
273
274 .cc$(OBJ_EXT):
275         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.cc
276 ';
277     join "", @m;
278 }
279
280 =item cflags (o)
281
282 Does very much the same as the cflags script in the perl
283 distribution. It doesn't return the whole compiler command line, but
284 initializes all of its parts. The const_cccmd method then actually
285 returns the definition of the CCCMD macro which uses these parts.
286
287 =cut
288
289 #'
290
291 sub cflags {
292     my($self,$libperl)=@_;
293     return $self->{CFLAGS} if $self->{CFLAGS};
294     return '' unless $self->needs_linking();
295
296     my($prog, $uc, $perltype, %cflags);
297     $libperl ||= $self->{LIBPERL_A} || "libperl$self->{LIB_EXT}" ;
298     $libperl =~ s/\.\$\(A\)$/$self->{LIB_EXT}/;
299
300     @cflags{qw(cc ccflags optimize large split shellflags)}
301         = @Config{qw(cc ccflags optimize large split shellflags)};
302     my($optdebug) = "";
303
304     $cflags{shellflags} ||= '';
305
306     my(%map) =  (
307                 D =>   '-DDEBUGGING',
308                 E =>   '-DEMBED',
309                 DE =>  '-DDEBUGGING -DEMBED',
310                 M =>   '-DEMBED -DMULTIPLICITY',
311                 DM =>  '-DDEBUGGING -DEMBED -DMULTIPLICITY',
312                 );
313
314     if ($libperl =~ /libperl(\w*)\Q$self->{LIB_EXT}/){
315         $uc = uc($1);
316     } else {
317         $uc = ""; # avoid warning
318     }
319     $perltype = $map{$uc} ? $map{$uc} : "";
320
321     if ($uc =~ /^D/) {
322         $optdebug = "-g";
323     }
324
325
326     my($name);
327     ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
328     if ($prog = $Config::Config{$name}) {
329         # Expand hints for this extension via the shell
330         print STDOUT "Processing $name hint:\n" if $Verbose;
331         my(@o)=`cc=\"$cflags{cc}\"
332           ccflags=\"$cflags{ccflags}\"
333           optimize=\"$cflags{optimize}\"
334           perltype=\"$cflags{perltype}\"
335           optdebug=\"$cflags{optdebug}\"
336           large=\"$cflags{large}\"
337           split=\"$cflags{'split'}\"
338           eval '$prog'
339           echo cc=\$cc
340           echo ccflags=\$ccflags
341           echo optimize=\$optimize
342           echo perltype=\$perltype
343           echo optdebug=\$optdebug
344           echo large=\$large
345           echo split=\$split
346           `;
347         my($line);
348         foreach $line (@o){
349             chomp $line;
350             if ($line =~ /(.*?)=\s*(.*)\s*$/){
351                 $cflags{$1} = $2;
352                 print STDOUT "  $1 = $2\n" if $Verbose;
353             } else {
354                 print STDOUT "Unrecognised result from hint: '$line'\n";
355             }
356         }
357     }
358
359     if ($optdebug) {
360         $cflags{optimize} = $optdebug;
361     }
362
363     for (qw(ccflags optimize perltype large split)) {
364         $cflags{$_} =~ s/^\s+//;
365         $cflags{$_} =~ s/\s+/ /g;
366         $cflags{$_} =~ s/\s+$//;
367         $self->{uc $_} ||= $cflags{$_}
368     }
369
370     return $self->{CFLAGS} = qq{
371 CCFLAGS = $self->{CCFLAGS}
372 OPTIMIZE = $self->{OPTIMIZE}
373 PERLTYPE = $self->{PERLTYPE}
374 LARGE = $self->{LARGE}
375 SPLIT = $self->{SPLIT}
376 };
377
378 }
379
380 =item clean (o)
381
382 Defines the clean target.
383
384 =cut
385
386 sub clean {
387 # --- Cleanup and Distribution Sections ---
388
389     my($self, %attribs) = @_;
390     my(@m,$dir);
391     push(@m, '
392 # Delete temporary files but do not touch installed files. We don\'t delete
393 # the Makefile here so a later make realclean still has a makefile to use.
394
395 clean ::
396 ');
397     # clean subdirectories first
398     for $dir (@{$self->{DIR}}) {
399         push @m, "\t-cd $dir && \$(TEST_F) $self->{MAKEFILE} && \$(MAKE) clean\n";
400     }
401
402     my(@otherfiles) = values %{$self->{XS}}; # .c files from *.xs files
403     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
404     push(@otherfiles, qw[./blib $(MAKE_APERL_FILE) $(INST_ARCHAUTODIR)/extralibs.all
405                          perlmain.c mon.out core so_locations pm_to_blib
406                          *~ */*~ */*/*~ *$(OBJ_EXT) *$(LIB_EXT) perl.exe
407                          $(BOOTSTRAP) $(BASEEXT).bso $(BASEEXT).def
408                          $(BASEEXT).exp
409                         ]);
410     push @m, "\t-$self->{RM_RF} @otherfiles\n";
411     # See realclean and ext/utils/make_ext for usage of Makefile.old
412     push(@m,
413          "\t-$self->{MV} $self->{MAKEFILE} $self->{MAKEFILE}.old \$(DEV_NULL)\n");
414     push(@m,
415          "\t$attribs{POSTOP}\n")   if $attribs{POSTOP};
416     join("", @m);
417 }
418
419 =item const_cccmd (o)
420
421 Returns the full compiler call for C programs and stores the
422 definition in CONST_CCCMD.
423
424 =cut
425
426 sub const_cccmd {
427     my($self,$libperl)=@_;
428     return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
429     return '' unless $self->needs_linking();
430     return $self->{CONST_CCCMD} =
431         q{CCCMD = $(CC) -c $(INC) $(CCFLAGS) $(OPTIMIZE) \\
432         $(PERLTYPE) $(LARGE) $(SPLIT) $(DEFINE_VERSION) \\
433         $(XS_DEFINE_VERSION)};
434 }
435
436 =item const_config (o)
437
438 Defines a couple of constants in the Makefile that are imported from
439 %Config.
440
441 =cut
442
443 sub const_config {
444 # --- Constants Sections ---
445
446     my($self) = shift;
447     my(@m,$m);
448     push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
449     push(@m,"\n# They may have been overridden via Makefile.PL or on the command line\n");
450     my(%once_only);
451     foreach $m (@{$self->{CONFIG}}){
452         # SITE*EXP macros are defined in &constants; avoid duplicates here
453         next if $once_only{$m} or $m eq 'sitelibexp' or $m eq 'sitearchexp';
454         push @m, "\U$m\E = ".$self->{uc $m}."\n";
455         $once_only{$m} = 1;
456     }
457     join('', @m);
458 }
459
460 =item const_loadlibs (o)
461
462 Defines EXTRALIBS, LDLOADLIBS, BSLOADLIBS, LD_RUN_PATH. See
463 L<ExtUtils::Liblist> for details.
464
465 =cut
466
467 sub const_loadlibs {
468     my($self) = shift;
469     return "" unless $self->needs_linking;
470     my @m;
471     push @m, qq{
472 # $self->{NAME} might depend on some other libraries:
473 # See ExtUtils::Liblist for details
474 #
475 };
476     my($tmp);
477     for $tmp (qw/
478          EXTRALIBS LDLOADLIBS BSLOADLIBS LD_RUN_PATH
479          /) {
480         next unless defined $self->{$tmp};
481         push @m, "$tmp = $self->{$tmp}\n";
482     }
483     return join "", @m;
484 }
485
486 =item constants (o)
487
488 Initializes lots of constants and .SUFFIXES and .PHONY
489
490 =cut
491
492 sub constants {
493     my($self) = @_;
494     my(@m,$tmp);
495
496     for $tmp (qw/
497
498               AR_STATIC_ARGS NAME DISTNAME NAME_SYM VERSION
499               VERSION_SYM XS_VERSION INST_BIN INST_EXE INST_LIB
500               INST_ARCHLIB INST_SCRIPT PREFIX  INSTALLDIRS
501               INSTALLPRIVLIB INSTALLARCHLIB INSTALLSITELIB
502               INSTALLSITEARCH INSTALLBIN INSTALLSCRIPT PERL_LIB
503               PERL_ARCHLIB SITELIBEXP SITEARCHEXP LIBPERL_A MYEXTLIB
504               FIRST_MAKEFILE MAKE_APERL_FILE PERLMAINCC PERL_SRC
505               PERL_INC PERL FULLPERL
506
507               / ) {
508         next unless defined $self->{$tmp};
509         push @m, "$tmp = $self->{$tmp}\n";
510     }
511
512     push @m, qq{
513 VERSION_MACRO = VERSION
514 DEFINE_VERSION = -D\$(VERSION_MACRO)=\\\"\$(VERSION)\\\"
515 XS_VERSION_MACRO = XS_VERSION
516 XS_DEFINE_VERSION = -D\$(XS_VERSION_MACRO)=\\\"\$(XS_VERSION)\\\"
517 };
518
519     push @m, qq{
520 MAKEMAKER = $INC{'ExtUtils/MakeMaker.pm'}
521 MM_VERSION = $ExtUtils::MakeMaker::VERSION
522 };
523
524     push @m, q{
525 # FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
526 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
527 # ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)  !!! Deprecated from MM 5.32  !!!
528 # PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
529 # DLBASE  = Basename part of dynamic library. May be just equal BASEEXT.
530 };
531
532     for $tmp (qw/
533               FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT
534               LDFROM LINKTYPE
535               / ) {
536         next unless defined $self->{$tmp};
537         push @m, "$tmp = $self->{$tmp}\n";
538     }
539
540     push @m, "
541 # Handy lists of source code files:
542 XS_FILES= ".join(" \\\n\t", sort keys %{$self->{XS}})."
543 C_FILES = ".join(" \\\n\t", @{$self->{C}})."
544 O_FILES = ".join(" \\\n\t", @{$self->{O_FILES}})."
545 H_FILES = ".join(" \\\n\t", @{$self->{H}})."
546 MAN1PODS = ".join(" \\\n\t", sort keys %{$self->{MAN1PODS}})."
547 MAN3PODS = ".join(" \\\n\t", sort keys %{$self->{MAN3PODS}})."
548 ";
549
550     for $tmp (qw/
551               INST_MAN1DIR INSTALLMAN1DIR MAN1EXT INST_MAN3DIR INSTALLMAN3DIR MAN3EXT
552               /) {
553         next unless defined $self->{$tmp};
554         push @m, "$tmp = $self->{$tmp}\n";
555     }
556
557     push @m, q{
558 .NO_CONFIG_REC: Makefile
559 } if $ENV{CLEARCASE_ROOT};
560
561     # why not q{} ? -- emacs
562     push @m, qq{
563 # work around a famous dec-osf make(1) feature(?):
564 makemakerdflt: all
565
566 .SUFFIXES: .xs .c .C .cpp .cxx .cc \$(OBJ_EXT)
567
568 # Nick wanted to get rid of .PRECIOUS. I don't remember why. I seem to recall, that
569 # some make implementations will delete the Makefile when we rebuild it. Because
570 # we call false(1) when we rebuild it. So make(1) is not completely wrong when it
571 # does so. Our milage may vary.
572 # .PRECIOUS: Makefile    # seems to be not necessary anymore
573
574 .PHONY: all config static dynamic test linkext manifest
575
576 # Where is the Config information that we are using/depend on
577 CONFIGDEP = \$(PERL_ARCHLIB)/Config.pm \$(PERL_INC)/config.h
578 };
579
580     my @parentdir = split(/::/, $self->{PARENT_NAME});
581     push @m, q{
582 # Where to put things:
583 INST_LIBDIR      = }. $self->catdir('$(INST_LIB)',@parentdir)        .q{
584 INST_ARCHLIBDIR  = }. $self->catdir('$(INST_ARCHLIB)',@parentdir)    .q{
585
586 INST_AUTODIR     = }. $self->catdir('$(INST_LIB)','auto','$(FULLEXT)')       .q{
587 INST_ARCHAUTODIR = }. $self->catdir('$(INST_ARCHLIB)','auto','$(FULLEXT)')   .q{
588 };
589
590     if ($self->has_link_code()) {
591         push @m, '
592 INST_STATIC  = $(INST_ARCHAUTODIR)/$(BASEEXT)$(LIB_EXT)
593 INST_DYNAMIC = $(INST_ARCHAUTODIR)/$(DLBASE).$(DLEXT)
594 INST_BOOT    = $(INST_ARCHAUTODIR)/$(BASEEXT).bs
595 ';
596     } else {
597         push @m, '
598 INST_STATIC  =
599 INST_DYNAMIC =
600 INST_BOOT    =
601 ';
602     }
603
604     $tmp = $self->export_list;
605     push @m, "
606 EXPORT_LIST = $tmp
607 ";
608     $tmp = $self->perl_archive;
609     push @m, "
610 PERL_ARCHIVE = $tmp
611 ";
612
613 #    push @m, q{
614 #INST_PM = }.join(" \\\n\t", sort values %{$self->{PM}}).q{
615 #
616 #PM_TO_BLIB = }.join(" \\\n\t", %{$self->{PM}}).q{
617 #};
618
619     push @m, q{
620 TO_INST_PM = }.join(" \\\n\t", sort keys %{$self->{PM}}).q{
621
622 PM_TO_BLIB = }.join(" \\\n\t", %{$self->{PM}}).q{
623 };
624
625     join('',@m);
626 }
627
628 =item depend (o)
629
630 Same as macro for the depend attribute.
631
632 =cut
633
634 sub depend {
635     my($self,%attribs) = @_;
636     my(@m,$key,$val);
637     while (($key,$val) = each %attribs){
638         last unless defined $key;
639         push @m, "$key: $val\n";
640     }
641     join "", @m;
642 }
643
644 =item dir_target (o)
645
646 Takes an array of directories that need to exist and returns a
647 Makefile entry for a .exists file in these directories. Returns
648 nothing, if the entry has already been processed. We're helpless
649 though, if the same directory comes as $(FOO) _and_ as "bar". Both of
650 them get an entry, that's why we use "::".
651
652 =cut
653
654 sub dir_target {
655 # --- Make-Directories section (internal method) ---
656 # dir_target(@array) returns a Makefile entry for the file .exists in each
657 # named directory. Returns nothing, if the entry has already been processed.
658 # We're helpless though, if the same directory comes as $(FOO) _and_ as "bar".
659 # Both of them get an entry, that's why we use "::". I chose '$(PERL)' as the
660 # prerequisite, because there has to be one, something that doesn't change
661 # too often :)
662
663     my($self,@dirs) = @_;
664     my(@m,$dir,$targdir);
665     foreach $dir (@dirs) {
666         my($src) = $self->catfile($self->{PERL_INC},'perl.h');
667         my($targ) = $self->catfile($dir,'.exists');
668         # catfile may have adapted syntax of $dir to target OS, so...
669         if ($Is_VMS) { # Just remove file name; dirspec is often in macro
670             ($targdir = $targ) =~ s:/?\.exists$::;
671         }
672         else { # while elsewhere we expect to see the dir separator in $targ
673             $targdir = dirname($targ);
674         }
675         next if $self->{DIR_TARGET}{$self}{$targdir}++;
676         push @m, qq{
677 $targ :: $src
678         $self->{NOECHO}\$(MKPATH) $targdir
679         $self->{NOECHO}\$(EQUALIZE_TIMESTAMP) $src $targ
680 };
681         push(@m,qq{
682         -$self->{NOECHO}\$(CHMOD) 755 $targdir
683 }) unless $Is_VMS;
684     }
685     join "", @m;
686 }
687
688 =item dist (o)
689
690 Defines a lot of macros for distribution support.
691
692 =cut
693
694 sub dist {
695     my($self, %attribs) = @_;
696
697     my(@m);
698     # VERSION should be sanitised before use as a file name
699     my($version)  = $attribs{VERSION}  || '$(VERSION)';
700     my($name)     = $attribs{NAME}     || '$(DISTNAME)';
701     my($tar)      = $attribs{TAR}      || 'tar';        # eg /usr/bin/gnutar
702     my($tarflags) = $attribs{TARFLAGS} || 'cvf';
703     my($zip)      = $attribs{ZIP}      || 'zip';        # eg pkzip Yuck!
704     my($zipflags) = $attribs{ZIPFLAGS} || '-r';
705     my($compress) = $attribs{COMPRESS} || 'compress';   # eg gzip
706     my($suffix)   = $attribs{SUFFIX}   || '.Z';          # eg .gz
707     my($shar)     = $attribs{SHAR}     || 'shar';       # eg "shar --gzip"
708     my($preop)    = $attribs{PREOP}    || "$self->{NOECHO}\$(NOOP)"; # eg update MANIFEST
709     my($postop)   = $attribs{POSTOP}   || "$self->{NOECHO}\$(NOOP)"; # eg remove the distdir
710
711     my($to_unix)  = $attribs{TO_UNIX} || ($Is_OS2
712                                           ? "$self->{NOECHO}"
713                                           . '$(TEST_F) tmp.zip && $(RM) tmp.zip;'
714                                           . ' $(ZIP) -ll -mr tmp.zip $(DISTVNAME) && unzip -o tmp.zip && $(RM) tmp.zip'
715                                           : "$self->{NOECHO}\$(NOOP)");
716
717     my($ci)       = $attribs{CI}       || 'ci -u';
718     my($rcs_label)= $attribs{RCS_LABEL}|| 'rcs -Nv$(VERSION_SYM): -q';
719     my($dist_cp)  = $attribs{DIST_CP}  || 'best';
720     my($dist_default) = $attribs{DIST_DEFAULT} || 'tardist';
721
722     push @m, "
723 DISTVNAME = ${name}-$version
724 TAR  = $tar
725 TARFLAGS = $tarflags
726 ZIP  = $zip
727 ZIPFLAGS = $zipflags
728 COMPRESS = $compress
729 SUFFIX = $suffix
730 SHAR = $shar
731 PREOP = $preop
732 POSTOP = $postop
733 TO_UNIX = $to_unix
734 CI = $ci
735 RCS_LABEL = $rcs_label
736 DIST_CP = $dist_cp
737 DIST_DEFAULT = $dist_default
738 ";
739     join "", @m;
740 }
741
742 =item dist_basics (o)
743
744 Defines the targets distclean, distcheck, skipcheck, manifest.
745
746 =cut
747
748 sub dist_basics {
749     my($self) = shift;
750     my @m;
751     push @m, q{
752 distclean :: realclean distcheck
753 };
754
755     push @m, q{
756 distcheck :
757         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=fullcheck \\
758                 -e fullcheck
759 };
760
761     push @m, q{
762 skipcheck :
763         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=skipcheck \\
764                 -e skipcheck
765 };
766
767     push @m, q{
768 manifest :
769         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=mkmanifest \\
770                 -e mkmanifest
771 };
772     join "", @m;
773 }
774
775 =item dist_ci (o)
776
777 Defines a check in target for RCS.
778
779 =cut
780
781 sub dist_ci {
782     my($self) = shift;
783     my @m;
784     push @m, q{
785 ci :
786         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=maniread \\
787                 -e "@all = keys %{ maniread() };" \\
788                 -e 'print("Executing $(CI) @all\n"); system("$(CI) @all");' \\
789                 -e 'print("Executing $(RCS_LABEL) ...\n"); system("$(RCS_LABEL) @all");'
790 };
791     join "", @m;
792 }
793
794 =item dist_core (o)
795
796 Defeines the targets dist, tardist, zipdist, uutardist, shdist
797
798 =cut
799
800 sub dist_core {
801     my($self) = shift;
802     my @m;
803     push @m, q{
804 dist : $(DIST_DEFAULT)
805         }.$self->{NOECHO}.q{$(PERL) -le 'print "Warning: Makefile possibly out of date with $$vf" if ' \
806             -e '-e ($$vf="$(VERSION_FROM)") and -M $$vf < -M "}.$self->{MAKEFILE}.q{";'
807
808 tardist : $(DISTVNAME).tar$(SUFFIX)
809
810 zipdist : $(DISTVNAME).zip
811
812 $(DISTVNAME).tar$(SUFFIX) : distdir
813         $(PREOP)
814         $(TO_UNIX)
815         $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
816         $(RM_RF) $(DISTVNAME)
817         $(COMPRESS) $(DISTVNAME).tar
818         $(POSTOP)
819
820 $(DISTVNAME).zip : distdir
821         $(PREOP)
822         $(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME)
823         $(RM_RF) $(DISTVNAME)
824         $(POSTOP)
825
826 uutardist : $(DISTVNAME).tar$(SUFFIX)
827         uuencode $(DISTVNAME).tar$(SUFFIX) \\
828                 $(DISTVNAME).tar$(SUFFIX) > \\
829                 $(DISTVNAME).tar$(SUFFIX)_uu
830
831 shdist : distdir
832         $(PREOP)
833         $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar
834         $(RM_RF) $(DISTVNAME)
835         $(POSTOP)
836 };
837     join "", @m;
838 }
839
840 =item dist_dir (o)
841
842 Defines the scratch directory target that will hold the distribution
843 before tar-ing (or shar-ing).
844
845 =cut
846
847 sub dist_dir {
848     my($self) = shift;
849     my @m;
850     push @m, q{
851 distdir :
852         $(RM_RF) $(DISTVNAME)
853         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=manicopy,maniread \\
854                 -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
855 };
856     join "", @m;
857 }
858
859 =item dist_test (o)
860
861 Defines a target that produces the distribution in the
862 scratchdirectory, and runs 'perl Makefile.PL; make ;make test' in that
863 subdirectory.
864
865 =cut
866
867 sub dist_test {
868     my($self) = shift;
869     my @m;
870     push @m, q{
871 disttest : distdir
872         cd $(DISTVNAME) && $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) Makefile.PL
873         cd $(DISTVNAME) && $(MAKE)
874         cd $(DISTVNAME) && $(MAKE) test
875 };
876     join "", @m;
877 }
878
879 =item dlsyms (o)
880
881 Used by AIX and VMS to define DL_FUNCS and DL_VARS and write the *.exp
882 files.
883
884 =cut
885
886 sub dlsyms {
887     my($self,%attribs) = @_;
888
889     return '' unless ($^O eq 'aix' && $self->needs_linking() );
890
891     my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
892     my($vars)  = $attribs{DL_VARS} || $self->{DL_VARS} || [];
893     my(@m);
894
895     push(@m,"
896 dynamic :: $self->{BASEEXT}.exp
897
898 ") unless $self->{SKIPHASH}{'dynamic'}; # dynamic and static are subs, so...
899
900     push(@m,"
901 static :: $self->{BASEEXT}.exp
902
903 ") unless $self->{SKIPHASH}{'static'};  # we avoid a warning if we tick them
904
905     push(@m,"
906 $self->{BASEEXT}.exp: Makefile.PL
907 ",'     $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e \'use ExtUtils::Mksymlists; \\
908         Mksymlists("NAME" => "',$self->{NAME},'", "DL_FUNCS" => ',
909         neatvalue($funcs),', "DL_VARS" => ', neatvalue($vars), ');\'
910 ');
911
912     join('',@m);
913 }
914
915 =item dynamic (o)
916
917 Defines the dynamic target.
918
919 =cut
920
921 sub dynamic {
922 # --- Dynamic Loading Sections ---
923
924     my($self) = shift;
925     '
926 ## $(INST_PM) has been moved to the all: target.
927 ## It remains here for awhile to allow for old usage: "make dynamic"
928 #dynamic :: '.$self->{MAKEFILE}.' $(INST_DYNAMIC) $(INST_BOOT) $(INST_PM)
929 dynamic :: '.$self->{MAKEFILE}.' $(INST_DYNAMIC) $(INST_BOOT)
930         '.$self->{NOECHO}.'$(NOOP)
931 ';
932 }
933
934 =item dynamic_bs (o)
935
936 Defines targets for bootstrap files.
937
938 =cut
939
940 sub dynamic_bs {
941     my($self, %attribs) = @_;
942     return '
943 BOOTSTRAP =
944 ' unless $self->has_link_code();
945
946     return '
947 BOOTSTRAP = '."$self->{BASEEXT}.bs".'
948
949 # As Mkbootstrap might not write a file (if none is required)
950 # we use touch to prevent make continually trying to remake it.
951 # The DynaLoader only reads a non-empty file.
952 $(BOOTSTRAP): '."$self->{MAKEFILE} $self->{BOOTDEP}".' $(INST_ARCHAUTODIR)/.exists
953         '.$self->{NOECHO}.'echo "Running Mkbootstrap for $(NAME) ($(BSLOADLIBS))"
954         '.$self->{NOECHO}.'$(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" \
955                 -MExtUtils::Mkbootstrap \
956                 -e "Mkbootstrap(\'$(BASEEXT)\',\'$(BSLOADLIBS)\');"
957         '.$self->{NOECHO}.'$(TOUCH) $(BOOTSTRAP)
958         $(CHMOD) 644 $@
959
960 $(INST_BOOT): $(BOOTSTRAP) $(INST_ARCHAUTODIR)/.exists
961         '."$self->{NOECHO}$self->{RM_RF}".' $(INST_BOOT)
962         -'.$self->{CP}.' $(BOOTSTRAP) $(INST_BOOT)
963         $(CHMOD) 644 $@
964 ';
965 }
966
967 =item dynamic_lib (o)
968
969 Defines how to produce the *.so (or equivalent) files.
970
971 =cut
972
973 sub dynamic_lib {
974     my($self, %attribs) = @_;
975     return '' unless $self->needs_linking(); #might be because of a subdir
976
977     return '' unless $self->has_link_code;
978
979     my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
980     my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
981     my($armaybe) = $attribs{ARMAYBE} || $self->{ARMAYBE} || ":";
982     my($ldfrom) = '$(LDFROM)';
983     $armaybe = 'ar' if ($^O eq 'dec_osf' and $armaybe eq ':');
984     my(@m);
985     push(@m,'
986 # This section creates the dynamically loadable $(INST_DYNAMIC)
987 # from $(OBJECT) and possibly $(MYEXTLIB).
988 ARMAYBE = '.$armaybe.'
989 OTHERLDFLAGS = '.$otherldflags.'
990 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
991
992 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)/.exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP)
993 ');
994     if ($armaybe ne ':'){
995         $ldfrom = 'tmp$(LIB_EXT)';
996         push(@m,'       $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
997         push(@m,'       $(RANLIB) '."$ldfrom\n");
998     }
999     $ldfrom = "-all $ldfrom -none" if ($^O eq 'dec_osf');
1000
1001     # Brain dead solaris linker does not use LD_RUN_PATH?
1002     # This fixes dynamic extensions which need shared libs
1003     my $ldrun = '';
1004     $ldrun = join ' ', map "-R$_", split /:/, $self->{LD_RUN_PATH}
1005        if ($^O eq 'solaris');
1006
1007     push(@m,'   LD_RUN_PATH="$(LD_RUN_PATH)" $(LD) -o $@ '.$ldrun.' $(LDDLFLAGS) '.$ldfrom.
1008                 ' $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) $(EXPORT_LIST)');
1009     push @m, '
1010         $(CHMOD) 755 $@
1011 ';
1012
1013     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
1014     join('',@m);
1015 }
1016
1017 =item exescan
1018
1019 Deprecated method. Use libscan instead.
1020
1021 =cut
1022
1023 sub exescan {
1024     my($self,$path) = @_;
1025     $path;
1026 }
1027
1028 =item extliblist
1029
1030 Called by init_others, and calls ext ExtUtils::Liblist. See
1031 L<ExtUtils::Liblist> for details.
1032
1033 =cut
1034
1035 sub extliblist {
1036     my($self,$libs) = @_;
1037     require ExtUtils::Liblist;
1038     $self->ext($libs, $Verbose);
1039 }
1040
1041 =item file_name_is_absolute
1042
1043 Takes as argument a path and returns true, if it is an absolute path.
1044
1045 =cut
1046
1047 sub file_name_is_absolute {
1048     my($self,$file) = @_;
1049     if ($Is_Dos){
1050         $file =~ m{^([a-z]:)?[\\/]}i ;
1051     }
1052     else {
1053         $file =~ m:^/: ;
1054     }
1055 }
1056
1057 =item find_perl
1058
1059 Finds the executables PERL and FULLPERL
1060
1061 =cut
1062
1063 sub find_perl {
1064     my($self, $ver, $names, $dirs, $trace) = @_;
1065     my($name, $dir);
1066     if ($trace >= 2){
1067         print "Looking for perl $ver by these names:
1068 @$names
1069 in these dirs:
1070 @$dirs
1071 ";
1072     }
1073     foreach $dir (@$dirs){
1074         next unless defined $dir; # $self->{PERL_SRC} may be undefined
1075         foreach $name (@$names){
1076             my ($abs, $val);
1077             if ($self->file_name_is_absolute($name)) { # /foo/bar
1078                 $abs = $name;
1079             } elsif ($self->canonpath($name) eq $self->canonpath(basename($name))) { # foo
1080                 $abs = $self->catfile($dir, $name);
1081             } else { # foo/bar
1082                 $abs = $self->canonpath($self->catfile($self->curdir, $name));
1083             }
1084             print "Checking $abs\n" if ($trace >= 2);
1085             next unless $self->maybe_command($abs);
1086             print "Executing $abs\n" if ($trace >= 2);
1087             $val = `$abs -e 'require $ver; print "VER_OK\n" ' 2>&1`;
1088             if ($val =~ /VER_OK/) {
1089                 print "Using PERL=$abs\n" if $trace;
1090                 return $abs;
1091             } elsif ($trace >= 2) {
1092                 print "Result: `$val'\n";
1093             }
1094         }
1095     }
1096     print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
1097     0; # false and not empty
1098 }
1099
1100 =back
1101
1102 =head2 Methods to actually produce chunks of text for the Makefile
1103
1104 The methods here are called for each MakeMaker object in the order
1105 specified by @ExtUtils::MakeMaker::MM_Sections.
1106
1107 =over 2
1108
1109 =item fixin
1110
1111 Inserts the sharpbang or equivalent magic number to a script
1112
1113 =cut
1114
1115 sub fixin { # stolen from the pink Camel book, more or less
1116     my($self,@files) = @_;
1117     my($does_shbang) = $Config::Config{'sharpbang'} =~ /^\s*\#\!/;
1118     my($file,$interpreter);
1119     for $file (@files) {
1120         local(*FIXIN);
1121         local(*FIXOUT);
1122         open(FIXIN, $file) or Carp::croak "Can't process '$file': $!";
1123         local $/ = "\n";
1124         chomp(my $line = <FIXIN>);
1125         next unless $line =~ s/^\s*\#!\s*//;     # Not a shbang file.
1126         # Now figure out the interpreter name.
1127         my($cmd,$arg) = split ' ', $line, 2;
1128         $cmd =~ s!^.*/!!;
1129
1130         # Now look (in reverse) for interpreter in absolute PATH (unless perl).
1131         if ($cmd eq "perl") {
1132             if ($Config{startperl} =~ m,^\#!.*/perl,) {
1133                 $interpreter = $Config{startperl};
1134                 $interpreter =~ s,^\#!,,;
1135             } else {
1136                 $interpreter = $Config{perlpath};
1137             }
1138         } else {
1139             my(@absdirs) = reverse grep {$self->file_name_is_absolute} $self->path;
1140             $interpreter = '';
1141             my($dir);
1142             foreach $dir (@absdirs) {
1143                 if ($self->maybe_command($cmd)) {
1144                     warn "Ignoring $interpreter in $file\n" if $Verbose && $interpreter;
1145                     $interpreter = $self->catfile($dir,$cmd);
1146                 }
1147             }
1148         }
1149         # Figure out how to invoke interpreter on this machine.
1150
1151         my($shb) = "";
1152         if ($interpreter) {
1153             print STDOUT "Changing sharpbang in $file to $interpreter" if $Verbose;
1154             # this is probably value-free on DOSISH platforms
1155             if ($does_shbang) {
1156                 $shb .= "$Config{'sharpbang'}$interpreter";
1157                 $shb .= ' ' . $arg if defined $arg;
1158                 $shb .= "\n";
1159             }
1160             $shb .= qq{
1161 eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}'
1162     if 0; # not running under some shell
1163 } unless $Is_Win32; # this won't work on win32, so don't
1164         } else {
1165             warn "Can't find $cmd in PATH, $file unchanged"
1166                 if $Verbose;
1167             next;
1168         }
1169
1170         unless ( open(FIXOUT,">$file.new") ) {
1171             warn "Can't create new $file: $!\n";
1172             next;
1173         }
1174         my($dev,$ino,$mode) = stat FIXIN;
1175         $mode = 0755 unless $dev;
1176         chmod $mode, $file;
1177         
1178         # Print out the new #! line (or equivalent).
1179         local $\;
1180         undef $/;
1181         print FIXOUT $shb, <FIXIN>;
1182         close FIXIN;
1183         close FIXOUT;
1184         # can't rename open files on some DOSISH platforms
1185         unless ( rename($file, "$file.bak") ) { 
1186             warn "Can't rename $file to $file.bak: $!";
1187             next;
1188         }
1189         unless ( rename("$file.new", $file) ) { 
1190             warn "Can't rename $file.new to $file: $!";
1191             unless ( rename("$file.bak", $file) ) {
1192                 warn "Can't rename $file.bak back to $file either: $!";
1193                 warn "Leaving $file renamed as $file.bak\n";
1194             }
1195             next;
1196         }
1197         unlink "$file.bak";
1198     } continue {
1199         chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
1200         system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';;
1201     }
1202 }
1203
1204 =item force (o)
1205
1206 Just writes FORCE:
1207
1208 =cut
1209
1210 sub force {
1211     my($self) = shift;
1212     '# Phony target to force checking subdirectories.
1213 FORCE:
1214         '.$self->{NOECHO}.'$(NOOP)
1215 ';
1216 }
1217
1218 =item guess_name
1219
1220 Guess the name of this package by examining the working directory's
1221 name. MakeMaker calls this only if the developer has not supplied a
1222 NAME attribute.
1223
1224 =cut
1225
1226 # ';
1227
1228 sub guess_name {
1229     my($self) = @_;
1230     use Cwd 'cwd';
1231     my $name = basename(cwd());
1232     $name =~ s|[\-_][\d\.\-]+$||;   # this is new with MM 5.00, we
1233                                     # strip minus or underline
1234                                     # followed by a float or some such
1235     print "Warning: Guessing NAME [$name] from current directory name.\n";
1236     $name;
1237 }
1238
1239 =item has_link_code
1240
1241 Returns true if C, XS, MYEXTLIB or similar objects exist within this
1242 object that need a compiler. Does not descend into subdirectories as
1243 needs_linking() does.
1244
1245 =cut
1246
1247 sub has_link_code {
1248     my($self) = shift;
1249     return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE};
1250     if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){
1251         $self->{HAS_LINK_CODE} = 1;
1252         return 1;
1253     }
1254     return $self->{HAS_LINK_CODE} = 0;
1255 }
1256
1257 =item init_dirscan
1258
1259 Initializes DIR, XS, PM, C, O_FILES, H, PL_FILES, MAN*PODS, EXE_FILES.
1260
1261 =cut
1262
1263 sub init_dirscan {      # --- File and Directory Lists (.xs .pm .pod etc)
1264     my($self) = @_;
1265     my($name, %dir, %xs, %c, %h, %ignore, %pl_files, %manifypods);
1266     local(%pm); #the sub in find() has to see this hash
1267     $ignore{'test.pl'} = 1;
1268     $ignore{'makefile.pl'} = 1 if $Is_VMS;
1269     foreach $name ($self->lsdir($self->curdir)){
1270         next if $name =~ /\#/;
1271         next if $name eq $self->curdir or $name eq $self->updir or $ignore{$name};
1272         next unless $self->libscan($name);
1273         if (-d $name){
1274             next if -l $name; # We do not support symlinks at all
1275             $dir{$name} = $name if (-f $self->catfile($name,"Makefile.PL"));
1276         } elsif ($name =~ /\.xs$/){
1277             my($c); ($c = $name) =~ s/\.xs$/.c/;
1278             $xs{$name} = $c;
1279             $c{$c} = 1;
1280         } elsif ($name =~ /\.c(pp|xx|c)?$/i){  # .c .C .cpp .cxx .cc
1281             $c{$name} = 1
1282                 unless $name =~ m/perlmain\.c/; # See MAP_TARGET
1283         } elsif ($name =~ /\.h$/i){
1284             $h{$name} = 1;
1285         } elsif ($name =~ /\.(p[ml]|pod)$/){
1286             $pm{$name} = $self->catfile('$(INST_LIBDIR)',$name);
1287         } elsif ($name =~ /\.PL$/ && $name ne "Makefile.PL") {
1288             ($pl_files{$name} = $name) =~ s/\.PL$// ;
1289         } elsif ($Is_VMS && $name =~ /\.pl$/ && $name ne 'makefile.pl' &&
1290                  $name ne 'test.pl') {  # case-insensitive filesystem
1291             ($pl_files{$name} = $name) =~ s/\.pl$// ;
1292         }
1293     }
1294
1295     # Some larger extensions often wish to install a number of *.pm/pl
1296     # files into the library in various locations.
1297
1298     # The attribute PMLIBDIRS holds an array reference which lists
1299     # subdirectories which we should search for library files to
1300     # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ].  We
1301     # recursively search through the named directories (skipping any
1302     # which don't exist or contain Makefile.PL files).
1303
1304     # For each *.pm or *.pl file found $self->libscan() is called with
1305     # the default installation path in $_[1]. The return value of
1306     # libscan defines the actual installation location.  The default
1307     # libscan function simply returns the path.  The file is skipped
1308     # if libscan returns false.
1309
1310     # The default installation location passed to libscan in $_[1] is:
1311     #
1312     #  ./*.pm           => $(INST_LIBDIR)/*.pm
1313     #  ./xyz/...        => $(INST_LIBDIR)/xyz/...
1314     #  ./lib/...        => $(INST_LIB)/...
1315     #
1316     # In this way the 'lib' directory is seen as the root of the actual
1317     # perl library whereas the others are relative to INST_LIBDIR
1318     # (which includes PARENT_NAME). This is a subtle distinction but one
1319     # that's important for nested modules.
1320
1321     $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}]
1322         unless $self->{PMLIBDIRS};
1323
1324     #only existing directories that aren't in $dir are allowed
1325
1326     # Avoid $_ wherever possible:
1327     # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
1328     my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
1329     my ($pmlibdir);
1330     @{$self->{PMLIBDIRS}} = ();
1331     foreach $pmlibdir (@pmlibdirs) {
1332         -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
1333     }
1334
1335     if (@{$self->{PMLIBDIRS}}){
1336         print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
1337             if ($Verbose >= 2);
1338         require File::Find;
1339         File::Find::find(sub {
1340             if (-d $_){
1341                 if ($_ eq "CVS" || $_ eq "RCS"){
1342                     $File::Find::prune = 1;
1343                 }
1344                 return;
1345             }
1346             return if /\#/;
1347             my($path, $prefix) = ($File::Find::name, '$(INST_LIBDIR)');
1348             my($striplibpath,$striplibname);
1349             $prefix =  '$(INST_LIB)' if (($striplibpath = $path) =~ s:^(\W*)lib\W:$1:i);
1350             ($striplibname,$striplibpath) = fileparse($striplibpath);
1351             my($inst) = $self->catfile($prefix,$striplibpath,$striplibname);
1352             local($_) = $inst; # for backwards compatibility
1353             $inst = $self->libscan($inst);
1354             print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
1355             return unless $inst;
1356             $pm{$path} = $inst;
1357         }, @{$self->{PMLIBDIRS}});
1358     }
1359
1360     $self->{DIR} = [sort keys %dir] unless $self->{DIR};
1361     $self->{XS}  = \%xs             unless $self->{XS};
1362     $self->{PM}  = \%pm             unless $self->{PM};
1363     $self->{C}   = [sort keys %c]   unless $self->{C};
1364     my(@o_files) = @{$self->{C}};
1365     $self->{O_FILES} = [grep s/\.c(pp|xx|c)?$/$self->{OBJ_EXT}/i, @o_files] ;
1366     $self->{H}   = [sort keys %h]   unless $self->{H};
1367     $self->{PL_FILES} = \%pl_files unless $self->{PL_FILES};
1368
1369     # Set up names of manual pages to generate from pods
1370     if ($self->{MAN1PODS}) {
1371     } elsif ( $self->{INST_MAN1DIR} =~ /^(none|\s*)$/ ) {
1372         $self->{MAN1PODS} = {};
1373     } else {
1374         my %manifypods = ();
1375         if ( exists $self->{EXE_FILES} ) {
1376             foreach $name (@{$self->{EXE_FILES}}) {
1377 #               use FileHandle ();
1378 #               my $fh = new FileHandle;
1379                 local *FH;
1380                 my($ispod)=0;
1381 #               if ($fh->open("<$name")) {
1382                 if (open(FH,"<$name")) {
1383 #                   while (<$fh>) {
1384                     while (<FH>) {
1385                         if (/^=head1\s+\w+/) {
1386                             $ispod=1;
1387                             last;
1388                         }
1389                     }
1390 #                   $fh->close;
1391                     close FH;
1392                 } else {
1393                     # If it doesn't exist yet, we assume, it has pods in it
1394                     $ispod = 1;
1395                 }
1396                 if( $ispod ) {
1397                     $manifypods{$name} =
1398                         $self->catfile('$(INST_MAN1DIR)',
1399                                        basename($name).'.$(MAN1EXT)');
1400                 }
1401             }
1402         }
1403         $self->{MAN1PODS} = \%manifypods;
1404     }
1405     if ($self->{MAN3PODS}) {
1406     } elsif ( $self->{INST_MAN3DIR} =~ /^(none|\s*)$/ ) {
1407         $self->{MAN3PODS} = {};
1408     } else {
1409         my %manifypods = (); # we collect the keys first, i.e. the files
1410                              # we have to convert to pod
1411         foreach $name (keys %{$self->{PM}}) {
1412             if ($name =~ /\.pod$/ ) {
1413                 $manifypods{$name} = $self->{PM}{$name};
1414             } elsif ($name =~ /\.p[ml]$/ ) {
1415 #               use FileHandle ();
1416 #               my $fh = new FileHandle;
1417                 local *FH;
1418                 my($ispod)=0;
1419 #               $fh->open("<$name");
1420                 if (open(FH,"<$name")) {
1421                     #           while (<$fh>) {
1422                     while (<FH>) {
1423                         if (/^=head1\s+\w+/) {
1424                             $ispod=1;
1425                             last;
1426                         }
1427                     }
1428                     #           $fh->close;
1429                     close FH;
1430                 } else {
1431                     $ispod = 1;
1432                 }
1433                 if( $ispod ) {
1434                     $manifypods{$name} = $self->{PM}{$name};
1435                 }
1436             }
1437         }
1438
1439         # Remove "Configure.pm" and similar, if it's not the only pod listed
1440         # To force inclusion, just name it "Configure.pod", or override MAN3PODS
1441         foreach $name (keys %manifypods) {
1442             if ($name =~ /(config|setup).*\.pm/i) {
1443                 delete $manifypods{$name};
1444                 next;
1445             }
1446             my($manpagename) = $name;
1447             unless ($manpagename =~ s!^\W*lib\W+!!) { # everything below lib is ok
1448                 $manpagename = $self->catfile(split(/::/,$self->{PARENT_NAME}),$manpagename);
1449             }
1450             $manpagename =~ s/\.p(od|m|l)$//;
1451             $manpagename = $self->replace_manpage_separator($manpagename);
1452             $manifypods{$name} = $self->catfile("\$(INST_MAN3DIR)","$manpagename.\$(MAN3EXT)");
1453         }
1454         $self->{MAN3PODS} = \%manifypods;
1455     }
1456 }
1457
1458 =item init_main
1459
1460 Initializes NAME, FULLEXT, BASEEXT, PARENT_NAME, DLBASE, PERL_SRC,
1461 PERL_LIB, PERL_ARCHLIB, PERL_INC, INSTALLDIRS, INST_*, INSTALL*,
1462 PREFIX, CONFIG, AR, AR_STATIC_ARGS, LD, OBJ_EXT, LIB_EXT, EXE_EXT, MAP_TARGET,
1463 LIBPERL_A, VERSION_FROM, VERSION, DISTNAME, VERSION_SYM.
1464
1465 =cut
1466
1467 sub init_main {
1468     my($self) = @_;
1469
1470     # --- Initialize Module Name and Paths
1471
1472     # NAME    = Foo::Bar::Oracle
1473     # FULLEXT = Foo/Bar/Oracle
1474     # BASEEXT = Oracle
1475     # ROOTEXT = Directory part of FULLEXT with leading /. !!! Deprecated from MM 5.32 !!!
1476     # PARENT_NAME = Foo::Bar
1477 ### Only UNIX:
1478 ###    ($self->{FULLEXT} =
1479 ###     $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket
1480     $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME});
1481
1482
1483     # Copied from DynaLoader:
1484
1485     my(@modparts) = split(/::/,$self->{NAME});
1486     my($modfname) = $modparts[-1];
1487
1488     # Some systems have restrictions on files names for DLL's etc.
1489     # mod2fname returns appropriate file base name (typically truncated)
1490     # It may also edit @modparts if required.
1491     if (defined &DynaLoader::mod2fname) {
1492         $modfname = &DynaLoader::mod2fname(\@modparts);
1493     }
1494
1495     ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!([\w:]+::)?(\w+)$! ;
1496
1497     if (defined &DynaLoader::mod2fname) {
1498         # As of 5.001m, dl_os2 appends '_'
1499         $self->{DLBASE} = $modfname;
1500     } else {
1501         $self->{DLBASE} = '$(BASEEXT)';
1502     }
1503
1504
1505     ### ROOTEXT deprecated from MM 5.32
1506 ###    ($self->{ROOTEXT} =
1507 ###     $self->{FULLEXT}) =~ s#/?\Q$self->{BASEEXT}\E$## ;      #eg. /BSD/Foo
1508 ###    $self->{ROOTEXT} = ($Is_VMS ? '' : '/') . $self->{ROOTEXT} if $self->{ROOTEXT};
1509
1510
1511     # --- Initialize PERL_LIB, INST_LIB, PERL_SRC
1512
1513     # *Real* information: where did we get these two from? ...
1514     my $inc_config_dir = dirname($INC{'Config.pm'});
1515     my $inc_carp_dir   = dirname($INC{'Carp.pm'});
1516
1517     unless ($self->{PERL_SRC}){
1518         my($dir);
1519         foreach $dir ($self->updir(),$self->catdir($self->updir(),$self->updir()),$self->catdir($self->updir(),$self->updir(),$self->updir())){
1520             if (
1521                 -f $self->catfile($dir,"config.sh")
1522                 &&
1523                 -f $self->catfile($dir,"perl.h")
1524                 &&
1525                 -f $self->catfile($dir,"lib","Exporter.pm")
1526                ) {
1527                 $self->{PERL_SRC}=$dir ;
1528                 last;
1529             }
1530         }
1531     }
1532     if ($self->{PERL_SRC}){
1533         $self->{PERL_LIB}     ||= $self->catdir("$self->{PERL_SRC}","lib");
1534         $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
1535         $self->{PERL_INC}     = ($Is_Win32) ? $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
1536
1537         # catch a situation that has occurred a few times in the past:
1538         unless (
1539                 -s $self->catfile($self->{PERL_SRC},'cflags')
1540                 or
1541                 $Is_VMS
1542                 &&
1543                 -s $self->catfile($self->{PERL_SRC},'perlshr_attr.opt')
1544                 or
1545                 $Is_Mac
1546                 or
1547                 $Is_Win32
1548                ){
1549             warn qq{
1550 You cannot build extensions below the perl source tree after executing
1551 a 'make clean' in the perl source tree.
1552
1553 To rebuild extensions distributed with the perl source you should
1554 simply Configure (to include those extensions) and then build perl as
1555 normal. After installing perl the source tree can be deleted. It is
1556 not needed for building extensions by running 'perl Makefile.PL'
1557 usually without extra arguments.
1558
1559 It is recommended that you unpack and build additional extensions away
1560 from the perl source tree.
1561 };
1562         }
1563     } else {
1564         # we should also consider $ENV{PERL5LIB} here
1565         $self->{PERL_LIB}     ||= $Config::Config{privlibexp};
1566         $self->{PERL_ARCHLIB} ||= $Config::Config{archlibexp};
1567         $self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
1568         my $perl_h;
1569         unless (-f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))){
1570             die qq{
1571 Error: Unable to locate installed Perl libraries or Perl source code.
1572
1573 It is recommended that you install perl in a standard location before
1574 building extensions. Some precompiled versions of perl do not contain
1575 these header files, so you cannot build extensions. In such a case,
1576 please build and install your perl from a fresh perl distribution. It
1577 usually solves this kind of problem.
1578
1579 \(You get this message, because MakeMaker could not find "$perl_h"\)
1580 };
1581         }
1582 #        print STDOUT "Using header files found in $self->{PERL_INC}\n"
1583 #            if $Verbose && $self->needs_linking();
1584
1585     }
1586
1587     # We get SITELIBEXP and SITEARCHEXP directly via
1588     # Get_from_Config. When we are running standard modules, these
1589     # won't matter, we will set INSTALLDIRS to "perl". Otherwise we
1590     # set it to "site". I prefer that INSTALLDIRS be set from outside
1591     # MakeMaker.
1592     $self->{INSTALLDIRS} ||= "site";
1593
1594     # INST_LIB typically pre-set if building an extension after
1595     # perl has been built and installed. Setting INST_LIB allows
1596     # you to build directly into, say $Config::Config{privlibexp}.
1597     unless ($self->{INST_LIB}){
1598
1599
1600         ##### XXXXX We have to change this nonsense
1601
1602         if (defined $self->{PERL_SRC} and $self->{INSTALLDIRS} eq "perl") {
1603             $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
1604         } else {
1605             $self->{INST_LIB} = $self->catdir($self->curdir,"blib","lib");
1606         }
1607     }
1608     $self->{INST_ARCHLIB} ||= $self->catdir($self->curdir,"blib","arch");
1609     $self->{INST_BIN} ||= $self->catdir($self->curdir,'blib','bin');
1610
1611     # We need to set up INST_LIBDIR before init_libscan() for VMS
1612     my @parentdir = split(/::/, $self->{PARENT_NAME});
1613     $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)',@parentdir);
1614     $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)',@parentdir);
1615     $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)','auto','$(FULLEXT)');
1616     $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)','auto','$(FULLEXT)');
1617
1618     # INST_EXE is deprecated, should go away March '97
1619     $self->{INST_EXE} ||= $self->catdir($self->curdir,'blib','script');
1620     $self->{INST_SCRIPT} ||= $self->catdir($self->curdir,'blib','script');
1621
1622     # The user who requests an installation directory explicitly
1623     # should not have to tell us a architecture installation directory
1624     # as well. We look if a directory exists that is named after the
1625     # architecture. If not we take it as a sign that it should be the
1626     # same as the requested installation directory. Otherwise we take
1627     # the found one.
1628     # We do the same thing twice: for privlib/archlib and for sitelib/sitearch
1629     my($libpair);
1630     for $libpair ({l=>"privlib", a=>"archlib"}, {l=>"sitelib", a=>"sitearch"}) {
1631         my $lib = "install$libpair->{l}";
1632         my $Lib = uc $lib;
1633         my $Arch = uc "install$libpair->{a}";
1634         if( $self->{$Lib} && ! $self->{$Arch} ){
1635             my($ilib) = $Config{$lib};
1636             $ilib = VMS::Filespec::unixify($ilib) if $Is_VMS;
1637
1638             $self->prefixify($Arch,$ilib,$self->{$Lib});
1639
1640             unless (-d $self->{$Arch}) {
1641                 print STDOUT "Directory $self->{$Arch} not found, thusly\n" if $Verbose;
1642                 $self->{$Arch} = $self->{$Lib};
1643             }
1644             print STDOUT "Defaulting $Arch to $self->{$Arch}\n" if $Verbose;
1645         }
1646     }
1647
1648     # we have to look at the relation between $Config{prefix} and the
1649     # requested values. We're going to set the $Config{prefix} part of
1650     # all the installation path variables to literally $(PREFIX), so
1651     # the user can still say make PREFIX=foo
1652     my($configure_prefix) = $Config{'prefix'};
1653     $configure_prefix = VMS::Filespec::unixify($configure_prefix) if $Is_VMS;
1654     $self->{PREFIX} ||= $configure_prefix;
1655
1656
1657     my($install_variable,$search_prefix,$replace_prefix);
1658
1659     # The rule, taken from Configure, is that if prefix contains perl,
1660     # we shape the tree
1661     #    perlprefix/lib/                INSTALLPRIVLIB
1662     #    perlprefix/lib/pod/
1663     #    perlprefix/lib/site_perl/      INSTALLSITELIB
1664     #    perlprefix/bin/                INSTALLBIN
1665     #    perlprefix/man/                INSTALLMAN1DIR
1666     # else
1667     #    prefix/lib/perl5/              INSTALLPRIVLIB
1668     #    prefix/lib/perl5/pod/
1669     #    prefix/lib/perl5/site_perl/    INSTALLSITELIB
1670     #    prefix/bin/                    INSTALLBIN
1671     #    prefix/lib/perl5/man/          INSTALLMAN1DIR
1672
1673     $replace_prefix = qq[\$\(PREFIX\)];
1674     for $install_variable (qw/
1675                            INSTALLBIN
1676                            INSTALLSCRIPT
1677                            /) {
1678         $self->prefixify($install_variable,$configure_prefix,$replace_prefix);
1679     }
1680     $search_prefix = $configure_prefix =~ /perl/ ?
1681         $self->catdir($configure_prefix,"lib") :
1682         $self->catdir($configure_prefix,"lib","perl5");
1683     if ($self->{LIB}) {
1684         $self->{INSTALLPRIVLIB} = $self->{INSTALLSITELIB} = $self->{LIB};
1685         $self->{INSTALLARCHLIB} = $self->{INSTALLSITEARCH} = 
1686             $self->catdir($self->{LIB},$Config{'archname'});
1687     } else {
1688         $replace_prefix = $self->{PREFIX} =~ /perl/ ? 
1689             $self->catdir(qq[\$\(PREFIX\)],"lib") :
1690                 $self->catdir(qq[\$\(PREFIX\)],"lib","perl5");
1691         for $install_variable (qw/
1692                                INSTALLPRIVLIB
1693                                INSTALLARCHLIB
1694                                INSTALLSITELIB
1695                                INSTALLSITEARCH
1696                                /) {
1697             $self->prefixify($install_variable,$search_prefix,$replace_prefix);
1698         }
1699     }
1700     $search_prefix = $configure_prefix =~ /perl/ ?
1701         $self->catdir($configure_prefix,"man") :
1702             $self->catdir($configure_prefix,"lib","perl5","man");
1703     $replace_prefix = $self->{PREFIX} =~ /perl/ ? 
1704         $self->catdir(qq[\$\(PREFIX\)],"man") :
1705             $self->catdir(qq[\$\(PREFIX\)],"lib","perl5","man");
1706     for $install_variable (qw/
1707                            INSTALLMAN1DIR
1708                            INSTALLMAN3DIR
1709                            /) {
1710         $self->prefixify($install_variable,$search_prefix,$replace_prefix);
1711     }
1712
1713     # Now we head at the manpages. Maybe they DO NOT want manpages
1714     # installed
1715     $self->{INSTALLMAN1DIR} = $Config::Config{installman1dir}
1716         unless defined $self->{INSTALLMAN1DIR};
1717     unless (defined $self->{INST_MAN1DIR}){
1718         if ($self->{INSTALLMAN1DIR} =~ /^(none|\s*)$/){
1719             $self->{INST_MAN1DIR} = $self->{INSTALLMAN1DIR};
1720         } else {
1721             $self->{INST_MAN1DIR} = $self->catdir($self->curdir,'blib','man1');
1722         }
1723     }
1724     $self->{MAN1EXT} ||= $Config::Config{man1ext};
1725
1726     $self->{INSTALLMAN3DIR} = $Config::Config{installman3dir}
1727         unless defined $self->{INSTALLMAN3DIR};
1728     unless (defined $self->{INST_MAN3DIR}){
1729         if ($self->{INSTALLMAN3DIR} =~ /^(none|\s*)$/){
1730             $self->{INST_MAN3DIR} = $self->{INSTALLMAN3DIR};
1731         } else {
1732             $self->{INST_MAN3DIR} = $self->catdir($self->curdir,'blib','man3');
1733         }
1734     }
1735     $self->{MAN3EXT} ||= $Config::Config{man3ext};
1736
1737
1738     # Get some stuff out of %Config if we haven't yet done so
1739     print STDOUT "CONFIG must be an array ref\n"
1740         if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
1741     $self->{CONFIG} = [] unless (ref $self->{CONFIG});
1742     push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
1743     push(@{$self->{CONFIG}}, 'shellflags') if $Config::Config{shellflags};
1744     my(%once_only,$m);
1745     foreach $m (@{$self->{CONFIG}}){
1746         next if $once_only{$m};
1747         print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
1748                 unless exists $Config::Config{$m};
1749         $self->{uc $m} ||= $Config::Config{$m};
1750         $once_only{$m} = 1;
1751     }
1752
1753 # This is too dangerous:
1754 #    if ($^O eq "next") {
1755 #       $self->{AR} = "libtool";
1756 #       $self->{AR_STATIC_ARGS} = "-o";
1757 #    }
1758 # But I leave it as a placeholder
1759
1760     $self->{AR_STATIC_ARGS} ||= "cr";
1761
1762     # These should never be needed
1763     $self->{LD} ||= 'ld';
1764     $self->{OBJ_EXT} ||= '.o';
1765     $self->{LIB_EXT} ||= '.a';
1766
1767     $self->{MAP_TARGET} ||= "perl";
1768
1769     $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
1770
1771     # make a simple check if we find Exporter
1772     warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
1773         (Exporter.pm not found)"
1774         unless -f $self->catfile("$self->{PERL_LIB}","Exporter.pm") ||
1775         $self->{NAME} eq "ExtUtils::MakeMaker";
1776
1777     # Determine VERSION and VERSION_FROM
1778     ($self->{DISTNAME}=$self->{NAME}) =~ s#(::)#-#g unless $self->{DISTNAME};
1779     if ($self->{VERSION_FROM}){
1780         $self->{VERSION} = $self->parse_version($self->{VERSION_FROM}) or
1781             Carp::carp "WARNING: Setting VERSION via file '$self->{VERSION_FROM}' failed\n"
1782     }
1783
1784     # strip blanks
1785     if ($self->{VERSION}) {
1786         $self->{VERSION} =~ s/^\s+//;
1787         $self->{VERSION} =~ s/\s+$//;
1788     }
1789
1790     $self->{VERSION} ||= "0.10";
1791     ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
1792
1793
1794     # Graham Barr and Paul Marquess had some ideas how to ensure
1795     # version compatibility between the *.pm file and the
1796     # corresponding *.xs file. The bottomline was, that we need an
1797     # XS_VERSION macro that defaults to VERSION:
1798     $self->{XS_VERSION} ||= $self->{VERSION};
1799
1800     # --- Initialize Perl Binary Locations
1801
1802     # Find Perl 5. The only contract here is that both 'PERL' and 'FULLPERL'
1803     # will be working versions of perl 5. miniperl has priority over perl
1804     # for PERL to ensure that $(PERL) is usable while building ./ext/*
1805     my ($component,@defpath);
1806     foreach $component ($self->{PERL_SRC}, $self->path(), $Config::Config{binexp}) {
1807         push @defpath, $component if defined $component;
1808     }
1809     $self->{PERL} ||=
1810         $self->find_perl(5.0, [ $^X, 'miniperl','perl','perl5',"perl$]" ],
1811             \@defpath, $Verbose );
1812     # don't check if perl is executable, maybe they have decided to
1813     # supply switches with perl
1814
1815     # Define 'FULLPERL' to be a non-miniperl (used in test: target)
1816     ($self->{FULLPERL} = $self->{PERL}) =~ s/miniperl/perl/i
1817         unless ($self->{FULLPERL});
1818 }
1819
1820 =item init_others
1821
1822 Initializes EXTRALIBS, BSLOADLIBS, LDLOADLIBS, LIBS, LD_RUN_PATH,
1823 OBJECT, BOOTDEP, PERLMAINCC, LDFROM, LINKTYPE, NOOP, FIRST_MAKEFILE,
1824 MAKEFILE, NOECHO, RM_F, RM_RF, TEST_F, TOUCH, CP, MV, CHMOD, UMASK_NULL
1825
1826 =cut
1827
1828 sub init_others {       # --- Initialize Other Attributes
1829     my($self) = shift;
1830
1831     # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
1832     # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
1833     # undefined. In any case we turn it into an anon array:
1834
1835     # May check $Config{libs} too, thus not empty.
1836     $self->{LIBS}=[''] unless $self->{LIBS};
1837
1838     $self->{LIBS}=[$self->{LIBS}] if ref \$self->{LIBS} eq 'SCALAR';
1839     $self->{LD_RUN_PATH} = "";
1840     my($libs);
1841     foreach $libs ( @{$self->{LIBS}} ){
1842         $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
1843         my(@libs) = $self->extliblist($libs);
1844         if ($libs[0] or $libs[1] or $libs[2]){
1845             # LD_RUN_PATH now computed by ExtUtils::Liblist
1846             ($self->{EXTRALIBS}, $self->{BSLOADLIBS}, $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
1847             last;
1848         }
1849     }
1850
1851     if ( $self->{OBJECT} ) {
1852         $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
1853     } else {
1854         # init_dirscan should have found out, if we have C files
1855         $self->{OBJECT} = "";
1856         $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
1857     }
1858     $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
1859     $self->{BOOTDEP}  = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
1860     $self->{PERLMAINCC} ||= '$(CC)';
1861     $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
1862
1863     # Sanity check: don't define LINKTYPE = dynamic if we're skipping
1864     # the 'dynamic' section of MM.  We don't have this problem with
1865     # 'static', since we either must use it (%Config says we can't
1866     # use dynamic loading) or the caller asked for it explicitly.
1867     if (!$self->{LINKTYPE}) {
1868        $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
1869                         ? 'static'
1870                         : ($Config::Config{usedl} ? 'dynamic' : 'static');
1871     };
1872
1873     # These get overridden for VMS and maybe some other systems
1874     $self->{NOOP}  ||= '$(SHELL) -c true';
1875     $self->{FIRST_MAKEFILE} ||= "Makefile";
1876     $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE};
1877     $self->{MAKE_APERL_FILE} ||= "Makefile.aperl";
1878     $self->{NOECHO} = '@' unless defined $self->{NOECHO};
1879     $self->{RM_F}  ||= "rm -f";
1880     $self->{RM_RF} ||= "rm -rf";
1881     $self->{TOUCH} ||= "touch";
1882     $self->{TEST_F} ||= "test -f";
1883     $self->{CP} ||= "cp";
1884     $self->{MV} ||= "mv";
1885     $self->{CHMOD} ||= "chmod";
1886     $self->{UMASK_NULL} ||= "umask 0";
1887     $self->{DEV_NULL} ||= "> /dev/null 2>&1";
1888 }
1889
1890 =item install (o)
1891
1892 Defines the install target.
1893
1894 =cut
1895
1896 sub install {
1897     my($self, %attribs) = @_;
1898     my(@m);
1899
1900     push @m, q{
1901 install :: all pure_install doc_install
1902
1903 install_perl :: all pure_perl_install doc_perl_install
1904
1905 install_site :: all pure_site_install doc_site_install
1906
1907 install_ :: install_site
1908         @echo INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
1909
1910 pure_install :: pure_$(INSTALLDIRS)_install
1911
1912 doc_install :: doc_$(INSTALLDIRS)_install
1913         }.$self->{NOECHO}.q{echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
1914
1915 pure__install : pure_site_install
1916         @echo INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
1917
1918 doc__install : doc_site_install
1919         @echo INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
1920
1921 pure_perl_install ::
1922         }.$self->{NOECHO}.q{$(MOD_INSTALL) \
1923                 read }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
1924                 write }.$self->catfile('$(INSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
1925                 $(INST_LIB) $(INSTALLPRIVLIB) \
1926                 $(INST_ARCHLIB) $(INSTALLARCHLIB) \
1927                 $(INST_BIN) $(INSTALLBIN) \
1928                 $(INST_SCRIPT) $(INSTALLSCRIPT) \
1929                 $(INST_MAN1DIR) $(INSTALLMAN1DIR) \
1930                 $(INST_MAN3DIR) $(INSTALLMAN3DIR)
1931         }.$self->{NOECHO}.q{$(WARN_IF_OLD_PACKLIST) \
1932                 }.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{
1933
1934
1935 pure_site_install ::
1936         }.$self->{NOECHO}.q{$(MOD_INSTALL) \
1937                 read }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
1938                 write }.$self->catfile('$(INSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{ \
1939                 $(INST_LIB) $(INSTALLSITELIB) \
1940                 $(INST_ARCHLIB) $(INSTALLSITEARCH) \
1941                 $(INST_BIN) $(INSTALLBIN) \
1942                 $(INST_SCRIPT) $(INSTALLSCRIPT) \
1943                 $(INST_MAN1DIR) $(INSTALLMAN1DIR) \
1944                 $(INST_MAN3DIR) $(INSTALLMAN3DIR)
1945         }.$self->{NOECHO}.q{$(WARN_IF_OLD_PACKLIST) \
1946                 }.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{
1947
1948 doc_perl_install ::
1949         }.$self->{NOECHO}.q{$(DOC_INSTALL) \
1950                 "Module" "$(NAME)" \
1951                 "installed into" "$(INSTALLPRIVLIB)" \
1952                 LINKTYPE "$(LINKTYPE)" \
1953                 VERSION "$(VERSION)" \
1954                 EXE_FILES "$(EXE_FILES)" \
1955                 >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
1956
1957 doc_site_install ::
1958         }.$self->{NOECHO}.q{$(DOC_INSTALL) \
1959                 "Module" "$(NAME)" \
1960                 "installed into" "$(INSTALLSITELIB)" \
1961                 LINKTYPE "$(LINKTYPE)" \
1962                 VERSION "$(VERSION)" \
1963                 EXE_FILES "$(EXE_FILES)" \
1964                 >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
1965
1966 };
1967
1968     push @m, q{
1969 uninstall :: uninstall_from_$(INSTALLDIRS)dirs
1970
1971 uninstall_from_perldirs ::
1972         }.$self->{NOECHO}.
1973         q{$(UNINSTALL) }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{
1974
1975 uninstall_from_sitedirs ::
1976         }.$self->{NOECHO}.
1977         q{$(UNINSTALL) }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{
1978 };
1979
1980     join("",@m);
1981 }
1982
1983 =item installbin (o)
1984
1985 Defines targets to install EXE_FILES.
1986
1987 =cut
1988
1989 sub installbin {
1990     my($self) = shift;
1991     return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
1992     return "" unless @{$self->{EXE_FILES}};
1993     my(@m, $from, $to, %fromto, @to);
1994     push @m, $self->dir_target(qw[$(INST_SCRIPT)]);
1995     for $from (@{$self->{EXE_FILES}}) {
1996         my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
1997         local($_) = $path; # for backwards compatibility
1998         $to = $self->libscan($path);
1999         print "libscan($from) => '$to'\n" if ($Verbose >=2);
2000         $fromto{$from}=$to;
2001     }
2002     @to   = values %fromto;
2003     push(@m, qq{
2004 EXE_FILES = @{$self->{EXE_FILES}}
2005
2006 } . ($Is_Win32
2007   ? q{FIXIN = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
2008     -e "system qq[pl2bat.bat ].shift"
2009 } : q{FIXIN = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::MakeMaker \
2010     -e "MY->fixin(shift)"
2011 }).qq{
2012 all :: @to
2013         $self->{NOECHO}\$(NOOP)
2014
2015 realclean ::
2016         $self->{RM_F} @to
2017 });
2018
2019     while (($from,$to) = each %fromto) {
2020         last unless defined $from;
2021         my $todir = dirname($to);
2022         push @m, "
2023 $to: $from $self->{MAKEFILE} " . $self->catdir($todir,'.exists') . "
2024         $self->{NOECHO}$self->{RM_F} $to
2025         $self->{CP} $from $to
2026         \$(FIXIN) $to
2027 ";
2028     }
2029     join "", @m;
2030 }
2031
2032 =item libscan (o)
2033
2034 Takes a path to a file that is found by init_dirscan and returns false
2035 if we don't want to include this file in the library. Mainly used to
2036 exclude RCS, CVS, and SCCS directories from installation.
2037
2038 =cut
2039
2040 # ';
2041
2042 sub libscan {
2043     my($self,$path) = @_;
2044     return '' if $path =~ m:\b(RCS|CVS|SCCS)\b: ;
2045     $path;
2046 }
2047
2048 =item linkext (o)
2049
2050 Defines the linkext target which in turn defines the LINKTYPE.
2051
2052 =cut
2053
2054 sub linkext {
2055     my($self, %attribs) = @_;
2056     # LINKTYPE => static or dynamic or ''
2057     my($linktype) = defined $attribs{LINKTYPE} ?
2058       $attribs{LINKTYPE} : '$(LINKTYPE)';
2059     "
2060 linkext :: $linktype
2061         $self->{NOECHO}\$(NOOP)
2062 ";
2063 }
2064
2065 =item lsdir
2066
2067 Takes as arguments a directory name and a regular expression. Returns
2068 all entries in the directory that match the regular expression.
2069
2070 =cut
2071
2072 sub lsdir {
2073     my($self) = shift;
2074     my($dir, $regex) = @_;
2075     my(@ls);
2076     my $dh = new DirHandle;
2077     $dh->open($dir || ".") or return ();
2078     @ls = $dh->read;
2079     $dh->close;
2080     @ls = grep(/$regex/, @ls) if $regex;
2081     @ls;
2082 }
2083
2084 =item macro (o)
2085
2086 Simple subroutine to insert the macros defined by the macro attribute
2087 into the Makefile.
2088
2089 =cut
2090
2091 sub macro {
2092     my($self,%attribs) = @_;
2093     my(@m,$key,$val);
2094     while (($key,$val) = each %attribs){
2095         last unless defined $key;
2096         push @m, "$key = $val\n";
2097     }
2098     join "", @m;
2099 }
2100
2101 =item makeaperl (o)
2102
2103 Called by staticmake. Defines how to write the Makefile to produce a
2104 static new perl.
2105
2106 By default the Makefile produced includes all the static extensions in
2107 the perl library. (Purified versions of library files, e.g.,
2108 DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
2109
2110 =cut
2111
2112 sub makeaperl {
2113     my($self, %attribs) = @_;
2114     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
2115         @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
2116     my(@m);
2117     push @m, "
2118 # --- MakeMaker makeaperl section ---
2119 MAP_TARGET    = $target
2120 FULLPERL      = $self->{FULLPERL}
2121 ";
2122     return join '', @m if $self->{PARENT};
2123
2124     my($dir) = join ":", @{$self->{DIR}};
2125
2126     unless ($self->{MAKEAPERL}) {
2127         push @m, q{
2128 $(MAP_TARGET) :: static $(MAKE_APERL_FILE)
2129         $(MAKE) -f $(MAKE_APERL_FILE) $@
2130
2131 $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE)
2132         }.$self->{NOECHO}.q{echo Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
2133         }.$self->{NOECHO}.q{$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
2134                 Makefile.PL DIR=}, $dir, q{ \
2135                 MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
2136                 MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
2137
2138         foreach (@ARGV){
2139                 if( /\s/ ){
2140                         s/=(.*)/='$1'/;
2141                 }
2142                 push @m, " \\\n\t\t$_";
2143         }
2144 #       push @m, map( " \\\n\t\t$_", @ARGV );
2145         push @m, "\n";
2146
2147         return join '', @m;
2148     }
2149
2150
2151
2152     my($cccmd, $linkcmd, $lperl);
2153
2154
2155     $cccmd = $self->const_cccmd($libperl);
2156     $cccmd =~ s/^CCCMD\s*=\s*//;
2157     $cccmd =~ s/\$\(INC\)/ -I$self->{PERL_INC} /;
2158     $cccmd .= " $Config::Config{cccdlflags}"
2159         if ($Config::Config{useshrplib} eq 'true');
2160     $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
2161
2162     # The front matter of the linkcommand...
2163     $linkcmd = join ' ', "\$(CC)",
2164             grep($_, @Config{qw(large split ldflags ccdlflags)});
2165     $linkcmd =~ s/\s+/ /g;
2166     $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
2167
2168     # Which *.a files could we make use of...
2169     local(%static);
2170     require File::Find;
2171     File::Find::find(sub {
2172         return unless m/\Q$self->{LIB_EXT}\E$/;
2173         return if m/^libperl/;
2174         # Skip purified versions of libraries (e.g., DynaLoader_pure_p1_c0_032.a)
2175         return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
2176
2177         if( exists $self->{INCLUDE_EXT} ){
2178                 my $found = 0;
2179                 my $incl;
2180                 my $xx;
2181
2182                 ($xx = $File::Find::name) =~ s,.*?/auto/,,;
2183                 $xx =~ s,/?$_,,;
2184                 $xx =~ s,/,::,g;
2185
2186                 # Throw away anything not explicitly marked for inclusion.
2187                 # DynaLoader is implied.
2188                 foreach $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
2189                         if( $xx eq $incl ){
2190                                 $found++;
2191                                 last;
2192                         }
2193                 }
2194                 return unless $found;
2195         }
2196         elsif( exists $self->{EXCLUDE_EXT} ){
2197                 my $excl;
2198                 my $xx;
2199
2200                 ($xx = $File::Find::name) =~ s,.*?/auto/,,;
2201                 $xx =~ s,/?$_,,;
2202                 $xx =~ s,/,::,g;
2203
2204                 # Throw away anything explicitly marked for exclusion
2205                 foreach $excl (@{$self->{EXCLUDE_EXT}}){
2206                         return if( $xx eq $excl );
2207                 }
2208         }
2209
2210         # don't include the installed version of this extension. I
2211         # leave this line here, although it is not necessary anymore:
2212         # I patched minimod.PL instead, so that Miniperl.pm won't
2213         # enclude duplicates
2214
2215         # Once the patch to minimod.PL is in the distribution, I can
2216         # drop it
2217         return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}$:;
2218         use Cwd 'cwd';
2219         $static{cwd() . "/" . $_}++;
2220     }, grep( -d $_, @{$searchdirs || []}) );
2221
2222     # We trust that what has been handed in as argument, will be buildable
2223     $static = [] unless $static;
2224     @static{@{$static}} = (1) x @{$static};
2225
2226     $extra = [] unless $extra && ref $extra eq 'ARRAY';
2227     for (sort keys %static) {
2228         next unless /\Q$self->{LIB_EXT}\E$/;
2229         $_ = dirname($_) . "/extralibs.ld";
2230         push @$extra, $_;
2231     }
2232
2233     grep(s/^/-I/, @{$perlinc || []});
2234
2235     $target = "perl" unless $target;
2236     $tmp = "." unless $tmp;
2237
2238 # MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
2239 # regenerate the Makefiles, MAP_STATIC and the dependencies for
2240 # extralibs.all are computed correctly
2241     push @m, "
2242 MAP_LINKCMD   = $linkcmd
2243 MAP_PERLINC   = @{$perlinc || []}
2244 MAP_STATIC    = ",
2245 join(" \\\n\t", reverse sort keys %static), "
2246
2247 MAP_PRELIBS   = $Config::Config{libs} $Config::Config{cryptlib}
2248 ";
2249
2250     if (defined $libperl) {
2251         ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
2252     }
2253     unless ($libperl && -f $lperl) { # Ilya's code...
2254         my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
2255         $libperl ||= "libperl$self->{LIB_EXT}";
2256         $libperl   = "$dir/$libperl";
2257         $lperl   ||= "libperl$self->{LIB_EXT}";
2258         $lperl     = "$dir/$lperl";
2259
2260         if (! -f $libperl and ! -f $lperl) {
2261           # We did not find a static libperl. Maybe there is a shared one?
2262           if ($^O eq 'solaris' or $^O eq 'sunos') {
2263             $lperl  = $libperl = "$dir/$Config::Config{libperl}";
2264             # SUNOS ld does not take the full path to a shared library
2265             $libperl = '' if $^O eq 'sunos';
2266           }
2267         }
2268
2269         print STDOUT "Warning: $libperl not found
2270     If you're going to build a static perl binary, make sure perl is installed
2271     otherwise ignore this warning\n"
2272                 unless (-f $lperl || defined($self->{PERL_SRC}));
2273     }
2274
2275     push @m, "
2276 MAP_LIBPERL = $libperl
2277 ";
2278
2279     push @m, "
2280 \$(INST_ARCHAUTODIR)/extralibs.all: \$(INST_ARCHAUTODIR)/.exists ".join(" \\\n\t", @$extra)."
2281         $self->{NOECHO}$self->{RM_F} \$\@
2282         $self->{NOECHO}\$(TOUCH) \$\@
2283 ";
2284
2285     my $catfile;
2286     foreach $catfile (@$extra){
2287         push @m, "\tcat $catfile >> \$\@\n";
2288     }
2289     # SUNOS ld does not take the full path to a shared library
2290     my $llibperl = ($libperl)?'$(MAP_LIBPERL)':'-lperl';
2291
2292     # Brain dead solaris linker does not use LD_RUN_PATH?
2293     # This fixes dynamic extensions which need shared libs
2294     my $ldfrom = ($^O eq 'solaris')?
2295            join(' ', map "-R$_", split /:/, $self->{LD_RUN_PATH}):'';
2296
2297 push @m, "
2298 \$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all
2299         \$(MAP_LINKCMD) -o \$\@ \$(OPTIMIZE) $tmp/perlmain\$(OBJ_EXT) $ldfrom $llibperl \$(MAP_STATIC) `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS)
2300         $self->{NOECHO}echo 'To install the new \"\$(MAP_TARGET)\" binary, call'
2301         $self->{NOECHO}echo '    make -f $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
2302         $self->{NOECHO}echo 'To remove the intermediate files say'
2303         $self->{NOECHO}echo '    make -f $makefilename map_clean'
2304
2305 $tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c
2306 ";
2307     push @m, "\tcd $tmp && $cccmd -I\$(PERL_INC) perlmain.c\n";
2308
2309     push @m, qq{
2310 $tmp/perlmain.c: $makefilename}, q{
2311         }.$self->{NOECHO}.q{echo Writing $@
2312         }.$self->{NOECHO}.q{$(PERL) $(MAP_PERLINC) -MExtUtils::Miniperl \\
2313                 -e "writemain(grep s#.*/auto/##, qw|$(MAP_STATIC)|)" > $@t && $(MV) $@t $@
2314
2315 };
2316     push @m, "\t",$self->{NOECHO}.q{$(PERL) $(INSTALLSCRIPT)/fixpmain
2317 } if (defined (&Dos::UseLFN) && Dos::UseLFN()==0);
2318
2319
2320     push @m, q{
2321 doc_inst_perl:
2322         }.$self->{NOECHO}.q{echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
2323         }.$self->{NOECHO}.q{$(DOC_INSTALL) \
2324                 "Perl binary" "$(MAP_TARGET)" \
2325                 MAP_STATIC "$(MAP_STATIC)" \
2326                 MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
2327                 MAP_LIBPERL "$(MAP_LIBPERL)" \
2328                 >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
2329
2330 };
2331
2332     push @m, q{
2333 inst_perl: pure_inst_perl doc_inst_perl
2334
2335 pure_inst_perl: $(MAP_TARGET)
2336         }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(INSTALLBIN)','$(MAP_TARGET)').q{
2337
2338 clean :: map_clean
2339
2340 map_clean :
2341         }.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
2342 };
2343
2344     join '', @m;
2345 }
2346
2347 =item makefile (o)
2348
2349 Defines how to rewrite the Makefile.
2350
2351 =cut
2352
2353 sub makefile {
2354     my($self) = shift;
2355     my @m;
2356     # We do not know what target was originally specified so we
2357     # must force a manual rerun to be sure. But as it should only
2358     # happen very rarely it is not a significant problem.
2359     push @m, '
2360 $(OBJECT) : $(FIRST_MAKEFILE)
2361 ' if $self->{OBJECT};
2362
2363     push @m, q{
2364 # We take a very conservative approach here, but it\'s worth it.
2365 # We move Makefile to Makefile.old here to avoid gnu make looping.
2366 }.$self->{MAKEFILE}.q{ : Makefile.PL $(CONFIGDEP)
2367         }.$self->{NOECHO}.q{echo "Makefile out-of-date with respect to $?"
2368         }.$self->{NOECHO}.q{echo "Cleaning current config before rebuilding Makefile..."
2369         -}.$self->{NOECHO}.q{$(MV) }."$self->{MAKEFILE} $self->{MAKEFILE}.old".q{
2370         -$(MAKE) -f }.$self->{MAKEFILE}.q{.old clean $(DEV_NULL) || $(NOOP)
2371         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" Makefile.PL }.join(" ",map(qq["$_"],@ARGV)).q{
2372         }.$self->{NOECHO}.q{echo "==> Your Makefile has been rebuilt. <=="
2373         }.$self->{NOECHO}.q{echo "==> Please rerun the make command.  <=="
2374         false
2375
2376 # To change behavior to :: would be nice, but would break Tk b9.02
2377 # so you find such a warning below the dist target.
2378 #}.$self->{MAKEFILE}.q{ :: $(VERSION_FROM)
2379 #       }.$self->{NOECHO}.q{echo "Warning: Makefile possibly out of date with $(VERSION_FROM)"
2380 };
2381
2382     join "", @m;
2383 }
2384
2385 =item manifypods (o)
2386
2387 Defines targets and routines to translate the pods into manpages and
2388 put them into the INST_* directories.
2389
2390 =cut
2391
2392 sub manifypods {
2393     my($self, %attribs) = @_;
2394     return "\nmanifypods :\n\t$self->{NOECHO}\$(NOOP)\n" unless %{$self->{MAN3PODS}} or %{$self->{MAN1PODS}};
2395     my($dist);
2396     my($pod2man_exe);
2397     if (defined $self->{PERL_SRC}) {
2398         $pod2man_exe = $self->catfile($self->{PERL_SRC},'pod','pod2man');
2399     } else {
2400         $pod2man_exe = $self->catfile($Config{scriptdirexp},'pod2man');
2401     }
2402     unless ($self->perl_script($pod2man_exe)) {
2403         # No pod2man but some MAN3PODS to be installed
2404         print <<END;
2405
2406 Warning: I could not locate your pod2man program. Please make sure,
2407          your pod2man program is in your PATH before you execute 'make'
2408
2409 END
2410         $pod2man_exe = "-S pod2man";
2411     }
2412     my(@m);
2413     push @m,
2414 qq[POD2MAN_EXE = $pod2man_exe\n],
2415 q[POD2MAN = $(PERL) -we '%m=@ARGV;for (keys %m){' \\
2416 -e 'next if -e $$m{$$_} && -M $$m{$$_} < -M $$_ && -M $$m{$$_} < -M "].$self->{MAKEFILE}.q[";' \\
2417 -e 'print "Manifying $$m{$$_}\n";' \\
2418 -e 'system(qq[$$^X ].q["-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" $(POD2MAN_EXE) ].qq[$$_>$$m{$$_}])==0 or warn "Couldn\\047t install $$m{$$_}\n";' \\
2419 -e 'chmod 0644, $$m{$$_} or warn "chmod 644 $$m{$$_}: $$!\n";}'
2420 ];
2421     push @m, "\nmanifypods : ";
2422     push @m, join " \\\n\t", keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}};
2423
2424     push(@m,"\n");
2425     if (%{$self->{MAN1PODS}} || %{$self->{MAN3PODS}}) {
2426         push @m, "\t$self->{NOECHO}\$(POD2MAN) \\\n\t";
2427         push @m, join " \\\n\t", %{$self->{MAN1PODS}}, %{$self->{MAN3PODS}};
2428     }
2429     join('', @m);
2430 }
2431
2432 =item maybe_command
2433
2434 Returns true, if the argument is likely to be a command.
2435
2436 =cut
2437
2438 sub maybe_command {
2439     my($self,$file) = @_;
2440     return $file if -x $file && ! -d $file;
2441     return;
2442 }
2443
2444 =item maybe_command_in_dirs
2445
2446 method under development. Not yet used. Ask Ilya :-)
2447
2448 =cut
2449
2450 sub maybe_command_in_dirs {     # $ver is optional argument if looking for perl
2451 # Ilya's suggestion. Not yet used, want to understand it first, but at least the code is here
2452     my($self, $names, $dirs, $trace, $ver) = @_;
2453     my($name, $dir);
2454     foreach $dir (@$dirs){
2455         next unless defined $dir; # $self->{PERL_SRC} may be undefined
2456         foreach $name (@$names){
2457             my($abs,$tryabs);
2458             if ($self->file_name_is_absolute($name)) { # /foo/bar
2459                 $abs = $name;
2460             } elsif ($self->canonpath($name) eq $self->canonpath(basename($name))) { # bar
2461                 $abs = $self->catfile($dir, $name);
2462             } else { # foo/bar
2463                 $abs = $self->catfile($self->curdir, $name);
2464             }
2465             print "Checking $abs for $name\n" if ($trace >= 2);
2466             next unless $tryabs = $self->maybe_command($abs);
2467             print "Substituting $tryabs instead of $abs\n"
2468                 if ($trace >= 2 and $tryabs ne $abs);
2469             $abs = $tryabs;
2470             if (defined $ver) {
2471                 print "Executing $abs\n" if ($trace >= 2);
2472                 if (`$abs -e 'require $ver; print "VER_OK\n" ' 2>&1` =~ /VER_OK/) {
2473                     print "Using PERL=$abs\n" if $trace;
2474                     return $abs;
2475                 }
2476             } else { # Do not look for perl
2477                 return $abs;
2478             }
2479         }
2480     }
2481 }
2482
2483 =item needs_linking (o)
2484
2485 Does this module need linking? Looks into subdirectory objects (see
2486 also has_link_code())
2487
2488 =cut
2489
2490 sub needs_linking {
2491     my($self) = shift;
2492     my($child,$caller);
2493     $caller = (caller(0))[3];
2494     Carp::confess("Needs_linking called too early") if $caller =~ /^ExtUtils::MakeMaker::/;
2495     return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
2496     if ($self->has_link_code or $self->{MAKEAPERL}){
2497         $self->{NEEDS_LINKING} = 1;
2498         return 1;
2499     }
2500     foreach $child (keys %{$self->{CHILDREN}}) {
2501         if ($self->{CHILDREN}->{$child}->needs_linking) {
2502             $self->{NEEDS_LINKING} = 1;
2503             return 1;
2504         }
2505     }
2506     return $self->{NEEDS_LINKING} = 0;
2507 }
2508
2509 =item nicetext
2510
2511 misnamed method (will have to be changed). The MM_Unix method just
2512 returns the argument without further processing.
2513
2514 On VMS used to insure that colons marking targets are preceded by
2515 space - most Unix Makes don't need this, but it's necessary under VMS
2516 to distinguish the target delimiter from a colon appearing as part of
2517 a filespec.
2518
2519 =cut
2520
2521 sub nicetext {
2522     my($self,$text) = @_;
2523     $text;
2524 }
2525
2526 =item parse_version
2527
2528 parse a file and return what you think is $VERSION in this file set to
2529
2530 =cut
2531
2532 sub parse_version {
2533     my($self,$parsefile) = @_;
2534     my $result;
2535     local *FH;
2536     local $/ = "\n";
2537     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
2538     my $inpod = 0;
2539     while (<FH>) {
2540         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2541         next if $inpod;
2542         chop;
2543         # next unless /\$(([\w\:\']*)\bVERSION)\b.*\=/;
2544         next unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
2545         my $eval = qq{
2546             package ExtUtils::MakeMaker::_version;
2547             no strict;
2548
2549             local $1$2;
2550             \$$2=undef; do {
2551                 $_
2552             }; \$$2
2553         };
2554         local($^W) = 0;
2555         $result = eval($eval);
2556         die "Could not eval '$eval' in $parsefile: $@" if $@;
2557         $result = "undef" unless defined $result;
2558         last;
2559     }
2560     close FH;
2561     return $result;
2562 }
2563
2564
2565 =item pasthru (o)
2566
2567 Defines the string that is passed to recursive make calls in
2568 subdirectories.
2569
2570 =cut
2571
2572 sub pasthru {
2573     my($self) = shift;
2574     my(@m,$key);
2575
2576     my(@pasthru);
2577     my($sep) = $Is_VMS ? ',' : '';
2578     $sep .= "\\\n\t";
2579
2580     foreach $key (qw(LIB LIBPERL_A LINKTYPE PREFIX OPTIMIZE)){
2581         push @pasthru, "$key=\"\$($key)\"";
2582     }
2583
2584     push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
2585     join "", @m;
2586 }
2587
2588 =item path
2589
2590 Takes no argument, returns the environment variable PATH as an array.
2591
2592 =cut
2593
2594 sub path {
2595     my($self) = @_;
2596     my $path_sep = ($Is_OS2 || $Is_Dos) ? ";" : ":";
2597     my $path = $ENV{PATH};
2598     $path =~ s:\\:/:g if $Is_OS2;
2599     my @path = split $path_sep, $path;
2600     foreach(@path) { $_ = '.' if $_ eq '' }
2601     @path;
2602 }
2603
2604 =item perl_script
2605
2606 Takes one argument, a file name, and returns the file name, if the
2607 argument is likely to be a perl script. On MM_Unix this is true for
2608 any ordinary, readable file.
2609
2610 =cut
2611
2612 sub perl_script {
2613     my($self,$file) = @_;
2614     return $file if -r $file && -f _;
2615     return;
2616 }
2617
2618 =item perldepend (o)
2619
2620 Defines the dependency from all *.h files that come with the perl
2621 distribution.
2622
2623 =cut
2624
2625 sub perldepend {
2626     my($self) = shift;
2627     my(@m);
2628     push @m, q{
2629 # Check for unpropogated config.sh changes. Should never happen.
2630 # We do NOT just update config.h because that is not sufficient.
2631 # An out of date config.h is not fatal but complains loudly!
2632 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
2633         -}.$self->{NOECHO}.q{echo "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
2634
2635 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
2636         }.$self->{NOECHO}.q{echo "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
2637         cd $(PERL_SRC) && $(MAKE) lib/Config.pm
2638 } if $self->{PERL_SRC};
2639
2640     return join "", @m unless $self->needs_linking;
2641
2642     push @m, q{
2643 PERL_HDRS = \
2644 $(PERL_INC)/EXTERN.h       $(PERL_INC)/gv.h           $(PERL_INC)/pp.h       \
2645 $(PERL_INC)/INTERN.h       $(PERL_INC)/handy.h        $(PERL_INC)/proto.h    \
2646 $(PERL_INC)/XSUB.h         $(PERL_INC)/hv.h           $(PERL_INC)/regcomp.h  \
2647 $(PERL_INC)/av.h           $(PERL_INC)/keywords.h     $(PERL_INC)/regexp.h   \
2648 $(PERL_INC)/config.h       $(PERL_INC)/mg.h           $(PERL_INC)/scope.h    \
2649 $(PERL_INC)/cop.h          $(PERL_INC)/op.h           $(PERL_INC)/sv.h       \
2650 $(PERL_INC)/cv.h           $(PERL_INC)/opcode.h       $(PERL_INC)/unixish.h  \
2651 $(PERL_INC)/dosish.h       $(PERL_INC)/patchlevel.h   $(PERL_INC)/util.h     \
2652 $(PERL_INC)/embed.h        $(PERL_INC)/perl.h                                \
2653 $(PERL_INC)/form.h         $(PERL_INC)/perly.h
2654
2655 $(OBJECT) : $(PERL_HDRS)
2656 } if $self->{OBJECT};
2657
2658     push @m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
2659
2660     join "\n", @m;
2661 }
2662
2663 =item pm_to_blib
2664
2665 Defines target that copies all files in the hash PM to their
2666 destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
2667
2668 =cut
2669
2670 sub pm_to_blib {
2671     my $self = shift;
2672     my($autodir) = $self->catdir('$(INST_LIB)','auto');
2673     return q{
2674 pm_to_blib: $(TO_INST_PM)
2675         }.$self->{NOECHO}.q{$(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" \
2676         "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MExtUtils::Install \
2677         -e "pm_to_blib({qw{$(PM_TO_BLIB)}},'}.$autodir.q{')"
2678         }.$self->{NOECHO}.q{$(TOUCH) $@
2679 };
2680 }
2681
2682 =item post_constants (o)
2683
2684 Returns an empty string per default. Dedicated to overrides from
2685 within Makefile.PL after all constants have been defined.
2686
2687 =cut
2688
2689 sub post_constants{
2690     my($self) = shift;
2691     "";
2692 }
2693
2694 =item post_initialize (o)
2695
2696 Returns an empty string per default. Used in Makefile.PLs to add some
2697 chunk of text to the Makefile after the object is initialized.
2698
2699 =cut
2700
2701 sub post_initialize {
2702     my($self) = shift;
2703     "";
2704 }
2705
2706 =item postamble (o)
2707
2708 Returns an empty string. Can be used in Makefile.PLs to write some
2709 text to the Makefile at the end.
2710
2711 =cut
2712
2713 sub postamble {
2714     my($self) = shift;
2715     "";
2716 }
2717
2718 =item prefixify
2719
2720 Check a path variable in $self from %Config, if it contains a prefix,
2721 and replace it with another one.
2722
2723 Takes as arguments an attribute name, a search prefix and a
2724 replacement prefix. Changes the attribute in the object.
2725
2726 =cut
2727
2728 sub prefixify {
2729     my($self,$var,$sprefix,$rprefix) = @_;
2730     $self->{uc $var} ||= $Config{lc $var};
2731     $self->{uc $var} = VMS::Filespec::unixpath($self->{uc $var}) if $Is_VMS;
2732     $self->{uc $var} =~ s/\Q$sprefix\E/$rprefix/;
2733 }
2734
2735 =item processPL (o)
2736
2737 Defines targets to run *.PL files.
2738
2739 =cut
2740
2741 sub processPL {
2742     my($self) = shift;
2743     return "" unless $self->{PL_FILES};
2744     my(@m, $plfile);
2745     foreach $plfile (sort keys %{$self->{PL_FILES}}) {
2746         push @m, "
2747 all :: $self->{PL_FILES}->{$plfile}
2748         $self->{NOECHO}\$(NOOP)
2749
2750 $self->{PL_FILES}->{$plfile} :: $plfile
2751         \$(PERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) $plfile
2752 ";
2753     }
2754     join "", @m;
2755 }
2756
2757 =item realclean (o)
2758
2759 Defines the realclean target.
2760
2761 =cut
2762
2763 sub realclean {
2764     my($self, %attribs) = @_;
2765     my(@m);
2766     push(@m,'
2767 # Delete temporary files (via clean) and also delete installed files
2768 realclean purge ::  clean
2769 ');
2770     # realclean subdirectories first (already cleaned)
2771     my $sub = "\t-cd %s && \$(TEST_F) %s && \$(MAKE) %s realclean\n";
2772     foreach(@{$self->{DIR}}){
2773         push(@m, sprintf($sub,$_,"$self->{MAKEFILE}.old","-f $self->{MAKEFILE}.old"));
2774         push(@m, sprintf($sub,$_,"$self->{MAKEFILE}",''));
2775     }
2776     push(@m, "  $self->{RM_RF} \$(INST_AUTODIR) \$(INST_ARCHAUTODIR)\n");
2777     if( $self->has_link_code ){
2778         push(@m, "      $self->{RM_F} \$(INST_DYNAMIC) \$(INST_BOOT)\n");
2779         push(@m, "      $self->{RM_F} \$(INST_STATIC)\n");
2780     }
2781     push(@m, "  $self->{RM_F} " . join(" ", values %{$self->{PM}}) . "\n");
2782     my(@otherfiles) = ($self->{MAKEFILE},
2783                        "$self->{MAKEFILE}.old"); # Makefiles last
2784     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
2785     push(@m, "  $self->{RM_RF} @otherfiles\n") if @otherfiles;
2786     push(@m, "  $attribs{POSTOP}\n")       if $attribs{POSTOP};
2787     join("", @m);
2788 }
2789
2790 =item replace_manpage_separator
2791
2792 Takes the name of a package, which may be a nested package, in the
2793 form Foo/Bar and replaces the slash with C<::>. Returns the replacement.
2794
2795 =cut
2796
2797 sub replace_manpage_separator {
2798     my($self,$man) = @_;
2799     $man =~ s,/+,::,g;
2800     $man;
2801 }
2802
2803 =item static (o)
2804
2805 Defines the static target.
2806
2807 =cut
2808
2809 sub static {
2810 # --- Static Loading Sections ---
2811
2812     my($self) = shift;
2813     '
2814 ## $(INST_PM) has been moved to the all: target.
2815 ## It remains here for awhile to allow for old usage: "make static"
2816 #static :: '.$self->{MAKEFILE}.' $(INST_STATIC) $(INST_PM)
2817 static :: '.$self->{MAKEFILE}.' $(INST_STATIC)
2818         '.$self->{NOECHO}.'$(NOOP)
2819 ';
2820 }
2821
2822 =item static_lib (o)
2823
2824 Defines how to produce the *.a (or equivalent) files.
2825
2826 =cut
2827
2828 sub static_lib {
2829     my($self) = @_;
2830 # Come to think of it, if there are subdirs with linkcode, we still have no INST_STATIC
2831 #    return '' unless $self->needs_linking(); #might be because of a subdir
2832
2833     return '' unless $self->has_link_code;
2834
2835     my(@m);
2836     push(@m, <<'END');
2837 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)/.exists
2838         $(RM_RF) $@
2839 END
2840     # If this extension has it's own library (eg SDBM_File)
2841     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
2842     push(@m, "\t$self->{CP} \$(MYEXTLIB) \$\@\n") if $self->{MYEXTLIB};
2843
2844     push @m,
2845 q{      $(AR) $(AR_STATIC_ARGS) $@ $(OBJECT) && $(RANLIB) $@
2846         $(CHMOD) 755 $@
2847         }.$self->{NOECHO}.q{echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
2848 };
2849     # Old mechanism - still available:
2850     push @m,
2851 "\t$self->{NOECHO}".q{echo "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
2852 }       if $self->{PERL_SRC} && $self->{EXTRALIBS};
2853     push @m, "\n";
2854
2855     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
2856     join('', "\n",@m);
2857 }
2858
2859 =item staticmake (o)
2860
2861 Calls makeaperl.
2862
2863 =cut
2864
2865 sub staticmake {
2866     my($self, %attribs) = @_;
2867     my(@static);
2868
2869     my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
2870
2871     # And as it's not yet built, we add the current extension
2872     # but only if it has some C code (or XS code, which implies C code)
2873     if (@{$self->{C}}) {
2874         @static = $self->catfile($self->{INST_ARCHLIB},
2875                                  "auto",
2876                                  $self->{FULLEXT},
2877                                  "$self->{BASEEXT}$self->{LIB_EXT}"
2878                                 );
2879     }
2880
2881     # Either we determine now, which libraries we will produce in the
2882     # subdirectories or we do it at runtime of the make.
2883
2884     # We could ask all subdir objects, but I cannot imagine, why it
2885     # would be necessary.
2886
2887     # Instead we determine all libraries for the new perl at
2888     # runtime.
2889     my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
2890
2891     $self->makeaperl(MAKE       => $self->{MAKEFILE},
2892                      DIRS       => \@searchdirs,
2893                      STAT       => \@static,
2894                      INCL       => \@perlinc,
2895                      TARGET     => $self->{MAP_TARGET},
2896                      TMP        => "",
2897                      LIBPERL    => $self->{LIBPERL_A}
2898                     );
2899 }
2900
2901 =item subdir_x (o)
2902
2903 Helper subroutine for subdirs
2904
2905 =cut
2906
2907 sub subdir_x {
2908     my($self, $subdir) = @_;
2909     my(@m);
2910     qq{
2911
2912 subdirs ::
2913         $self->{NOECHO}cd $subdir && \$(MAKE) all \$(PASTHRU)
2914
2915 };
2916 }
2917
2918 =item subdirs (o)
2919
2920 Defines targets to process subdirectories.
2921
2922 =cut
2923
2924 sub subdirs {
2925 # --- Sub-directory Sections ---
2926     my($self) = shift;
2927     my(@m,$dir);
2928     # This method provides a mechanism to automatically deal with
2929     # subdirectories containing further Makefile.PL scripts.
2930     # It calls the subdir_x() method for each subdirectory.
2931     foreach $dir (@{$self->{DIR}}){
2932         push(@m, $self->subdir_x($dir));
2933 ####    print "Including $dir subdirectory\n";
2934     }
2935     if (@m){
2936         unshift(@m, "
2937 # The default clean, realclean and test targets in this Makefile
2938 # have automatically been given entries for each subdir.
2939
2940 ");
2941     } else {
2942         push(@m, "\n# none")
2943     }
2944     join('',@m);
2945 }
2946
2947 =item test (o)
2948
2949 Defines the test targets.
2950
2951 =cut
2952
2953 sub test {
2954 # --- Test and Installation Sections ---
2955
2956     my($self, %attribs) = @_;
2957     my $tests = $attribs{TESTS};
2958     if (!$tests && -d 't') {
2959         $tests = $Is_Win32 ? join(' ', <t\\*.t>) : 't/*.t';
2960     }
2961     # note: 'test.pl' name is also hardcoded in init_dirscan()
2962     my(@m);
2963     push(@m,"
2964 TEST_VERBOSE=0
2965 TEST_TYPE=test_\$(LINKTYPE)
2966 TEST_FILE = test.pl
2967 TEST_FILES = $tests
2968 TESTDB_SW = -d
2969
2970 testdb :: testdb_\$(LINKTYPE)
2971
2972 test :: \$(TEST_TYPE)
2973 ");
2974     push(@m, map("\t$self->{NOECHO}cd $_ && \$(TEST_F) $self->{MAKEFILE} && \$(MAKE) test \$(PASTHRU)\n",
2975                  @{$self->{DIR}}));
2976     push(@m, "\t$self->{NOECHO}echo 'No tests defined for \$(NAME) extension.'\n")
2977         unless $tests or -f "test.pl" or @{$self->{DIR}};
2978     push(@m, "\n");
2979
2980     push(@m, "test_dynamic :: pure_all\n");
2981     push(@m, $self->test_via_harness('$(FULLPERL)', '$(TEST_FILES)')) if $tests;
2982     push(@m, $self->test_via_script('$(FULLPERL)', '$(TEST_FILE)')) if -f "test.pl";
2983     push(@m, "\n");
2984
2985     push(@m, "testdb_dynamic :: pure_all\n");
2986     push(@m, $self->test_via_script('$(FULLPERL) $(TESTDB_SW)', '$(TEST_FILE)'));
2987     push(@m, "\n");
2988
2989     # Occasionally we may face this degenerate target:
2990     push @m, "test_ : test_dynamic\n\n";
2991
2992     if ($self->needs_linking()) {
2993         push(@m, "test_static :: pure_all \$(MAP_TARGET)\n");
2994         push(@m, $self->test_via_harness('./$(MAP_TARGET)', '$(TEST_FILES)')) if $tests;
2995         push(@m, $self->test_via_script('./$(MAP_TARGET)', '$(TEST_FILE)')) if -f "test.pl";
2996         push(@m, "\n");
2997         push(@m, "testdb_static :: pure_all \$(MAP_TARGET)\n");
2998         push(@m, $self->test_via_script('./$(MAP_TARGET) $(TESTDB_SW)', '$(TEST_FILE)'));
2999         push(@m, "\n");
3000     } else {
3001         push @m, "test_static :: test_dynamic\n";
3002         push @m, "testdb_static :: testdb_dynamic\n";
3003     }
3004     join("", @m);
3005 }
3006
3007 =item test_via_harness (o)
3008
3009 Helper method to write the test targets
3010
3011 =cut
3012
3013 sub test_via_harness {
3014     my($self, $perl, $tests) = @_;
3015     $perl = "PERL_DL_NONLAZY=1 $perl" unless $Is_Win32;
3016     "\t$perl".q! -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e 'use Test::Harness qw(&runtests $$verbose); $$verbose=$(TEST_VERBOSE); runtests @ARGV;' !."$tests\n";
3017 }
3018
3019 =item test_via_script (o)
3020
3021 Other helper method for test.
3022
3023 =cut
3024
3025 sub test_via_script {
3026     my($self, $perl, $script) = @_;
3027     $perl = "PERL_DL_NONLAZY=1 $perl" unless $Is_Win32;
3028     qq{\t$perl}.q{ -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) }.qq{$script
3029 };
3030 }
3031
3032 =item tool_autosplit (o)
3033
3034 Defines a simple perl call that runs autosplit. May be deprecated by
3035 pm_to_blib soon.
3036
3037 =cut
3038
3039 sub tool_autosplit {
3040 # --- Tool Sections ---
3041
3042     my($self, %attribs) = @_;
3043     my($asl) = "";
3044     $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
3045     q{
3046 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
3047 AUTOSPLITFILE = $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e 'use AutoSplit;}.$asl.q{autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) ;'
3048 };
3049 }
3050
3051 =item tools_other (o)
3052
3053 Defines SHELL, LD, TOUCH, CP, MV, RM_F, RM_RF, CHMOD, UMASK_NULL in
3054 the Makefile. Also defines the perl programs MKPATH,
3055 WARN_IF_OLD_PACKLIST, MOD_INSTALL. DOC_INSTALL, and UNINSTALL.
3056
3057 =cut
3058
3059 sub tools_other {
3060     my($self) = shift;
3061     my @m;
3062     my $bin_sh = $Config{sh} || '/bin/sh';
3063     push @m, qq{
3064 SHELL = $bin_sh
3065 };
3066
3067     for (qw/ CHMOD CP LD MV NOOP RM_F RM_RF TEST_F TOUCH UMASK_NULL DEV_NULL/ ) {
3068         push @m, "$_ = $self->{$_}\n";
3069     }
3070
3071     push @m, q{
3072 # The following is a portable way to say mkdir -p
3073 # To see which directories are created, change the if 0 to if 1
3074 MKPATH = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e mkpath
3075
3076 # This helps us to minimize the effect of the .exists files A yet
3077 # better solution would be to have a stable file in the perl
3078 # distribution with a timestamp of zero. But this solution doesn't
3079 # need any changes to the core distribution and works with older perls
3080 EQUALIZE_TIMESTAMP = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e eqtime
3081 };
3082
3083
3084     return join "", @m if $self->{PARENT};
3085
3086     push @m, q{
3087 # Here we warn users that an old packlist file was found somewhere,
3088 # and that they should call some uninstall routine
3089 WARN_IF_OLD_PACKLIST = $(PERL) -we 'exit unless -f $$ARGV[0];' \\
3090 -e 'print "WARNING: I have found an old package in\n";' \\
3091 -e 'print "\t$$ARGV[0].\n";' \\
3092 -e 'print "Please make sure the two installations are not conflicting\n";'
3093
3094 UNINST=0
3095 VERBINST=1
3096
3097 MOD_INSTALL = $(PERL) -I$(INST_LIB) -I$(PERL_LIB) -MExtUtils::Install \
3098 -e "install({@ARGV},'$(VERBINST)',0,'$(UNINST)');"
3099
3100 DOC_INSTALL = $(PERL) -e '$$\="\n\n";' \
3101 -e 'print "=head2 ", scalar(localtime), ": C<", shift, ">", " L<", shift, ">";' \
3102 -e 'print "=over 4";' \
3103 -e 'while (defined($$key = shift) and defined($$val = shift)){print "=item *";print "C<$$key: $$val>";}' \
3104 -e 'print "=back";'
3105
3106 UNINSTALL =   $(PERL) -MExtUtils::Install \
3107 -e 'uninstall($$ARGV[0],1,1); print "\nUninstall is deprecated. Please check the";' \
3108 -e 'print " packlist above carefully.\n  There may be errors. Remove the";' \
3109 -e 'print " appropriate files manually.\n  Sorry for the inconveniences.\n"'
3110 };
3111
3112     return join "", @m;
3113 }
3114
3115 =item tool_xsubpp (o)
3116
3117 Determines typemaps, xsubpp version, prototype behaviour.
3118
3119 =cut
3120
3121 sub tool_xsubpp {
3122     my($self) = shift;
3123     return "" unless $self->needs_linking;
3124     my($xsdir)  = $self->catdir($self->{PERL_LIB},"ExtUtils");
3125     my(@tmdeps) = $self->catdir('$(XSUBPPDIR)','typemap');
3126     if( $self->{TYPEMAPS} ){
3127         my $typemap;
3128         foreach $typemap (@{$self->{TYPEMAPS}}){
3129                 if( ! -f  $typemap ){
3130                         warn "Typemap $typemap not found.\n";
3131                 }
3132                 else{
3133                         push(@tmdeps,  $typemap);
3134                 }
3135         }
3136     }
3137     push(@tmdeps, "typemap") if -f "typemap";
3138     my(@tmargs) = map("-typemap $_", @tmdeps);
3139     if( exists $self->{XSOPT} ){
3140         unshift( @tmargs, $self->{XSOPT} );
3141     }
3142
3143
3144     my $xsubpp_version = $self->xsubpp_version($self->catfile($xsdir,"xsubpp"));
3145
3146     # What are the correct thresholds for version 1 && 2 Paul?
3147     if ( $xsubpp_version > 1.923 ){
3148         $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
3149     } else {
3150         if (defined $self->{XSPROTOARG} && $self->{XSPROTOARG} =~ /\-prototypes/) {
3151             print STDOUT qq{Warning: This extension wants to pass the switch "-prototypes" to xsubpp.
3152         Your version of xsubpp is $xsubpp_version and cannot handle this.
3153         Please upgrade to a more recent version of xsubpp.
3154 };
3155         } else {
3156             $self->{XSPROTOARG} = "";
3157         }
3158     }
3159
3160     return qq{
3161 XSUBPPDIR = $xsdir
3162 XSUBPP = \$(XSUBPPDIR)/xsubpp
3163 XSPROTOARG = $self->{XSPROTOARG}
3164 XSUBPPDEPS = @tmdeps
3165 XSUBPPARGS = @tmargs
3166 };
3167 };
3168
3169 sub xsubpp_version
3170 {
3171     my($self,$xsubpp) = @_;
3172     return $Xsubpp_Version if defined $Xsubpp_Version; # global variable
3173
3174     my ($version) ;
3175
3176     # try to figure out the version number of the xsubpp on the system
3177
3178     # first try the -v flag, introduced in 1.921 & 2.000a2
3179
3180     return "" unless $self->needs_linking;
3181
3182     my $command = "$self->{PERL} -I$self->{PERL_LIB} $xsubpp -v 2>&1";
3183     print "Running $command\n" if $Verbose >= 2;
3184     $version = `$command` ;
3185     warn "Running '$command' exits with status " . ($?>>8) if $?;
3186     chop $version ;
3187
3188     return $Xsubpp_Version = $1 if $version =~ /^xsubpp version (.*)/ ;
3189
3190     # nope, then try something else
3191
3192     my $counter = '000';
3193     my ($file) = 'temp' ;
3194     $counter++ while -e "$file$counter"; # don't overwrite anything
3195     $file .= $counter;
3196
3197     open(F, ">$file") or die "Cannot open file '$file': $!\n" ;
3198     print F <<EOM ;
3199 MODULE = fred PACKAGE = fred
3200
3201 int
3202 fred(a)
3203         int     a;
3204 EOM
3205
3206     close F ;
3207
3208     $command = "$self->{PERL} $xsubpp $file 2>&1";
3209     print "Running $command\n" if $Verbose >= 2;
3210     my $text = `$command` ;
3211     warn "Running '$command' exits with status " . ($?>>8) if $?;
3212     unlink $file ;
3213
3214     # gets 1.2 -> 1.92 and 2.000a1
3215     return $Xsubpp_Version = $1 if $text =~ /automatically by xsubpp version ([\S]+)\s*/  ;
3216
3217     # it is either 1.0 or 1.1
3218     return $Xsubpp_Version = 1.1 if $text =~ /^Warning: ignored semicolon/ ;
3219
3220     # none of the above, so 1.0
3221     return $Xsubpp_Version = "1.0" ;
3222 }
3223
3224 =item top_targets (o)
3225
3226 Defines the targets all, subdirs, config, and O_FILES
3227
3228 =cut
3229
3230 sub top_targets {
3231 # --- Target Sections ---
3232
3233     my($self) = shift;
3234     my(@m);
3235     push @m, '
3236 #all :: config $(INST_PM) subdirs linkext manifypods
3237 ';
3238
3239     push @m, '
3240 all :: pure_all manifypods
3241         '.$self->{NOECHO}.'$(NOOP)
3242
3243           unless $self->{SKIPHASH}{'all'};
3244     
3245     push @m, '
3246 pure_all :: config pm_to_blib subdirs linkext
3247         '.$self->{NOECHO}.'$(NOOP)
3248
3249 subdirs :: $(MYEXTLIB)
3250         '.$self->{NOECHO}.'$(NOOP)
3251
3252 config :: '.$self->{MAKEFILE}.' $(INST_LIBDIR)/.exists
3253         '.$self->{NOECHO}.'$(NOOP)
3254
3255 config :: $(INST_ARCHAUTODIR)/.exists
3256         '.$self->{NOECHO}.'$(NOOP)
3257
3258 config :: $(INST_AUTODIR)/.exists
3259         '.$self->{NOECHO}.'$(NOOP)
3260 ';
3261
3262     push @m, qq{
3263 config :: Version_check
3264         $self->{NOECHO}\$(NOOP)
3265
3266 } unless $self->{PARENT} or ($self->{PERL_SRC} && $self->{INSTALLDIRS} eq "perl") or $self->{NO_VC};
3267
3268     push @m, $self->dir_target(qw[$(INST_AUTODIR) $(INST_LIBDIR) $(INST_ARCHAUTODIR)]);
3269
3270     if (%{$self->{MAN1PODS}}) {
3271         push @m, qq[
3272 config :: \$(INST_MAN1DIR)/.exists
3273         $self->{NOECHO}\$(NOOP)
3274
3275 ];
3276         push @m, $self->dir_target(qw[$(INST_MAN1DIR)]);
3277     }
3278     if (%{$self->{MAN3PODS}}) {
3279         push @m, qq[
3280 config :: \$(INST_MAN3DIR)/.exists
3281         $self->{NOECHO}\$(NOOP)
3282
3283 ];
3284         push @m, $self->dir_target(qw[$(INST_MAN3DIR)]);
3285     }
3286
3287     push @m, '
3288 $(O_FILES): $(H_FILES)
3289 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
3290
3291     push @m, q{
3292 help:
3293         perldoc ExtUtils::MakeMaker
3294 };
3295
3296     push @m, q{
3297 Version_check:
3298         }.$self->{NOECHO}.q{$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
3299                 -MExtUtils::MakeMaker=Version_check \
3300                 -e "Version_check('$(MM_VERSION)')"
3301 };
3302
3303     join('',@m);
3304 }
3305
3306 =item writedoc
3307
3308 Obsolete, depecated method. Not used since Version 5.21.
3309
3310 =cut
3311
3312 sub writedoc {
3313 # --- perllocal.pod section ---
3314     my($self,$what,$name,@attribs)=@_;
3315     my $time = localtime;
3316     print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
3317     print join "\n\n=item *\n\n", map("C<$_>",@attribs);
3318     print "\n\n=back\n\n";
3319 }
3320
3321 =item xs_c (o)
3322
3323 Defines the suffix rules to compile XS files to C.
3324
3325 =cut
3326
3327 sub xs_c {
3328     my($self) = shift;
3329     return '' unless $self->needs_linking();
3330     '
3331 .xs.c:
3332         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >$*.tc && $(MV) $*.tc $@
3333 ';
3334 }
3335
3336 =item xs_o (o)
3337
3338 Defines suffix rules to go from XS to object files directly. This is
3339 only intended for broken make implementations.
3340
3341 =cut
3342
3343 sub xs_o {      # many makes are too dumb to use xs_c then c_o
3344     my($self) = shift;
3345     return '' unless $self->needs_linking();
3346     '
3347 .xs$(OBJ_EXT):
3348         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >xstmp.c && $(MV) xstmp.c $*.c
3349         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
3350 ';
3351 }
3352
3353 =item perl_archive
3354
3355 This is internal method that returns path to libperl.a equivalent
3356 to be linked to dynamic extensions. UNIX does not have one but OS2
3357 and Win32 do.
3358
3359 =cut 
3360
3361 sub perl_archive
3362 {
3363  return "";
3364 }
3365
3366 =item export_list
3367
3368 This is internal method that returns name of a file that is
3369 passed to linker to define symbols to be exported.
3370 UNIX does not have one but OS2 and Win32 do.
3371
3372 =cut 
3373
3374 sub export_list
3375 {
3376  return "";
3377 }
3378
3379
3380 1;
3381
3382 =back
3383
3384 =head1 SEE ALSO
3385
3386 L<ExtUtils::MakeMaker>
3387
3388 =cut
3389
3390 __END__