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