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