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