Fix unnecessary re-linking
[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';                      # 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 ';
1117 }
1118
1119 =item guess_name
1120
1121 Guess the name of this package by examining the working directory's
1122 name. MakeMaker calls this only if the developer has not supplied a
1123 NAME attribute.
1124
1125 =cut
1126
1127 # ';
1128
1129 sub guess_name {
1130     my($self) = @_;
1131     use Cwd 'cwd';
1132     my $name = basename(cwd());
1133     $name =~ s|[\-_][\d\.\-]+$||;   # this is new with MM 5.00, we
1134                                     # strip minus or underline
1135                                     # followed by a float or some such
1136     print "Warning: Guessing NAME [$name] from current directory name.\n";
1137     $name;
1138 }
1139
1140 =item has_link_code
1141
1142 Returns true if C, XS, MYEXTLIB or similar objects exist within this
1143 object that need a compiler. Does not descend into subdirectories as
1144 needs_linking() does.
1145
1146 =cut
1147
1148 sub has_link_code {
1149     my($self) = shift;
1150     return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE};
1151     if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){
1152         $self->{HAS_LINK_CODE} = 1;
1153         return 1;
1154     }
1155     return $self->{HAS_LINK_CODE} = 0;
1156 }
1157
1158 =item init_dirscan
1159
1160 Initializes DIR, XS, PM, C, O_FILES, H, PL_FILES, MAN*PODS, EXE_FILES.
1161
1162 =cut
1163
1164 sub init_dirscan {      # --- File and Directory Lists (.xs .pm .pod etc)
1165     my($self) = @_;
1166     my($name, %dir, %xs, %c, %h, %ignore, %pl_files, %manifypods);
1167     local(%pm); #the sub in find() has to see this hash
1168     $ignore{'test.pl'} = 1;
1169     $ignore{'makefile.pl'} = 1 if $Is_VMS;
1170     foreach $name ($self->lsdir($self->curdir)){
1171         next if $name =~ /\#/;
1172         next if $name eq $self->curdir or $name eq $self->updir or $ignore{$name};
1173         next unless $self->libscan($name);
1174         if (-d $name){
1175             next if -l $name; # We do not support symlinks at all
1176             $dir{$name} = $name if (-f $self->catfile($name,"Makefile.PL"));
1177         } elsif ($name =~ /\.xs$/){
1178             my($c); ($c = $name) =~ s/\.xs$/.c/;
1179             $xs{$name} = $c;
1180             $c{$c} = 1;
1181         } elsif ($name =~ /\.c(pp|xx|c)?$/i){  # .c .C .cpp .cxx .cc
1182             $c{$name} = 1
1183                 unless $name =~ m/perlmain\.c/; # See MAP_TARGET
1184         } elsif ($name =~ /\.h$/i){
1185             $h{$name} = 1;
1186         } elsif ($name =~ /\.(p[ml]|pod)$/){
1187             $pm{$name} = $self->catfile('$(INST_LIBDIR)',$name);
1188         } elsif ($name =~ /\.PL$/ && $name ne "Makefile.PL") {
1189             ($pl_files{$name} = $name) =~ s/\.PL$// ;
1190         } elsif ($Is_VMS && $name =~ /\.pl$/ && $name ne 'makefile.pl' &&
1191                  $name ne 'test.pl') {  # case-insensitive filesystem
1192             ($pl_files{$name} = $name) =~ s/\.pl$// ;
1193         }
1194     }
1195
1196     # Some larger extensions often wish to install a number of *.pm/pl
1197     # files into the library in various locations.
1198
1199     # The attribute PMLIBDIRS holds an array reference which lists
1200     # subdirectories which we should search for library files to
1201     # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ].  We
1202     # recursively search through the named directories (skipping any
1203     # which don't exist or contain Makefile.PL files).
1204
1205     # For each *.pm or *.pl file found $self->libscan() is called with
1206     # the default installation path in $_[1]. The return value of
1207     # libscan defines the actual installation location.  The default
1208     # libscan function simply returns the path.  The file is skipped
1209     # if libscan returns false.
1210
1211     # The default installation location passed to libscan in $_[1] is:
1212     #
1213     #  ./*.pm           => $(INST_LIBDIR)/*.pm
1214     #  ./xyz/...        => $(INST_LIBDIR)/xyz/...
1215     #  ./lib/...        => $(INST_LIB)/...
1216     #
1217     # In this way the 'lib' directory is seen as the root of the actual
1218     # perl library whereas the others are relative to INST_LIBDIR
1219     # (which includes PARENT_NAME). This is a subtle distinction but one
1220     # that's important for nested modules.
1221
1222     $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}]
1223         unless $self->{PMLIBDIRS};
1224
1225     #only existing directories that aren't in $dir are allowed
1226
1227     # Avoid $_ wherever possible:
1228     # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
1229     my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
1230     my ($pmlibdir);
1231     @{$self->{PMLIBDIRS}} = ();
1232     foreach $pmlibdir (@pmlibdirs) {
1233         -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
1234     }
1235
1236     if (@{$self->{PMLIBDIRS}}){
1237         print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
1238             if ($Verbose >= 2);
1239         require File::Find;
1240         File::Find::find(sub {
1241             if (-d $_){
1242                 if ($_ eq "CVS" || $_ eq "RCS"){
1243                     $File::Find::prune = 1;
1244                 }
1245                 return;
1246             }
1247             return if /\#/;
1248             my($path, $prefix) = ($File::Find::name, '$(INST_LIBDIR)');
1249             my($striplibpath,$striplibname);
1250             $prefix =  '$(INST_LIB)' if (($striplibpath = $path) =~ s:^(\W*)lib\W:$1:i);
1251             ($striplibname,$striplibpath) = fileparse($striplibpath);
1252             my($inst) = $self->catfile($prefix,$striplibpath,$striplibname);
1253             local($_) = $inst; # for backwards compatibility
1254             $inst = $self->libscan($inst);
1255             print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
1256             return unless $inst;
1257             $pm{$path} = $inst;
1258         }, @{$self->{PMLIBDIRS}});
1259     }
1260
1261     $self->{DIR} = [sort keys %dir] unless $self->{DIR};
1262     $self->{XS}  = \%xs             unless $self->{XS};
1263     $self->{PM}  = \%pm             unless $self->{PM};
1264     $self->{C}   = [sort keys %c]   unless $self->{C};
1265     my(@o_files) = @{$self->{C}};
1266     $self->{O_FILES} = [grep s/\.c(pp|xx|c)?$/$self->{OBJ_EXT}/i, @o_files] ;
1267     $self->{H}   = [sort keys %h]   unless $self->{H};
1268     $self->{PL_FILES} = \%pl_files unless $self->{PL_FILES};
1269
1270     # Set up names of manual pages to generate from pods
1271     if ($self->{MAN1PODS}) {
1272     } elsif ( $self->{INST_MAN1DIR} =~ /^(none|\s*)$/ ) {
1273         $self->{MAN1PODS} = {};
1274     } else {
1275         my %manifypods = ();
1276         if ( exists $self->{EXE_FILES} ) {
1277             foreach $name (@{$self->{EXE_FILES}}) {
1278 #               use FileHandle ();
1279 #               my $fh = new FileHandle;
1280                 local *FH;
1281                 my($ispod)=0;
1282                 # one day test, if $/ can be set to '' safely (is the bug fixed that was in 5.001m?)
1283 #               if ($fh->open("<$name")) {
1284                 if (open(FH,"<$name")) {
1285 #                   while (<$fh>) {
1286                     while (<FH>) {
1287                         if (/^=head1\s+\w+/) {
1288                             $ispod=1;
1289                             last;
1290                         }
1291                     }
1292 #                   $fh->close;
1293                     close FH;
1294                 } else {
1295                     # If it doesn't exist yet, we assume, it has pods in it
1296                     $ispod = 1;
1297                 }
1298                 if( $ispod ) {
1299                     $manifypods{$name} = $self->catfile('$(INST_MAN1DIR)',basename($name).'.$(MAN1EXT)');
1300                 }
1301             }
1302         }
1303         $self->{MAN1PODS} = \%manifypods;
1304     }
1305     if ($self->{MAN3PODS}) {
1306     } elsif ( $self->{INST_MAN3DIR} =~ /^(none|\s*)$/ ) {
1307         $self->{MAN3PODS} = {};
1308     } else {
1309         my %manifypods = (); # we collect the keys first, i.e. the files
1310                              # we have to convert to pod
1311         foreach $name (keys %{$self->{PM}}) {
1312             if ($name =~ /\.pod$/ ) {
1313                 $manifypods{$name} = $self->{PM}{$name};
1314             } elsif ($name =~ /\.p[ml]$/ ) {
1315 #               use FileHandle ();
1316 #               my $fh = new FileHandle;
1317                 local *FH;
1318                 my($ispod)=0;
1319 #               $fh->open("<$name");
1320                 if (open(FH,"<$name")) {
1321                     #           while (<$fh>) {
1322                     while (<FH>) {
1323                         if (/^=head1\s+\w+/) {
1324                             $ispod=1;
1325                             last;
1326                         }
1327                     }
1328                     #           $fh->close;
1329                     close FH;
1330                 } else {
1331                     $ispod = 1;
1332                 }
1333                 if( $ispod ) {
1334                     $manifypods{$name} = $self->{PM}{$name};
1335                 }
1336             }
1337         }
1338
1339         # Remove "Configure.pm" and similar, if it's not the only pod listed
1340         # To force inclusion, just name it "Configure.pod", or override MAN3PODS
1341         foreach $name (keys %manifypods) {
1342             if ($name =~ /(config|setup).*\.pm/i) {
1343                 delete $manifypods{$name};
1344                 next;
1345             }
1346             my($manpagename) = $name;
1347             unless ($manpagename =~ s!^\W*lib\W+!!) { # everything below lib is ok
1348                 $manpagename = $self->catfile(split(/::/,$self->{PARENT_NAME}),$manpagename);
1349             }
1350             $manpagename =~ s/\.p(od|m|l)$//;
1351             $manpagename = $self->replace_manpage_separator($manpagename);
1352             $manifypods{$name} = $self->catfile("\$(INST_MAN3DIR)","$manpagename.\$(MAN3EXT)");
1353         }
1354         $self->{MAN3PODS} = \%manifypods;
1355     }
1356 }
1357
1358 =item init_main
1359
1360 Initializes NAME, FULLEXT, BASEEXT, PARENT_NAME, DLBASE, PERL_SRC,
1361 PERL_LIB, PERL_ARCHLIB, PERL_INC, INSTALLDIRS, INST_*, INSTALL*,
1362 PREFIX, CONFIG, AR, AR_STATIC_ARGS, LD, OBJ_EXT, LIB_EXT, EXE_EXT, MAP_TARGET,
1363 LIBPERL_A, VERSION_FROM, VERSION, DISTNAME, VERSION_SYM.
1364
1365 =cut
1366
1367 sub init_main {
1368     my($self) = @_;
1369
1370     # --- Initialize Module Name and Paths
1371
1372     # NAME    = Foo::Bar::Oracle
1373     # FULLEXT = Foo/Bar/Oracle
1374     # BASEEXT = Oracle
1375     # ROOTEXT = Directory part of FULLEXT with leading /. !!! Deprecated from MM 5.32 !!!
1376     # PARENT_NAME = Foo::Bar
1377 ### Only UNIX:
1378 ###    ($self->{FULLEXT} =
1379 ###     $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket
1380     $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME});
1381
1382
1383     # Copied from DynaLoader:
1384
1385     my(@modparts) = split(/::/,$self->{NAME});
1386     my($modfname) = $modparts[-1];
1387
1388     # Some systems have restrictions on files names for DLL's etc.
1389     # mod2fname returns appropriate file base name (typically truncated)
1390     # It may also edit @modparts if required.
1391     if (defined &DynaLoader::mod2fname) {
1392         $modfname = &DynaLoader::mod2fname(\@modparts);
1393     }
1394
1395     ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!([\w:]+::)?(\w+)$! ;
1396
1397     if (defined &DynaLoader::mod2fname) {
1398         # As of 5.001m, dl_os2 appends '_'
1399         $self->{DLBASE} = $modfname;
1400     } else {
1401         $self->{DLBASE} = '$(BASEEXT)';
1402     }
1403
1404
1405     ### ROOTEXT deprecated from MM 5.32
1406 ###    ($self->{ROOTEXT} =
1407 ###     $self->{FULLEXT}) =~ s#/?\Q$self->{BASEEXT}\E$## ;      #eg. /BSD/Foo
1408 ###    $self->{ROOTEXT} = ($Is_VMS ? '' : '/') . $self->{ROOTEXT} if $self->{ROOTEXT};
1409
1410
1411     # --- Initialize PERL_LIB, INST_LIB, PERL_SRC
1412
1413     # *Real* information: where did we get these two from? ...
1414     my $inc_config_dir = dirname($INC{'Config.pm'});
1415     my $inc_carp_dir   = dirname($INC{'Carp.pm'});
1416
1417     unless ($self->{PERL_SRC}){
1418         my($dir);
1419         foreach $dir ($self->updir(),$self->catdir($self->updir(),$self->updir()),$self->catdir($self->updir(),$self->updir(),$self->updir())){
1420             if (
1421                 -f $self->catfile($dir,"config.sh")
1422                 &&
1423                 -f $self->catfile($dir,"perl.h")
1424                 &&
1425                 -f $self->catfile($dir,"lib","Exporter.pm")
1426                ) {
1427                 $self->{PERL_SRC}=$dir ;
1428                 last;
1429             }
1430         }
1431     }
1432     if ($self->{PERL_SRC}){
1433         $self->{PERL_LIB}     ||= $self->catdir("$self->{PERL_SRC}","lib");
1434         $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
1435         $self->{PERL_INC}     = ($Is_Win32) ? $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
1436
1437         # catch a situation that has occurred a few times in the past:
1438         unless (
1439                 -s $self->catfile($self->{PERL_SRC},'cflags')
1440                 or
1441                 $Is_VMS
1442                 &&
1443                 -s $self->catfile($self->{PERL_SRC},'perlshr_attr.opt')
1444                 or
1445                 $Is_Mac
1446                 or
1447                 $Is_Win32
1448                ){
1449             warn qq{
1450 You cannot build extensions below the perl source tree after executing
1451 a 'make clean' in the perl source tree.
1452
1453 To rebuild extensions distributed with the perl source you should
1454 simply Configure (to include those extensions) and then build perl as
1455 normal. After installing perl the source tree can be deleted. It is
1456 not needed for building extensions by running 'perl Makefile.PL'
1457 usually without extra arguments.
1458
1459 It is recommended that you unpack and build additional extensions away
1460 from the perl source tree.
1461 };
1462         }
1463     } else {
1464         # we should also consider $ENV{PERL5LIB} here
1465         $self->{PERL_LIB}     ||= $Config::Config{privlibexp};
1466         $self->{PERL_ARCHLIB} ||= $Config::Config{archlibexp};
1467         $self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
1468         my $perl_h;
1469         unless (-f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))){
1470             die qq{
1471 Error: Unable to locate installed Perl libraries or Perl source code.
1472
1473 It is recommended that you install perl in a standard location before
1474 building extensions. Some precompiled versions of perl do not contain
1475 these header files, so you cannot build extensions. In such a case,
1476 please build and install your perl from a fresh perl distribution. It
1477 usually solves this kind of problem.
1478
1479 \(You get this message, because MakeMaker could not find "$perl_h"\)
1480 };
1481         }
1482 #        print STDOUT "Using header files found in $self->{PERL_INC}\n"
1483 #            if $Verbose && $self->needs_linking();
1484
1485     }
1486
1487     # We get SITELIBEXP and SITEARCHEXP directly via
1488     # Get_from_Config. When we are running standard modules, these
1489     # won't matter, we will set INSTALLDIRS to "perl". Otherwise we
1490     # set it to "site". I prefer that INSTALLDIRS be set from outside
1491     # MakeMaker.
1492     $self->{INSTALLDIRS} ||= "site";
1493
1494     # INST_LIB typically pre-set if building an extension after
1495     # perl has been built and installed. Setting INST_LIB allows
1496     # you to build directly into, say $Config::Config{privlibexp}.
1497     unless ($self->{INST_LIB}){
1498
1499
1500         ##### XXXXX We have to change this nonsense
1501
1502         if (defined $self->{PERL_SRC} and $self->{INSTALLDIRS} eq "perl") {
1503             $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
1504         } else {
1505             $self->{INST_LIB} = $self->catdir($self->curdir,"blib","lib");
1506         }
1507     }
1508     $self->{INST_ARCHLIB} ||= $self->catdir($self->curdir,"blib","arch");
1509     $self->{INST_BIN} ||= $self->catdir($self->curdir,'blib','bin');
1510
1511     # We need to set up INST_LIBDIR before init_libscan() for VMS
1512     my @parentdir = split(/::/, $self->{PARENT_NAME});
1513     $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)',@parentdir);
1514     $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)',@parentdir);
1515     $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)','auto','$(FULLEXT)');
1516     $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)','auto','$(FULLEXT)');
1517
1518     # INST_EXE is deprecated, should go away March '97
1519     $self->{INST_EXE} ||= $self->catdir($self->curdir,'blib','script');
1520     $self->{INST_SCRIPT} ||= $self->catdir($self->curdir,'blib','script');
1521
1522     # The user who requests an installation directory explicitly
1523     # should not have to tell us a architecture installation directory
1524     # as well. We look if a directory exists that is named after the
1525     # architecture. If not we take it as a sign that it should be the
1526     # same as the requested installation directory. Otherwise we take
1527     # the found one.
1528     # We do the same thing twice: for privlib/archlib and for sitelib/sitearch
1529     my($libpair);
1530     for $libpair ({l=>"privlib", a=>"archlib"}, {l=>"sitelib", a=>"sitearch"}) {
1531         my $lib = "install$libpair->{l}";
1532         my $Lib = uc $lib;
1533         my $Arch = uc "install$libpair->{a}";
1534         if( $self->{$Lib} && ! $self->{$Arch} ){
1535             my($ilib) = $Config{$lib};
1536             $ilib = VMS::Filespec::unixify($ilib) if $Is_VMS;
1537
1538             $self->prefixify($Arch,$ilib,$self->{$Lib});
1539
1540             unless (-d $self->{$Arch}) {
1541                 print STDOUT "Directory $self->{$Arch} not found, thusly\n" if $Verbose;
1542                 $self->{$Arch} = $self->{$Lib};
1543             }
1544             print STDOUT "Defaulting $Arch to $self->{$Arch}\n" if $Verbose;
1545         }
1546     }
1547
1548     # we have to look at the relation between $Config{prefix} and the
1549     # requested values. We're going to set the $Config{prefix} part of
1550     # all the installation path variables to literally $(PREFIX), so
1551     # the user can still say make PREFIX=foo
1552     my($configure_prefix) = $Config{'prefix'};
1553     $configure_prefix = VMS::Filespec::unixify($configure_prefix) if $Is_VMS;
1554     $self->{PREFIX} ||= $configure_prefix;
1555
1556
1557     my($install_variable,$search_prefix,$replace_prefix);
1558
1559     # The rule, taken from Configure, is that if prefix contains perl,
1560     # we shape the tree
1561     #    perlprefix/lib/                INSTALLPRIVLIB
1562     #    perlprefix/lib/pod/
1563     #    perlprefix/lib/site_perl/      INSTALLSITELIB
1564     #    perlprefix/bin/                INSTALLBIN
1565     #    perlprefix/man/                INSTALLMAN1DIR
1566     # else
1567     #    prefix/lib/perl5/              INSTALLPRIVLIB
1568     #    prefix/lib/perl5/pod/
1569     #    prefix/lib/perl5/site_perl/    INSTALLSITELIB
1570     #    prefix/bin/                    INSTALLBIN
1571     #    prefix/lib/perl5/man/          INSTALLMAN1DIR
1572
1573     $replace_prefix = qq[\$\(PREFIX\)];
1574     for $install_variable (qw/
1575                            INSTALLBIN
1576                            INSTALLSCRIPT
1577                            /) {
1578         $self->prefixify($install_variable,$configure_prefix,$replace_prefix);
1579     }
1580     $search_prefix = $configure_prefix =~ /perl/ ?
1581         $self->catdir($configure_prefix,"lib") :
1582         $self->catdir($configure_prefix,"lib","perl5");
1583     if ($self->{LIB}) {
1584         $self->{INSTALLPRIVLIB} = $self->{INSTALLSITELIB} = $self->{LIB};
1585         $self->{INSTALLARCHLIB} = $self->{INSTALLSITEARCH} = 
1586             $self->catdir($self->{LIB},$Config{'archname'});
1587     } else {
1588         $replace_prefix = $self->{PREFIX} =~ /perl/ ? 
1589             $self->catdir(qq[\$\(PREFIX\)],"lib") :
1590                 $self->catdir(qq[\$\(PREFIX\)],"lib","perl5");
1591         for $install_variable (qw/
1592                                INSTALLPRIVLIB
1593                                INSTALLARCHLIB
1594                                INSTALLSITELIB
1595                                INSTALLSITEARCH
1596                                /) {
1597             $self->prefixify($install_variable,$search_prefix,$replace_prefix);
1598         }
1599     }
1600     $search_prefix = $configure_prefix =~ /perl/ ?
1601         $self->catdir($configure_prefix,"man") :
1602             $self->catdir($configure_prefix,"lib","perl5","man");
1603     $replace_prefix = $self->{PREFIX} =~ /perl/ ? 
1604         $self->catdir(qq[\$\(PREFIX\)],"man") :
1605             $self->catdir(qq[\$\(PREFIX\)],"lib","perl5","man");
1606     for $install_variable (qw/
1607                            INSTALLMAN1DIR
1608                            INSTALLMAN3DIR
1609                            /) {
1610         $self->prefixify($install_variable,$search_prefix,$replace_prefix);
1611     }
1612
1613     # Now we head at the manpages. Maybe they DO NOT want manpages
1614     # installed
1615     $self->{INSTALLMAN1DIR} = $Config::Config{installman1dir}
1616         unless defined $self->{INSTALLMAN1DIR};
1617     unless (defined $self->{INST_MAN1DIR}){
1618         if ($self->{INSTALLMAN1DIR} =~ /^(none|\s*)$/){
1619             $self->{INST_MAN1DIR} = $self->{INSTALLMAN1DIR};
1620         } else {
1621             $self->{INST_MAN1DIR} = $self->catdir($self->curdir,'blib','man1');
1622         }
1623     }
1624     $self->{MAN1EXT} ||= $Config::Config{man1ext};
1625
1626     $self->{INSTALLMAN3DIR} = $Config::Config{installman3dir}
1627         unless defined $self->{INSTALLMAN3DIR};
1628     unless (defined $self->{INST_MAN3DIR}){
1629         if ($self->{INSTALLMAN3DIR} =~ /^(none|\s*)$/){
1630             $self->{INST_MAN3DIR} = $self->{INSTALLMAN3DIR};
1631         } else {
1632             $self->{INST_MAN3DIR} = $self->catdir($self->curdir,'blib','man3');
1633         }
1634     }
1635     $self->{MAN3EXT} ||= $Config::Config{man3ext};
1636
1637
1638     # Get some stuff out of %Config if we haven't yet done so
1639     print STDOUT "CONFIG must be an array ref\n"
1640         if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
1641     $self->{CONFIG} = [] unless (ref $self->{CONFIG});
1642     push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
1643     push(@{$self->{CONFIG}}, 'shellflags') if $Config::Config{shellflags};
1644     my(%once_only,$m);
1645     foreach $m (@{$self->{CONFIG}}){
1646         next if $once_only{$m};
1647         print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
1648                 unless exists $Config::Config{$m};
1649         $self->{uc $m} ||= $Config::Config{$m};
1650         $once_only{$m} = 1;
1651     }
1652
1653 # This is too dangerous:
1654 #    if ($^O eq "next") {
1655 #       $self->{AR} = "libtool";
1656 #       $self->{AR_STATIC_ARGS} = "-o";
1657 #    }
1658 # But I leave it as a placeholder
1659
1660     $self->{AR_STATIC_ARGS} ||= "cr";
1661
1662     # These should never be needed
1663     $self->{LD} ||= 'ld';
1664     $self->{OBJ_EXT} ||= '.o';
1665     $self->{LIB_EXT} ||= '.a';
1666
1667     $self->{MAP_TARGET} ||= "perl";
1668
1669     $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
1670
1671     # make a simple check if we find Exporter
1672     warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
1673         (Exporter.pm not found)"
1674         unless -f $self->catfile("$self->{PERL_LIB}","Exporter.pm") ||
1675         $self->{NAME} eq "ExtUtils::MakeMaker";
1676
1677     # Determine VERSION and VERSION_FROM
1678     ($self->{DISTNAME}=$self->{NAME}) =~ s#(::)#-#g unless $self->{DISTNAME};
1679     if ($self->{VERSION_FROM}){
1680         $self->{VERSION} = $self->parse_version($self->{VERSION_FROM}) or
1681             Carp::carp "WARNING: Setting VERSION via file '$self->{VERSION_FROM}' failed\n"
1682     }
1683
1684     # strip blanks
1685     if ($self->{VERSION}) {
1686         $self->{VERSION} =~ s/^\s+//;
1687         $self->{VERSION} =~ s/\s+$//;
1688     }
1689
1690     $self->{VERSION} ||= "0.10";
1691     ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
1692
1693
1694     # Graham Barr and Paul Marquess had some ideas how to ensure
1695     # version compatibility between the *.pm file and the
1696     # corresponding *.xs file. The bottomline was, that we need an
1697     # XS_VERSION macro that defaults to VERSION:
1698     $self->{XS_VERSION} ||= $self->{VERSION};
1699
1700     # --- Initialize Perl Binary Locations
1701
1702     # Find Perl 5. The only contract here is that both 'PERL' and 'FULLPERL'
1703     # will be working versions of perl 5. miniperl has priority over perl
1704     # for PERL to ensure that $(PERL) is usable while building ./ext/*
1705     my ($component,@defpath);
1706     foreach $component ($self->{PERL_SRC}, $self->path(), $Config::Config{binexp}) {
1707         push @defpath, $component if defined $component;
1708     }
1709     $self->{PERL} ||=
1710         $self->find_perl(5.0, [ $^X, 'miniperl','perl','perl5',"perl$]" ],
1711             \@defpath, $Verbose );
1712     # don't check if perl is executable, maybe they have decided to
1713     # supply switches with perl
1714
1715     # Define 'FULLPERL' to be a non-miniperl (used in test: target)
1716     ($self->{FULLPERL} = $self->{PERL}) =~ s/miniperl/perl/i
1717         unless ($self->{FULLPERL});
1718 }
1719
1720 =item init_others
1721
1722 Initializes EXTRALIBS, BSLOADLIBS, LDLOADLIBS, LIBS, LD_RUN_PATH,
1723 OBJECT, BOOTDEP, PERLMAINCC, LDFROM, LINKTYPE, NOOP, FIRST_MAKEFILE,
1724 MAKEFILE, NOECHO, RM_F, RM_RF, TEST_F, TOUCH, CP, MV, CHMOD, UMASK_NULL
1725
1726 =cut
1727
1728 sub init_others {       # --- Initialize Other Attributes
1729     my($self) = shift;
1730
1731     # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
1732     # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
1733     # undefined. In any case we turn it into an anon array:
1734
1735     # May check $Config{libs} too, thus not empty.
1736     $self->{LIBS}=[''] unless $self->{LIBS};
1737
1738     $self->{LIBS}=[$self->{LIBS}] if ref \$self->{LIBS} eq 'SCALAR';
1739     $self->{LD_RUN_PATH} = "";
1740     my($libs);
1741     foreach $libs ( @{$self->{LIBS}} ){
1742         $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
1743         my(@libs) = $self->extliblist($libs);
1744         if ($libs[0] or $libs[1] or $libs[2]){
1745             # LD_RUN_PATH now computed by ExtUtils::Liblist
1746             ($self->{EXTRALIBS}, $self->{BSLOADLIBS}, $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
1747             last;
1748         }
1749     }
1750
1751     if ( $self->{OBJECT} ) {
1752         $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
1753     } else {
1754         # init_dirscan should have found out, if we have C files
1755         $self->{OBJECT} = "";
1756         $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
1757     }
1758     $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
1759     $self->{BOOTDEP}  = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
1760     $self->{PERLMAINCC} ||= '$(CC)';
1761     $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
1762
1763     # Sanity check: don't define LINKTYPE = dynamic if we're skipping
1764     # the 'dynamic' section of MM.  We don't have this problem with
1765     # 'static', since we either must use it (%Config says we can't
1766     # use dynamic loading) or the caller asked for it explicitly.
1767     if (!$self->{LINKTYPE}) {
1768        $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
1769                         ? 'static'
1770                         : ($Config::Config{usedl} ? 'dynamic' : 'static');
1771     };
1772
1773     # These get overridden for VMS and maybe some other systems
1774     $self->{NOOP}  ||= '$(SHELL) -c true';
1775     $self->{FIRST_MAKEFILE} ||= "Makefile";
1776     $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE};
1777     $self->{MAKE_APERL_FILE} ||= "Makefile.aperl";
1778     $self->{NOECHO} = '@' unless defined $self->{NOECHO};
1779     $self->{RM_F}  ||= "rm -f";
1780     $self->{RM_RF} ||= "rm -rf";
1781     $self->{TOUCH} ||= "touch";
1782     $self->{TEST_F} ||= "test -f";
1783     $self->{CP} ||= "cp";
1784     $self->{MV} ||= "mv";
1785     $self->{CHMOD} ||= "chmod";
1786     $self->{UMASK_NULL} ||= "umask 0";
1787     $self->{DEV_NULL} ||= "> /dev/null 2>&1";
1788 }
1789
1790 =item install (o)
1791
1792 Defines the install target.
1793
1794 =cut
1795
1796 sub install {
1797     my($self, %attribs) = @_;
1798     my(@m);
1799
1800     push @m, q{
1801 install :: all pure_install doc_install
1802
1803 install_perl :: all pure_perl_install doc_perl_install
1804
1805 install_site :: all pure_site_install doc_site_install
1806
1807 install_ :: install_site
1808         @echo INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
1809
1810 pure_install :: pure_$(INSTALLDIRS)_install
1811
1812 doc_install :: doc_$(INSTALLDIRS)_install
1813         }.$self->{NOECHO}.q{echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
1814
1815 pure__install : pure_site_install
1816         @echo INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
1817
1818 doc__install : doc_site_install
1819         @echo INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
1820
1821 pure_perl_install ::
1822         }.$self->{NOECHO}.q{$(MOD_INSTALL) \
1823                 read }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
1824                 write }.$self->catfile('$(INSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
1825                 $(INST_LIB) $(INSTALLPRIVLIB) \
1826                 $(INST_ARCHLIB) $(INSTALLARCHLIB) \
1827                 $(INST_BIN) $(INSTALLBIN) \
1828                 $(INST_SCRIPT) $(INSTALLSCRIPT) \
1829                 $(INST_MAN1DIR) $(INSTALLMAN1DIR) \
1830                 $(INST_MAN3DIR) $(INSTALLMAN3DIR)
1831         }.$self->{NOECHO}.q{$(WARN_IF_OLD_PACKLIST) \
1832                 }.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{
1833
1834
1835 pure_site_install ::
1836         }.$self->{NOECHO}.q{$(MOD_INSTALL) \
1837                 read }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
1838                 write }.$self->catfile('$(INSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{ \
1839                 $(INST_LIB) $(INSTALLSITELIB) \
1840                 $(INST_ARCHLIB) $(INSTALLSITEARCH) \
1841                 $(INST_BIN) $(INSTALLBIN) \
1842                 $(INST_SCRIPT) $(INSTALLSCRIPT) \
1843                 $(INST_MAN1DIR) $(INSTALLMAN1DIR) \
1844                 $(INST_MAN3DIR) $(INSTALLMAN3DIR)
1845         }.$self->{NOECHO}.q{$(WARN_IF_OLD_PACKLIST) \
1846                 }.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{
1847
1848 doc_perl_install ::
1849         }.$self->{NOECHO}.q{$(DOC_INSTALL) \
1850                 "Module" "$(NAME)" \
1851                 "installed into" "$(INSTALLPRIVLIB)" \
1852                 LINKTYPE "$(LINKTYPE)" \
1853                 VERSION "$(VERSION)" \
1854                 EXE_FILES "$(EXE_FILES)" \
1855                 >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
1856
1857 doc_site_install ::
1858         }.$self->{NOECHO}.q{$(DOC_INSTALL) \
1859                 "Module" "$(NAME)" \
1860                 "installed into" "$(INSTALLSITELIB)" \
1861                 LINKTYPE "$(LINKTYPE)" \
1862                 VERSION "$(VERSION)" \
1863                 EXE_FILES "$(EXE_FILES)" \
1864                 >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
1865
1866 };
1867
1868     push @m, q{
1869 uninstall :: uninstall_from_$(INSTALLDIRS)dirs
1870
1871 uninstall_from_perldirs ::
1872         }.$self->{NOECHO}.
1873         q{$(UNINSTALL) }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{
1874
1875 uninstall_from_sitedirs ::
1876         }.$self->{NOECHO}.
1877         q{$(UNINSTALL) }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{
1878 };
1879
1880     join("",@m);
1881 }
1882
1883 =item installbin (o)
1884
1885 Defines targets to install EXE_FILES.
1886
1887 =cut
1888
1889 sub installbin {
1890     my($self) = shift;
1891     return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
1892     return "" unless @{$self->{EXE_FILES}};
1893     my(@m, $from, $to, %fromto, @to);
1894     push @m, $self->dir_target(qw[$(INST_SCRIPT)]);
1895     for $from (@{$self->{EXE_FILES}}) {
1896         my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
1897         local($_) = $path; # for backwards compatibility
1898         $to = $self->libscan($path);
1899         print "libscan($from) => '$to'\n" if ($Verbose >=2);
1900         $fromto{$from}=$to;
1901     }
1902     @to   = values %fromto;
1903     push(@m, "
1904 EXE_FILES = @{$self->{EXE_FILES}}
1905
1906 all :: @to
1907
1908 realclean ::
1909         $self->{RM_F} @to
1910 ");
1911
1912     while (($from,$to) = each %fromto) {
1913         last unless defined $from;
1914         my $todir = dirname($to);
1915         push @m, "
1916 $to: $from $self->{MAKEFILE} $todir/.exists
1917         $self->{NOECHO}$self->{RM_F} $to
1918         $self->{CP} $from $to
1919 ";
1920     }
1921     join "", @m;
1922 }
1923
1924 =item libscan (o)
1925
1926 Takes a path to a file that is found by init_dirscan and returns false
1927 if we don't want to include this file in the library. Mainly used to
1928 exclude RCS, CVS, and SCCS directories from installation.
1929
1930 =cut
1931
1932 # ';
1933
1934 sub libscan {
1935     my($self,$path) = @_;
1936     return '' if $path =~ m:\b(RCS|CVS|SCCS)\b: ;
1937     $path;
1938 }
1939
1940 =item linkext (o)
1941
1942 Defines the linkext target which in turn defines the LINKTYPE.
1943
1944 =cut
1945
1946 sub linkext {
1947     my($self, %attribs) = @_;
1948     # LINKTYPE => static or dynamic or ''
1949     my($linktype) = defined $attribs{LINKTYPE} ?
1950       $attribs{LINKTYPE} : '$(LINKTYPE)';
1951     "
1952 linkext :: $linktype
1953         $self->{NOECHO}\$(NOOP)
1954 ";
1955 }
1956
1957 =item lsdir
1958
1959 Takes as arguments a directory name and a regular expression. Returns
1960 all entries in the directory that match the regular expression.
1961
1962 =cut
1963
1964 sub lsdir {
1965     my($self) = shift;
1966     my($dir, $regex) = @_;
1967     my(@ls);
1968     my $dh = new DirHandle;
1969     $dh->open($dir || ".") or return ();
1970     @ls = $dh->read;
1971     $dh->close;
1972     @ls = grep(/$regex/, @ls) if $regex;
1973     @ls;
1974 }
1975
1976 =item macro (o)
1977
1978 Simple subroutine to insert the macros defined by the macro attribute
1979 into the Makefile.
1980
1981 =cut
1982
1983 sub macro {
1984     my($self,%attribs) = @_;
1985     my(@m,$key,$val);
1986     while (($key,$val) = each %attribs){
1987         last unless defined $key;
1988         push @m, "$key = $val\n";
1989     }
1990     join "", @m;
1991 }
1992
1993 =item makeaperl (o)
1994
1995 Called by staticmake. Defines how to write the Makefile to produce a
1996 static new perl.
1997
1998 By default the Makefile produced includes all the static extensions in
1999 the perl library. (Purified versions of library files, e.g.,
2000 DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
2001
2002 =cut
2003
2004 sub makeaperl {
2005     my($self, %attribs) = @_;
2006     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
2007         @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
2008     my(@m);
2009     push @m, "
2010 # --- MakeMaker makeaperl section ---
2011 MAP_TARGET    = $target
2012 FULLPERL      = $self->{FULLPERL}
2013 ";
2014     return join '', @m if $self->{PARENT};
2015
2016     my($dir) = join ":", @{$self->{DIR}};
2017
2018     unless ($self->{MAKEAPERL}) {
2019         push @m, q{
2020 $(MAP_TARGET) :: static $(MAKE_APERL_FILE)
2021         $(MAKE) -f $(MAKE_APERL_FILE) $@
2022
2023 $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE)
2024         }.$self->{NOECHO}.q{echo Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
2025         }.$self->{NOECHO}.q{$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
2026                 Makefile.PL DIR=}, $dir, q{ \
2027                 MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
2028                 MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
2029
2030         foreach (@ARGV){
2031                 if( /\s/ ){
2032                         s/=(.*)/='$1'/;
2033                 }
2034                 push @m, " \\\n\t\t$_";
2035         }
2036 #       push @m, map( " \\\n\t\t$_", @ARGV );
2037         push @m, "\n";
2038
2039         return join '', @m;
2040     }
2041
2042
2043
2044     my($cccmd, $linkcmd, $lperl);
2045
2046
2047     $cccmd = $self->const_cccmd($libperl);
2048     $cccmd =~ s/^CCCMD\s*=\s*//;
2049     $cccmd =~ s/\$\(INC\)/ -I$self->{PERL_INC} /;
2050     $cccmd .= " $Config::Config{cccdlflags}"
2051         if ($Config::Config{useshrplib} eq 'true');
2052     $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
2053
2054     # The front matter of the linkcommand...
2055     $linkcmd = join ' ', "\$(CC)",
2056             grep($_, @Config{qw(large split ldflags ccdlflags)});
2057     $linkcmd =~ s/\s+/ /g;
2058     $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
2059
2060     # Which *.a files could we make use of...
2061     local(%static);
2062     require File::Find;
2063     File::Find::find(sub {
2064         return unless m/\Q$self->{LIB_EXT}\E$/;
2065         return if m/^libperl/;
2066         # Skip purified versions of libraries (e.g., DynaLoader_pure_p1_c0_032.a)
2067         return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
2068
2069         if( exists $self->{INCLUDE_EXT} ){
2070                 my $found = 0;
2071                 my $incl;
2072                 my $xx;
2073
2074                 ($xx = $File::Find::name) =~ s,.*?/auto/,,;
2075                 $xx =~ s,/?$_,,;
2076                 $xx =~ s,/,::,g;
2077
2078                 # Throw away anything not explicitly marked for inclusion.
2079                 # DynaLoader is implied.
2080                 foreach $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
2081                         if( $xx eq $incl ){
2082                                 $found++;
2083                                 last;
2084                         }
2085                 }
2086                 return unless $found;
2087         }
2088         elsif( exists $self->{EXCLUDE_EXT} ){
2089                 my $excl;
2090                 my $xx;
2091
2092                 ($xx = $File::Find::name) =~ s,.*?/auto/,,;
2093                 $xx =~ s,/?$_,,;
2094                 $xx =~ s,/,::,g;
2095
2096                 # Throw away anything explicitly marked for exclusion
2097                 foreach $excl (@{$self->{EXCLUDE_EXT}}){
2098                         return if( $xx eq $excl );
2099                 }
2100         }
2101
2102         # don't include the installed version of this extension. I
2103         # leave this line here, although it is not necessary anymore:
2104         # I patched minimod.PL instead, so that Miniperl.pm won't
2105         # enclude duplicates
2106
2107         # Once the patch to minimod.PL is in the distribution, I can
2108         # drop it
2109         return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}$:;
2110         use Cwd 'cwd';
2111         $static{cwd() . "/" . $_}++;
2112     }, grep( -d $_, @{$searchdirs || []}) );
2113
2114     # We trust that what has been handed in as argument, will be buildable
2115     $static = [] unless $static;
2116     @static{@{$static}} = (1) x @{$static};
2117
2118     $extra = [] unless $extra && ref $extra eq 'ARRAY';
2119     for (sort keys %static) {
2120         next unless /\Q$self->{LIB_EXT}\E$/;
2121         $_ = dirname($_) . "/extralibs.ld";
2122         push @$extra, $_;
2123     }
2124
2125     grep(s/^/-I/, @{$perlinc || []});
2126
2127     $target = "perl" unless $target;
2128     $tmp = "." unless $tmp;
2129
2130 # MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
2131 # regenerate the Makefiles, MAP_STATIC and the dependencies for
2132 # extralibs.all are computed correctly
2133     push @m, "
2134 MAP_LINKCMD   = $linkcmd
2135 MAP_PERLINC   = @{$perlinc || []}
2136 MAP_STATIC    = ",
2137 join(" \\\n\t", reverse sort keys %static), "
2138
2139 MAP_PRELIBS   = $Config::Config{libs} $Config::Config{cryptlib}
2140 ";
2141
2142     if (defined $libperl) {
2143         ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
2144     }
2145     unless ($libperl && -f $lperl) { # Ilya's code...
2146         my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
2147         $libperl ||= "libperl$self->{LIB_EXT}";
2148         $libperl   = "$dir/$libperl";
2149         $lperl   ||= "libperl$self->{LIB_EXT}";
2150         $lperl     = "$dir/$lperl";
2151
2152         if (! -f $libperl and ! -f $lperl) {
2153           # We did not find a static libperl. Maybe there is a shared one?
2154           if ($^O eq 'solaris' or $^O eq 'sunos') {
2155             $lperl  = $libperl = "$dir/$Config::Config{libperl}";
2156             # SUNOS ld does not take the full path to a shared library
2157             $libperl = '' if $^O eq 'sunos';
2158           }
2159         }
2160
2161         print STDOUT "Warning: $libperl not found
2162     If you're going to build a static perl binary, make sure perl is installed
2163     otherwise ignore this warning\n"
2164                 unless (-f $lperl || defined($self->{PERL_SRC}));
2165     }
2166
2167     push @m, "
2168 MAP_LIBPERL = $libperl
2169 ";
2170
2171     push @m, "
2172 \$(INST_ARCHAUTODIR)/extralibs.all: \$(INST_ARCHAUTODIR)/.exists ".join(" \\\n\t", @$extra)."
2173         $self->{NOECHO}$self->{RM_F} \$\@
2174         $self->{NOECHO}\$(TOUCH) \$\@
2175 ";
2176
2177     my $catfile;
2178     foreach $catfile (@$extra){
2179         push @m, "\tcat $catfile >> \$\@\n";
2180     }
2181     # SUNOS ld does not take the full path to a shared library
2182     my $llibperl = ($libperl)?'$(MAP_LIBPERL)':'-lperl';
2183
2184     # Brain dead solaris linker does not use LD_RUN_PATH?
2185     # This fixes dynamic extensions which need shared libs
2186     my $ldfrom = ($^O eq 'solaris')?
2187            join(' ', map "-R$_", split /:/, $self->{LD_RUN_PATH}):'';
2188
2189 push @m, "
2190 \$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all
2191         \$(MAP_LINKCMD) -o \$\@ \$(OPTIMIZE) $tmp/perlmain\$(OBJ_EXT) $ldfrom $llibperl \$(MAP_STATIC) `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS)
2192         $self->{NOECHO}echo 'To install the new \"\$(MAP_TARGET)\" binary, call'
2193         $self->{NOECHO}echo '    make -f $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
2194         $self->{NOECHO}echo 'To remove the intermediate files say'
2195         $self->{NOECHO}echo '    make -f $makefilename map_clean'
2196
2197 $tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c
2198 ";
2199     push @m, "\tcd $tmp && $cccmd -I\$(PERL_INC) perlmain.c\n";
2200
2201     push @m, qq{
2202 $tmp/perlmain.c: $makefilename}, q{
2203         }.$self->{NOECHO}.q{echo Writing $@
2204         }.$self->{NOECHO}.q{$(PERL) $(MAP_PERLINC) -MExtUtils::Miniperl \\
2205                 -e "writemain(grep s#.*/auto/##, qw|$(MAP_STATIC)|)" > $@t && $(MV) $@t $@
2206
2207 };
2208
2209     push @m, q{
2210 doc_inst_perl:
2211         }.$self->{NOECHO}.q{echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
2212         }.$self->{NOECHO}.q{$(DOC_INSTALL) \
2213                 "Perl binary" "$(MAP_TARGET)" \
2214                 MAP_STATIC "$(MAP_STATIC)" \
2215                 MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
2216                 MAP_LIBPERL "$(MAP_LIBPERL)" \
2217                 >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
2218
2219 };
2220
2221     push @m, q{
2222 inst_perl: pure_inst_perl doc_inst_perl
2223
2224 pure_inst_perl: $(MAP_TARGET)
2225         }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(INSTALLBIN)','$(MAP_TARGET)').q{
2226
2227 clean :: map_clean
2228
2229 map_clean :
2230         }.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
2231 };
2232
2233     join '', @m;
2234 }
2235
2236 =item makefile (o)
2237
2238 Defines how to rewrite the Makefile.
2239
2240 =cut
2241
2242 sub makefile {
2243     my($self) = shift;
2244     my @m;
2245     # We do not know what target was originally specified so we
2246     # must force a manual rerun to be sure. But as it should only
2247     # happen very rarely it is not a significant problem.
2248     push @m, '
2249 $(OBJECT) : $(FIRST_MAKEFILE)
2250 ' if $self->{OBJECT};
2251
2252     push @m, q{
2253 # We take a very conservative approach here, but it\'s worth it.
2254 # We move Makefile to Makefile.old here to avoid gnu make looping.
2255 }.$self->{MAKEFILE}.q{ : Makefile.PL $(CONFIGDEP)
2256         }.$self->{NOECHO}.q{echo "Makefile out-of-date with respect to $?"
2257         }.$self->{NOECHO}.q{echo "Cleaning current config before rebuilding Makefile..."
2258         -}.$self->{NOECHO}.q{$(MV) }."$self->{MAKEFILE} $self->{MAKEFILE}.old".q{
2259         -$(MAKE) -f }.$self->{MAKEFILE}.q{.old clean $(DEV_NULL) || $(NOOP)
2260         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" Makefile.PL }.join(" ",map(qq["$_"],@ARGV)).q{
2261         }.$self->{NOECHO}.q{echo "==> Your Makefile has been rebuilt. <=="
2262         }.$self->{NOECHO}.q{echo "==> Please rerun the make command.  <=="
2263         false
2264
2265 # To change behavior to :: would be nice, but would break Tk b9.02
2266 # so you find such a warning below the dist target.
2267 #}.$self->{MAKEFILE}.q{ :: $(VERSION_FROM)
2268 #       }.$self->{NOECHO}.q{echo "Warning: Makefile possibly out of date with $(VERSION_FROM)"
2269 };
2270
2271     join "", @m;
2272 }
2273
2274 =item manifypods (o)
2275
2276 Defines targets and routines to translate the pods into manpages and
2277 put them into the INST_* directories.
2278
2279 =cut
2280
2281 sub manifypods {
2282     my($self, %attribs) = @_;
2283     return "\nmanifypods :\n\t$self->{NOECHO}\$(NOOP)\n" unless %{$self->{MAN3PODS}} or %{$self->{MAN1PODS}};
2284     my($dist);
2285     my($pod2man_exe);
2286     if (defined $self->{PERL_SRC}) {
2287         $pod2man_exe = $self->catfile($self->{PERL_SRC},'pod','pod2man');
2288     } else {
2289         $pod2man_exe = $self->catfile($Config{scriptdirexp},'pod2man');
2290     }
2291     unless ($self->perl_script($pod2man_exe)) {
2292         # No pod2man but some MAN3PODS to be installed
2293         print <<END;
2294
2295 Warning: I could not locate your pod2man program. Please make sure,
2296          your pod2man program is in your PATH before you execute 'make'
2297
2298 END
2299         $pod2man_exe = "-S pod2man";
2300     }
2301     my(@m);
2302     push @m,
2303 qq[POD2MAN_EXE = $pod2man_exe\n],
2304 q[POD2MAN = $(PERL) -we '%m=@ARGV;for (keys %m){' \\
2305 -e 'next if -e $$m{$$_} && -M $$m{$$_} < -M $$_ && -M $$m{$$_} < -M "].$self->{MAKEFILE}.q[";' \\
2306 -e 'print "Manifying $$m{$$_}\n";' \\
2307 -e 'system(qq[$$^X ].q["-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" $(POD2MAN_EXE) ].qq[$$_>$$m{$$_}])==0 or warn "Couldn\\047t install $$m{$$_}\n";' \\
2308 -e 'chmod 0644, $$m{$$_} or warn "chmod 644 $$m{$$_}: $$!\n";}'
2309 ];
2310     push @m, "\nmanifypods : ";
2311     push @m, join " \\\n\t", keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}};
2312
2313     push(@m,"\n");
2314     if (%{$self->{MAN1PODS}} || %{$self->{MAN3PODS}}) {
2315         push @m, "\t$self->{NOECHO}\$(POD2MAN) \\\n\t";
2316         push @m, join " \\\n\t", %{$self->{MAN1PODS}}, %{$self->{MAN3PODS}};
2317     }
2318     join('', @m);
2319 }
2320
2321 =item maybe_command
2322
2323 Returns true, if the argument is likely to be a command.
2324
2325 =cut
2326
2327 sub maybe_command {
2328     my($self,$file) = @_;
2329     return $file if -x $file && ! -d $file;
2330     return;
2331 }
2332
2333 =item maybe_command_in_dirs
2334
2335 method under development. Not yet used. Ask Ilya :-)
2336
2337 =cut
2338
2339 sub maybe_command_in_dirs {     # $ver is optional argument if looking for perl
2340 # Ilya's suggestion. Not yet used, want to understand it first, but at least the code is here
2341     my($self, $names, $dirs, $trace, $ver) = @_;
2342     my($name, $dir);
2343     foreach $dir (@$dirs){
2344         next unless defined $dir; # $self->{PERL_SRC} may be undefined
2345         foreach $name (@$names){
2346             my($abs,$tryabs);
2347             if ($self->file_name_is_absolute($name)) { # /foo/bar
2348                 $abs = $name;
2349             } elsif ($self->canonpath($name) eq $self->canonpath(basename($name))) { # bar
2350                 $abs = $self->catfile($dir, $name);
2351             } else { # foo/bar
2352                 $abs = $self->catfile($self->curdir, $name);
2353             }
2354             print "Checking $abs for $name\n" if ($trace >= 2);
2355             next unless $tryabs = $self->maybe_command($abs);
2356             print "Substituting $tryabs instead of $abs\n"
2357                 if ($trace >= 2 and $tryabs ne $abs);
2358             $abs = $tryabs;
2359             if (defined $ver) {
2360                 print "Executing $abs\n" if ($trace >= 2);
2361                 if (`$abs -e 'require $ver; print "VER_OK\n" ' 2>&1` =~ /VER_OK/) {
2362                     print "Using PERL=$abs\n" if $trace;
2363                     return $abs;
2364                 }
2365             } else { # Do not look for perl
2366                 return $abs;
2367             }
2368         }
2369     }
2370 }
2371
2372 =item needs_linking (o)
2373
2374 Does this module need linking? Looks into subdirectory objects (see
2375 also has_link_code())
2376
2377 =cut
2378
2379 sub needs_linking {
2380     my($self) = shift;
2381     my($child,$caller);
2382     $caller = (caller(0))[3];
2383     Carp::confess("Needs_linking called too early") if $caller =~ /^ExtUtils::MakeMaker::/;
2384     return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
2385     if ($self->has_link_code or $self->{MAKEAPERL}){
2386         $self->{NEEDS_LINKING} = 1;
2387         return 1;
2388     }
2389     foreach $child (keys %{$self->{CHILDREN}}) {
2390         if ($self->{CHILDREN}->{$child}->needs_linking) {
2391             $self->{NEEDS_LINKING} = 1;
2392             return 1;
2393         }
2394     }
2395     return $self->{NEEDS_LINKING} = 0;
2396 }
2397
2398 =item nicetext
2399
2400 misnamed method (will have to be changed). The MM_Unix method just
2401 returns the argument without further processing.
2402
2403 On VMS used to insure that colons marking targets are preceded by
2404 space - most Unix Makes don't need this, but it's necessary under VMS
2405 to distinguish the target delimiter from a colon appearing as part of
2406 a filespec.
2407
2408 =cut
2409
2410 sub nicetext {
2411     my($self,$text) = @_;
2412     $text;
2413 }
2414
2415 =item parse_version
2416
2417 parse a file and return what you think is $VERSION in this file set to
2418
2419 =cut
2420
2421 sub parse_version {
2422     my($self,$parsefile) = @_;
2423     my $result;
2424     local *FH;
2425     local $/ = "\n";
2426     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
2427     my $inpod = 0;
2428     while (<FH>) {
2429         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2430         next if $inpod;
2431         chop;
2432         next unless /\$(([\w\:\']*)\bVERSION)\b.*\=/;
2433         my $eval = qq{
2434             package ExtUtils::MakeMaker::_version;
2435             no strict;
2436
2437             \$$1=undef; do {
2438                 $_
2439             }; \$$1
2440         };
2441         local($^W) = 0;
2442         $result = eval($eval) || 0;
2443         die "Could not eval '$eval' in $parsefile: $@" if $@;
2444         last;
2445     }
2446     close FH;
2447     return $result;
2448 }
2449
2450
2451 =item pasthru (o)
2452
2453 Defines the string that is passed to recursive make calls in
2454 subdirectories.
2455
2456 =cut
2457
2458 sub pasthru {
2459     my($self) = shift;
2460     my(@m,$key);
2461
2462     my(@pasthru);
2463     my($sep) = $Is_VMS ? ',' : '';
2464     $sep .= "\\\n\t";
2465
2466     foreach $key (qw(LIB LIBPERL_A LINKTYPE PREFIX OPTIMIZE)){
2467         push @pasthru, "$key=\"\$($key)\"";
2468     }
2469
2470     push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
2471     join "", @m;
2472 }
2473
2474 =item path
2475
2476 Takes no argument, returns the environment variable PATH as an array.
2477
2478 =cut
2479
2480 sub path {
2481     my($self) = @_;
2482     my $path_sep = $Is_OS2 ? ";" : ":";
2483     my $path = $ENV{PATH};
2484     $path =~ s:\\:/:g if $Is_OS2;
2485     my @path = split $path_sep, $path;
2486     foreach(@path) { $_ = '.' if $_ eq '' }
2487     @path;
2488 }
2489
2490 =item perl_script
2491
2492 Takes one argument, a file name, and returns the file name, if the
2493 argument is likely to be a perl script. On MM_Unix this is true for
2494 any ordinary, readable file.
2495
2496 =cut
2497
2498 sub perl_script {
2499     my($self,$file) = @_;
2500     return $file if -r $file && -f _;
2501     return;
2502 }
2503
2504 =item perldepend (o)
2505
2506 Defines the dependency from all *.h files that come with the perl
2507 distribution.
2508
2509 =cut
2510
2511 sub perldepend {
2512     my($self) = shift;
2513     my(@m);
2514     push @m, q{
2515 # Check for unpropogated config.sh changes. Should never happen.
2516 # We do NOT just update config.h because that is not sufficient.
2517 # An out of date config.h is not fatal but complains loudly!
2518 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
2519         -}.$self->{NOECHO}.q{echo "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
2520
2521 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
2522         }.$self->{NOECHO}.q{echo "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
2523         cd $(PERL_SRC) && $(MAKE) lib/Config.pm
2524 } if $self->{PERL_SRC};
2525
2526     return join "", @m unless $self->needs_linking;
2527
2528     push @m, q{
2529 PERL_HDRS = \
2530 $(PERL_INC)/EXTERN.h       $(PERL_INC)/gv.h           $(PERL_INC)/pp.h       \
2531 $(PERL_INC)/INTERN.h       $(PERL_INC)/handy.h        $(PERL_INC)/proto.h    \
2532 $(PERL_INC)/XSUB.h         $(PERL_INC)/hv.h           $(PERL_INC)/regcomp.h  \
2533 $(PERL_INC)/av.h           $(PERL_INC)/keywords.h     $(PERL_INC)/regexp.h   \
2534 $(PERL_INC)/config.h       $(PERL_INC)/mg.h           $(PERL_INC)/scope.h    \
2535 $(PERL_INC)/cop.h          $(PERL_INC)/op.h           $(PERL_INC)/sv.h       \
2536 $(PERL_INC)/cv.h           $(PERL_INC)/opcode.h       $(PERL_INC)/unixish.h  \
2537 $(PERL_INC)/dosish.h       $(PERL_INC)/patchlevel.h   $(PERL_INC)/util.h     \
2538 $(PERL_INC)/embed.h        $(PERL_INC)/perl.h                                \
2539 $(PERL_INC)/form.h         $(PERL_INC)/perly.h
2540
2541 $(OBJECT) : $(PERL_HDRS)
2542 } if $self->{OBJECT};
2543
2544     push @m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
2545
2546     join "\n", @m;
2547 }
2548
2549 =item pm_to_blib
2550
2551 Defines target that copies all files in the hash PM to their
2552 destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
2553
2554 =cut
2555
2556 sub pm_to_blib {
2557     my $self = shift;
2558     my($autodir) = $self->catdir('$(INST_LIB)','auto');
2559     return q{
2560 pm_to_blib: $(TO_INST_PM)
2561         }.$self->{NOECHO}.q{$(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" \
2562         "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MExtUtils::Install \
2563         -e "pm_to_blib({qw{$(PM_TO_BLIB)}},'}.$autodir.q{')"
2564         }.$self->{NOECHO}.q{$(TOUCH) $@
2565 };
2566 }
2567
2568 =item post_constants (o)
2569
2570 Returns an empty string per default. Dedicated to overrides from
2571 within Makefile.PL after all constants have been defined.
2572
2573 =cut
2574
2575 sub post_constants{
2576     my($self) = shift;
2577     "";
2578 }
2579
2580 =item post_initialize (o)
2581
2582 Returns an empty string per default. Used in Makefile.PLs to add some
2583 chunk of text to the Makefile after the object is initialized.
2584
2585 =cut
2586
2587 sub post_initialize {
2588     my($self) = shift;
2589     "";
2590 }
2591
2592 =item postamble (o)
2593
2594 Returns an empty string. Can be used in Makefile.PLs to write some
2595 text to the Makefile at the end.
2596
2597 =cut
2598
2599 sub postamble {
2600     my($self) = shift;
2601     "";
2602 }
2603
2604 =item prefixify
2605
2606 Check a path variable in $self from %Config, if it contains a prefix,
2607 and replace it with another one.
2608
2609 Takes as arguments an attribute name, a search prefix and a
2610 replacement prefix. Changes the attribute in the object.
2611
2612 =cut
2613
2614 sub prefixify {
2615     my($self,$var,$sprefix,$rprefix) = @_;
2616     $self->{uc $var} ||= $Config{lc $var};
2617     $self->{uc $var} = VMS::Filespec::unixpath($self->{uc $var}) if $Is_VMS;
2618     $self->{uc $var} =~ s/\Q$sprefix\E/$rprefix/;
2619 }
2620
2621 =item processPL (o)
2622
2623 Defines targets to run *.PL files.
2624
2625 =cut
2626
2627 sub processPL {
2628     my($self) = shift;
2629     return "" unless $self->{PL_FILES};
2630     my(@m, $plfile);
2631     foreach $plfile (sort keys %{$self->{PL_FILES}}) {
2632         push @m, "
2633 all :: $self->{PL_FILES}->{$plfile}
2634
2635 $self->{PL_FILES}->{$plfile} :: $plfile
2636         \$(PERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) $plfile
2637 ";
2638     }
2639     join "", @m;
2640 }
2641
2642 =item realclean (o)
2643
2644 Defines the realclean target.
2645
2646 =cut
2647
2648 sub realclean {
2649     my($self, %attribs) = @_;
2650     my(@m);
2651     push(@m,'
2652 # Delete temporary files (via clean) and also delete installed files
2653 realclean purge ::  clean
2654 ');
2655     # realclean subdirectories first (already cleaned)
2656     my $sub = "\t-cd %s && \$(TEST_F) %s && \$(MAKE) %s realclean\n";
2657     foreach(@{$self->{DIR}}){
2658         push(@m, sprintf($sub,$_,"$self->{MAKEFILE}.old","-f $self->{MAKEFILE}.old"));
2659         push(@m, sprintf($sub,$_,"$self->{MAKEFILE}",''));
2660     }
2661     push(@m, "  $self->{RM_RF} \$(INST_AUTODIR) \$(INST_ARCHAUTODIR)\n");
2662     if( $self->has_link_code ){
2663         push(@m, "      $self->{RM_F} \$(INST_DYNAMIC) \$(INST_BOOT)\n");
2664         push(@m, "      $self->{RM_F} \$(INST_STATIC)\n");
2665     }
2666     push(@m, "  $self->{RM_F} " . join(" ", values %{$self->{PM}}) . "\n");
2667     my(@otherfiles) = ($self->{MAKEFILE},
2668                        "$self->{MAKEFILE}.old"); # Makefiles last
2669     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
2670     push(@m, "  $self->{RM_RF} @otherfiles\n") if @otherfiles;
2671     push(@m, "  $attribs{POSTOP}\n")       if $attribs{POSTOP};
2672     join("", @m);
2673 }
2674
2675 =item replace_manpage_separator
2676
2677 Takes the name of a package, which may be a nested package, in the
2678 form Foo/Bar and replaces the slash with C<::>. Returns the replacement.
2679
2680 =cut
2681
2682 sub replace_manpage_separator {
2683     my($self,$man) = @_;
2684     $man =~ s,/+,::,g;
2685     $man;
2686 }
2687
2688 =item static (o)
2689
2690 Defines the static target.
2691
2692 =cut
2693
2694 sub static {
2695 # --- Static Loading Sections ---
2696
2697     my($self) = shift;
2698     '
2699 ## $(INST_PM) has been moved to the all: target.
2700 ## It remains here for awhile to allow for old usage: "make static"
2701 #static :: '.$self->{MAKEFILE}.' $(INST_STATIC) $(INST_PM)
2702 static :: '.$self->{MAKEFILE}.' $(INST_STATIC)
2703         '.$self->{NOECHO}.'$(NOOP)
2704 ';
2705 }
2706
2707 =item static_lib (o)
2708
2709 Defines how to produce the *.a (or equivalent) files.
2710
2711 =cut
2712
2713 sub static_lib {
2714     my($self) = @_;
2715 # Come to think of it, if there are subdirs with linkcode, we still have no INST_STATIC
2716 #    return '' unless $self->needs_linking(); #might be because of a subdir
2717
2718     return '' unless $self->has_link_code;
2719
2720     my(@m);
2721     push(@m, <<'END');
2722 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)/.exists
2723         $(RM_RF) $@
2724 END
2725     # If this extension has it's own library (eg SDBM_File)
2726     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
2727     push(@m, "\t$self->{CP} \$(MYEXTLIB) \$\@\n") if $self->{MYEXTLIB};
2728
2729     push @m,
2730 q{      $(AR) $(AR_STATIC_ARGS) $@ $(OBJECT) && $(RANLIB) $@
2731         $(CHMOD) 755 $@
2732         }.$self->{NOECHO}.q{echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
2733 };
2734     # Old mechanism - still available:
2735     push @m,
2736 "\t$self->{NOECHO}".q{echo "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
2737 }       if $self->{PERL_SRC} && $self->{EXTRALIBS};
2738     push @m, "\n";
2739
2740     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
2741     join('', "\n",@m);
2742 }
2743
2744 =item staticmake (o)
2745
2746 Calls makeaperl.
2747
2748 =cut
2749
2750 sub staticmake {
2751     my($self, %attribs) = @_;
2752     my(@static);
2753
2754     my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
2755
2756     # And as it's not yet built, we add the current extension
2757     # but only if it has some C code (or XS code, which implies C code)
2758     if (@{$self->{C}}) {
2759         @static = $self->catfile($self->{INST_ARCHLIB},
2760                                  "auto",
2761                                  $self->{FULLEXT},
2762                                  "$self->{BASEEXT}$self->{LIB_EXT}"
2763                                 );
2764     }
2765
2766     # Either we determine now, which libraries we will produce in the
2767     # subdirectories or we do it at runtime of the make.
2768
2769     # We could ask all subdir objects, but I cannot imagine, why it
2770     # would be necessary.
2771
2772     # Instead we determine all libraries for the new perl at
2773     # runtime.
2774     my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
2775
2776     $self->makeaperl(MAKE       => $self->{MAKEFILE},
2777                      DIRS       => \@searchdirs,
2778                      STAT       => \@static,
2779                      INCL       => \@perlinc,
2780                      TARGET     => $self->{MAP_TARGET},
2781                      TMP        => "",
2782                      LIBPERL    => $self->{LIBPERL_A}
2783                     );
2784 }
2785
2786 =item subdir_x (o)
2787
2788 Helper subroutine for subdirs
2789
2790 =cut
2791
2792 sub subdir_x {
2793     my($self, $subdir) = @_;
2794     my(@m);
2795     qq{
2796
2797 subdirs ::
2798         $self->{NOECHO}cd $subdir && \$(MAKE) all \$(PASTHRU)
2799
2800 };
2801 }
2802
2803 =item subdirs (o)
2804
2805 Defines targets to process subdirectories.
2806
2807 =cut
2808
2809 sub subdirs {
2810 # --- Sub-directory Sections ---
2811     my($self) = shift;
2812     my(@m,$dir);
2813     # This method provides a mechanism to automatically deal with
2814     # subdirectories containing further Makefile.PL scripts.
2815     # It calls the subdir_x() method for each subdirectory.
2816     foreach $dir (@{$self->{DIR}}){
2817         push(@m, $self->subdir_x($dir));
2818 ####    print "Including $dir subdirectory\n";
2819     }
2820     if (@m){
2821         unshift(@m, "
2822 # The default clean, realclean and test targets in this Makefile
2823 # have automatically been given entries for each subdir.
2824
2825 ");
2826     } else {
2827         push(@m, "\n# none")
2828     }
2829     join('',@m);
2830 }
2831
2832 =item test (o)
2833
2834 Defines the test targets.
2835
2836 =cut
2837
2838 sub test {
2839 # --- Test and Installation Sections ---
2840
2841     my($self, %attribs) = @_;
2842     my $tests = $attribs{TESTS};
2843     if (!$tests && -d 't') {
2844         $tests = $Is_Win32 ? join(' ', <t\\*.t>) : 't/*.t';
2845     }
2846     my(@m);
2847     push(@m,"
2848 TEST_VERBOSE=0
2849 TEST_TYPE=test_\$(LINKTYPE)
2850 TEST_FILE = test.pl
2851 TESTDB_SW = -d
2852
2853 testdb :: testdb_\$(LINKTYPE)
2854
2855 test :: \$(TEST_TYPE)
2856 ");
2857     push(@m, map("\t$self->{NOECHO}cd $_ && \$(TEST_F) $self->{MAKEFILE} && \$(MAKE) test \$(PASTHRU)\n",
2858                  @{$self->{DIR}}));
2859     push(@m, "\t$self->{NOECHO}echo 'No tests defined for \$(NAME) extension.'\n")
2860         unless $tests or -f "test.pl" or @{$self->{DIR}};
2861     push(@m, "\n");
2862
2863     push(@m, "test_dynamic :: pure_all\n");
2864     push(@m, $self->test_via_harness('$(FULLPERL)', $tests)) if $tests;
2865     push(@m, $self->test_via_script('$(FULLPERL)', 'test.pl')) if -f "test.pl";
2866     push(@m, "\n");
2867
2868     push(@m, "testdb_dynamic :: pure_all\n");
2869     push(@m, $self->test_via_script('$(FULLPERL) $(TESTDB_SW)', '$(TEST_FILE)'));
2870     push(@m, "\n");
2871
2872     # Occasionally we may face this degenerate target:
2873     push @m, "test_ : test_dynamic\n\n";
2874
2875     if ($self->needs_linking()) {
2876         push(@m, "test_static :: pure_all \$(MAP_TARGET)\n");
2877         push(@m, $self->test_via_harness('./$(MAP_TARGET)', $tests)) if $tests;
2878         push(@m, $self->test_via_script('./$(MAP_TARGET)', 'test.pl')) if -f "test.pl";
2879         push(@m, "\n");
2880         push(@m, "testdb_static :: pure_all \$(MAP_TARGET)\n");
2881         push(@m, $self->test_via_script('./$(MAP_TARGET) $(TESTDB_SW)', '$(TEST_FILE)'));
2882         push(@m, "\n");
2883     } else {
2884         push @m, "test_static :: test_dynamic\n";
2885         push @m, "testdb_static :: testdb_dynamic\n";
2886     }
2887     join("", @m);
2888 }
2889
2890 =item test_via_harness (o)
2891
2892 Helper method to write the test targets
2893
2894 =cut
2895
2896 sub test_via_harness {
2897     my($self, $perl, $tests) = @_;
2898     "\tPERL_DL_NONLAZY=1 $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";
2899 }
2900
2901 =item test_via_script (o)
2902
2903 Other helper method for test.
2904
2905 =cut
2906
2907 sub test_via_script {
2908     my($self, $perl, $script) = @_;
2909     qq{\tPERL_DL_NONLAZY=1 $perl}.q{ -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) }.qq{$script
2910 };
2911 }
2912
2913 =item tool_autosplit (o)
2914
2915 Defines a simple perl call that runs autosplit. May be deprecated by
2916 pm_to_blib soon.
2917
2918 =cut
2919
2920 sub tool_autosplit {
2921 # --- Tool Sections ---
2922
2923     my($self, %attribs) = @_;
2924     my($asl) = "";
2925     $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
2926     q{
2927 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
2928 AUTOSPLITFILE = $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e 'use AutoSplit;}.$asl.q{autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) ;'
2929 };
2930 }
2931
2932 =item tools_other (o)
2933
2934 Defines SHELL, LD, TOUCH, CP, MV, RM_F, RM_RF, CHMOD, UMASK_NULL in
2935 the Makefile. Also defines the perl programs MKPATH,
2936 WARN_IF_OLD_PACKLIST, MOD_INSTALL. DOC_INSTALL, and UNINSTALL.
2937
2938 =cut
2939
2940 sub tools_other {
2941     my($self) = shift;
2942     my @m;
2943     my $bin_sh = $Config{sh} || '/bin/sh';
2944     push @m, qq{
2945 SHELL = $bin_sh
2946 };
2947
2948     for (qw/ CHMOD CP LD MV NOOP RM_F RM_RF TEST_F TOUCH UMASK_NULL DEV_NULL/ ) {
2949         push @m, "$_ = $self->{$_}\n";
2950     }
2951
2952     push @m, q{
2953 # The following is a portable way to say mkdir -p
2954 # To see which directories are created, change the if 0 to if 1
2955 MKPATH = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e mkpath
2956
2957 # This helps us to minimize the effect of the .exists files A yet
2958 # better solution would be to have a stable file in the perl
2959 # distribution with a timestamp of zero. But this solution doesn't
2960 # need any changes to the core distribution and works with older perls
2961 EQUALIZE_TIMESTAMP = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e eqtime
2962 };
2963
2964
2965     return join "", @m if $self->{PARENT};
2966
2967     push @m, q{
2968 # Here we warn users that an old packlist file was found somewhere,
2969 # and that they should call some uninstall routine
2970 WARN_IF_OLD_PACKLIST = $(PERL) -we 'exit unless -f $$ARGV[0];' \\
2971 -e 'print "WARNING: I have found an old package in\n";' \\
2972 -e 'print "\t$$ARGV[0].\n";' \\
2973 -e 'print "Please make sure the two installations are not conflicting\n";'
2974
2975 UNINST=0
2976 VERBINST=1
2977
2978 MOD_INSTALL = $(PERL) -I$(INST_LIB) -I$(PERL_LIB) -MExtUtils::Install \
2979 -e "install({@ARGV},'$(VERBINST)',0,'$(UNINST)');"
2980
2981 DOC_INSTALL = $(PERL) -e '$$\="\n\n";' \
2982 -e 'print "=head2 ", scalar(localtime), ": C<", shift, ">", " L<", shift, ">";' \
2983 -e 'print "=over 4";' \
2984 -e 'while (defined($$key = shift) and defined($$val = shift)){print "=item *";print "C<$$key: $$val>";}' \
2985 -e 'print "=back";'
2986
2987 UNINSTALL =   $(PERL) -MExtUtils::Install \
2988 -e 'uninstall($$ARGV[0],1,1); print "\nUninstall is deprecated. Please check the";' \
2989 -e 'print " packlist above carefully.\n  There may be errors. Remove the";' \
2990 -e 'print " appropriate files manually.\n  Sorry for the inconveniences.\n"'
2991 };
2992
2993     return join "", @m;
2994 }
2995
2996 =item tool_xsubpp (o)
2997
2998 Determines typemaps, xsubpp version, prototype behaviour.
2999
3000 =cut
3001
3002 sub tool_xsubpp {
3003     my($self) = shift;
3004     return "" unless $self->needs_linking;
3005     my($xsdir)  = $self->catdir($self->{PERL_LIB},"ExtUtils");
3006     my(@tmdeps) = $self->catdir('$(XSUBPPDIR)','typemap');
3007     if( $self->{TYPEMAPS} ){
3008         my $typemap;
3009         foreach $typemap (@{$self->{TYPEMAPS}}){
3010                 if( ! -f  $typemap ){
3011                         warn "Typemap $typemap not found.\n";
3012                 }
3013                 else{
3014                         push(@tmdeps,  $typemap);
3015                 }
3016         }
3017     }
3018     push(@tmdeps, "typemap") if -f "typemap";
3019     my(@tmargs) = map("-typemap $_", @tmdeps);
3020     if( exists $self->{XSOPT} ){
3021         unshift( @tmargs, $self->{XSOPT} );
3022     }
3023
3024
3025     my $xsubpp_version = $self->xsubpp_version($self->catfile($xsdir,"xsubpp"));
3026
3027     # What are the correct thresholds for version 1 && 2 Paul?
3028     if ( $xsubpp_version > 1.923 ){
3029         $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
3030     } else {
3031         if (defined $self->{XSPROTOARG} && $self->{XSPROTOARG} =~ /\-prototypes/) {
3032             print STDOUT qq{Warning: This extension wants to pass the switch "-prototypes" to xsubpp.
3033         Your version of xsubpp is $xsubpp_version and cannot handle this.
3034         Please upgrade to a more recent version of xsubpp.
3035 };
3036         } else {
3037             $self->{XSPROTOARG} = "";
3038         }
3039     }
3040
3041     return qq{
3042 XSUBPPDIR = $xsdir
3043 XSUBPP = \$(XSUBPPDIR)/xsubpp
3044 XSPROTOARG = $self->{XSPROTOARG}
3045 XSUBPPDEPS = @tmdeps
3046 XSUBPPARGS = @tmargs
3047 };
3048 };
3049
3050 sub xsubpp_version
3051 {
3052     my($self,$xsubpp) = @_;
3053     return $Xsubpp_Version if defined $Xsubpp_Version; # global variable
3054
3055     my ($version) ;
3056
3057     # try to figure out the version number of the xsubpp on the system
3058
3059     # first try the -v flag, introduced in 1.921 & 2.000a2
3060
3061     return "" unless $self->needs_linking;
3062
3063     my $command = "$self->{PERL} -I$self->{PERL_LIB} $xsubpp -v 2>&1";
3064     print "Running $command\n" if $Verbose >= 2;
3065     $version = `$command` ;
3066     warn "Running '$command' exits with status " . ($?>>8) if $?;
3067     chop $version ;
3068
3069     return $Xsubpp_Version = $1 if $version =~ /^xsubpp version (.*)/ ;
3070
3071     # nope, then try something else
3072
3073     my $counter = '000';
3074     my ($file) = 'temp' ;
3075     $counter++ while -e "$file$counter"; # don't overwrite anything
3076     $file .= $counter;
3077
3078     open(F, ">$file") or die "Cannot open file '$file': $!\n" ;
3079     print F <<EOM ;
3080 MODULE = fred PACKAGE = fred
3081
3082 int
3083 fred(a)
3084         int     a;
3085 EOM
3086
3087     close F ;
3088
3089     $command = "$self->{PERL} $xsubpp $file 2>&1";
3090     print "Running $command\n" if $Verbose >= 2;
3091     my $text = `$command` ;
3092     warn "Running '$command' exits with status " . ($?>>8) if $?;
3093     unlink $file ;
3094
3095     # gets 1.2 -> 1.92 and 2.000a1
3096     return $Xsubpp_Version = $1 if $text =~ /automatically by xsubpp version ([\S]+)\s*/  ;
3097
3098     # it is either 1.0 or 1.1
3099     return $Xsubpp_Version = 1.1 if $text =~ /^Warning: ignored semicolon/ ;
3100
3101     # none of the above, so 1.0
3102     return $Xsubpp_Version = "1.0" ;
3103 }
3104
3105 =item top_targets (o)
3106
3107 Defines the targets all, subdirs, config, and O_FILES
3108
3109 =cut
3110
3111 sub top_targets {
3112 # --- Target Sections ---
3113
3114     my($self) = shift;
3115     my(@m);
3116     push @m, '
3117 #all :: config $(INST_PM) subdirs linkext manifypods
3118 ';
3119
3120     push @m, '
3121 all :: pure_all manifypods
3122         '.$self->{NOECHO}.'$(NOOP)
3123
3124           unless $self->{SKIPHASH}{'all'};
3125     
3126     push @m, '
3127 pure_all :: config pm_to_blib subdirs linkext
3128         '.$self->{NOECHO}.'$(NOOP)
3129
3130 subdirs :: $(MYEXTLIB)
3131         '.$self->{NOECHO}.'$(NOOP)
3132
3133 config :: '.$self->{MAKEFILE}.' $(INST_LIBDIR)/.exists
3134         '.$self->{NOECHO}.'$(NOOP)
3135
3136 config :: $(INST_ARCHAUTODIR)/.exists
3137         '.$self->{NOECHO}.'$(NOOP)
3138
3139 config :: $(INST_AUTODIR)/.exists
3140         '.$self->{NOECHO}.'$(NOOP)
3141 ';
3142
3143     push @m, qq{
3144 config :: Version_check
3145         $self->{NOECHO}\$(NOOP)
3146
3147 } unless $self->{PARENT} or ($self->{PERL_SRC} && $self->{INSTALLDIRS} eq "perl") or $self->{NO_VC};
3148
3149     push @m, $self->dir_target(qw[$(INST_AUTODIR) $(INST_LIBDIR) $(INST_ARCHAUTODIR)]);
3150
3151     if (%{$self->{MAN1PODS}}) {
3152         push @m, qq[
3153 config :: \$(INST_MAN1DIR)/.exists
3154         $self->{NOECHO}\$(NOOP)
3155
3156 ];
3157         push @m, $self->dir_target(qw[$(INST_MAN1DIR)]);
3158     }
3159     if (%{$self->{MAN3PODS}}) {
3160         push @m, qq[
3161 config :: \$(INST_MAN3DIR)/.exists
3162         $self->{NOECHO}\$(NOOP)
3163
3164 ];
3165         push @m, $self->dir_target(qw[$(INST_MAN3DIR)]);
3166     }
3167
3168     push @m, '
3169 $(O_FILES): $(H_FILES)
3170 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
3171
3172     push @m, q{
3173 help:
3174         perldoc ExtUtils::MakeMaker
3175 };
3176
3177     push @m, q{
3178 Version_check:
3179         }.$self->{NOECHO}.q{$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
3180                 -MExtUtils::MakeMaker=Version_check \
3181                 -e "Version_check('$(MM_VERSION)')"
3182 };
3183
3184     join('',@m);
3185 }
3186
3187 =item writedoc
3188
3189 Obsolete, depecated method. Not used since Version 5.21.
3190
3191 =cut
3192
3193 sub writedoc {
3194 # --- perllocal.pod section ---
3195     my($self,$what,$name,@attribs)=@_;
3196     my $time = localtime;
3197     print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
3198     print join "\n\n=item *\n\n", map("C<$_>",@attribs);
3199     print "\n\n=back\n\n";
3200 }
3201
3202 =item xs_c (o)
3203
3204 Defines the suffix rules to compile XS files to C.
3205
3206 =cut
3207
3208 sub xs_c {
3209     my($self) = shift;
3210     return '' unless $self->needs_linking();
3211     '
3212 .xs.c:
3213         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >$*.tc && $(MV) $*.tc $@
3214 ';
3215 }
3216
3217 =item xs_o (o)
3218
3219 Defines suffix rules to go from XS to object files directly. This is
3220 only intended for broken make implementations.
3221
3222 =cut
3223
3224 sub xs_o {      # many makes are too dumb to use xs_c then c_o
3225     my($self) = shift;
3226     return '' unless $self->needs_linking();
3227     '
3228 .xs$(OBJ_EXT):
3229         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >xstmp.c && $(MV) xstmp.c $*.c
3230         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
3231 ';
3232 }
3233
3234 =item perl_archive
3235
3236 This is internal method that returns path to libperl.a equivalent
3237 to be linked to dynamic extensions. UNIX does not have one but OS2
3238 and Win32 do.
3239
3240 =cut 
3241
3242 sub perl_archive
3243 {
3244  return "";
3245 }
3246
3247 =item export_list
3248
3249 This is internal method that returns name of a file that is
3250 passed to linker to define symbols to be exported.
3251 UNIX does not have one but OS2 and Win32 do.
3252
3253 =cut 
3254
3255 sub export_list
3256 {
3257  return "";
3258 }
3259
3260
3261 1;
3262
3263 =back
3264
3265 =head1 SEE ALSO
3266
3267 L<ExtUtils::MakeMaker>
3268
3269 =cut
3270
3271 __END__