decedad1ce4e27f0c551cc79956a7c9deb63ad15
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MakeMaker.pm
1 package ExtUtils::MakeMaker::TieAtt;
2 # this package will go away again, when we don't have modules around
3 # anymore that import %att It ties an empty %att and records in which
4 # object this %att was tied. FETCH and STORE return/store-to the
5 # appropriate value from %$self
6
7 # the warndirectuse method warns if somebody calls MM->something. It
8 # has nothing to do with the tie'd %att.
9
10 $Enough_limit = 5;
11
12 sub TIEHASH {
13     bless { SECRETHASH => $_[1]};
14 }
15
16 sub FETCH {
17     print "Warning (non-fatal): Importing of %att is deprecated [$_[1]]
18         use \$self instead\n" unless ++$Enough>$Enough_limit;
19     print "Further ExtUtils::MakeMaker::TieAtt warnings suppressed\n" if $Enough==$Enough_limit;
20     $_[0]->{SECRETHASH}->{$_[1]};
21 }
22
23 sub STORE {
24     print "Warning (non-fatal): Importing of %att is deprecated [$_[1]][$_[2]]
25         use \$self instead\n" unless ++$Enough>$Enough_limit;
26     print "Further ExtUtils::MakeMaker::TieAtt warnings suppressed\n" if $Enough==$Enough_limit;
27     $_[0]->{SECRETHASH}->{$_[1]} = $_[2];
28 }
29
30 sub FIRSTKEY {
31     print "Warning (non-fatal): Importing of %att is deprecated [FIRSTKEY]
32         use \$self instead\n" unless ++$Enough>$Enough_limit;
33     print "Further ExtUtils::MakeMaker::TieAtt warnings suppressed\n" if $Enough==$Enough_limit;
34     each %{$_[0]->{SECRETHASH}};
35 }
36
37 sub NEXTKEY {
38     each %{$_[0]->{SECRETHASH}};
39 }
40
41 sub DESTROY {
42 }
43
44 sub warndirectuse {
45     my($caller) = @_;
46     return if $Enough>$Enough_limit;
47     print STDOUT "Warning (non-fatal): Direct use of class methods deprecated; use\n";
48     my($method) = $caller =~ /.*:(\w+)$/;
49     print STDOUT
50 '               my $self = shift;
51                 $self->MM::', $method, "();
52         instead\n";
53     print "Further ExtUtils::MakeMaker::TieAtt warnings suppressed\n"
54         if ++$Enough==$Enough_limit;
55 }
56
57 package ExtUtils::MakeMaker;
58
59 # Last edited $Date: 1995/11/24 21:01:25 $ by Andreas Koenig
60 # $Id: MakeMaker.pm,v 1.114 1995/11/24 21:01:25 k Exp $
61
62 $Version = $VERSION = "5.10";
63
64 $ExtUtils::MakeMaker::Version_OK = 4.13;        # Makefiles older than $Version_OK will die
65                         # (Will be checked from MakeMaker version 4.13 onwards)
66
67 use Config;
68 use Carp;
69 use Cwd;
70 require Exporter;
71 require ExtUtils::Manifest;
72 require ExtUtils::Liblist;
73 #use strict qw(refs);
74
75 eval {require DynaLoader;};     # Get mod2fname, if defined. Will fail
76                                 # with miniperl.
77
78 # print join "**\n**", "", %INC, "";
79 %NORMAL_INC = %INC;
80
81
82
83 @ISA = qw(Exporter);
84 @EXPORT = qw(&WriteMakefile &writeMakefile $Verbose &prompt);
85 @EXPORT_OK = qw($Version $VERSION &Version_check
86                 &help &neatvalue &mkbootstrap &mksymlists
87                 %att  ## Import of %att is deprecated, please use OO features!
88 );
89
90 $Is_VMS = $Config::Config{osname} eq 'VMS';
91 require ExtUtils::MM_VMS if $Is_VMS;
92 $Is_OS2 = $Config::Config{osname} =~ m|^os/?2$|i ;
93 $ENV{EMXSHELL} = 'sh' if $Is_OS2; # to run `commands`
94
95 $ExtUtils::MakeMaker::Verbose = 0 unless defined $ExtUtils::MakeMaker::Verbose;
96 $^W=1;
97 #$SIG{__DIE__} = sub { print @_, Carp::longmess(); die; };
98 ####$SIG{__WARN__} = sub { print Carp::longmess(); warn @_; };
99 $SIG{__WARN__} = sub {
100     $_[0] =~ /^Use of uninitialized value/ && return;
101     $_[0] =~ /used only once/ && return;
102     $_[0] =~ /^Subroutine\s+[\w:]+\s+redefined/ && return;
103     warn @_;
104 };
105
106 # Setup dummy package:
107 # MY exists for overriding methods to be defined within
108 unshift(@MY::ISA, qw(MM));
109
110 # Dummy package MM inherits actual methods from OS-specific
111 # default packages.  We use this intermediate package so
112 # MY::XYZ->func() can call MM->func() and get the proper
113 # default routine without having to know under what OS
114 # it's running.
115
116 @MM::ISA = qw[MM_Unix ExtUtils::MakeMaker];
117 unshift @MM::ISA, 'ExtUtils::MM_VMS' if $Is_VMS;
118 unshift @MM::ISA, 'ExtUtils::MM_OS2' if $Is_OS2;
119
120
121 @ExtUtils::MakeMaker::MM_Sections_spec = (
122     post_initialize     => {},
123     const_config        => {},
124     constants           => {},
125     const_loadlibs      => {},
126     const_cccmd         => {}, # the last but one addition here (CONST_CCCMD)
127     tool_autosplit      => {},
128     tool_xsubpp         => {},
129     tools_other         => {},
130     dist                => {},
131     macro               => {},
132     post_constants      => {},
133     pasthru             => {},
134     c_o                 => {},
135     xs_c                => {},
136     xs_o                => {},
137     top_targets         => {}, # currently the last section that adds a key to $self (DIR_TARGET)
138     linkext             => {},
139     dlsyms              => {},
140     dynamic             => {},
141     dynamic_bs          => {},
142     dynamic_lib         => {},
143     static              => {},
144     static_lib          => {},
145     installpm           => {},
146     manifypods          => {},
147     processPL           => {},
148     installbin          => {},
149     subdirs             => {},
150     clean               => {},
151     realclean           => {},
152     dist_basics         => {},
153     dist_core           => {},
154     dist_dir            => {},
155     dist_test           => {},
156     dist_ci             => {},
157     install             => {},
158     force               => {},
159     perldepend          => {},
160     makefile            => {},
161     staticmake          => {},  # Sadly this defines more macros
162     test                => {},
163     postamble           => {},  # should always be last the user has hands on
164     selfdocument        => {},  # well, he may override it, but he won't do it
165 );
166 # looses section ordering
167 %ExtUtils::MakeMaker::MM_Sections = @ExtUtils::MakeMaker::MM_Sections_spec;
168 # keeps order
169 @ExtUtils::MakeMaker::MM_Sections = grep(!ref, @ExtUtils::MakeMaker::MM_Sections_spec);
170
171 %ExtUtils::MakeMaker::Recognized_Att_Keys = %ExtUtils::MakeMaker::MM_Sections; # All sections are valid keys.
172
173 @ExtUtils::MakeMaker::Get_from_Config = qw(
174 ar
175 cc
176 cccdlflags
177 ccdlflags
178 dlext
179 dlsrc
180 ld
181 lddlflags
182 ldflags
183 libc
184 lib_ext
185 obj_ext
186 ranlib
187 so
188 );
189
190 my $item;
191 foreach $item (split(/\n/,attrib_help())){
192     next unless $item =~ m/^=item\s+(\w+)\s*$/;
193     $ExtUtils::MakeMaker::Recognized_Att_Keys{$1} = $2;
194     print "Attribute '$1' => '$2'\n" if ($ExtUtils::MakeMaker::Verbose >= 2);
195 }
196 foreach $item (@ExtUtils::MakeMaker::Get_from_Config) {
197     next unless $Config::Config{$item};
198     $ExtUtils::MakeMaker::Recognized_Att_Keys{uc $item} = $Config::Config{$item};
199     print "Attribute '\U$item\E' => '$Config::Config{$item}'\n"
200         if ($ExtUtils::MakeMaker::Verbose >= 2);
201 }
202
203 %ExtUtils::MakeMaker::Prepend_dot_dot = qw(
204 INST_LIB 1 INST_ARCHLIB 1 INST_EXE 1 MAP_TARGET 1 INST_MAN1DIR 1 INST_MAN3DIR 1
205 PERL_SRC 1 PERL 1 FULLPERL 1
206 );
207 $PACKNAME = "PACK000";
208
209 sub writeMakefile {
210     die <<END;
211
212 The extension you are trying to build apparently is rather old and
213 most probably outdated. We detect that from the fact, that a
214 subroutine "writeMakefile" is called, and this subroutine is not
215 supported anymore since about October 1994.
216
217 Please contact the author or look into CPAN (details about CPAN can be
218 found in the FAQ and at http:/www.perl.com) for a more recent version
219 of the extension. If you're really desperate, you can try to change
220 the subroutine name from writeMakefile to WriteMakefile and rerun
221 'perl Makefile.PL', but you're most probably left alone, when you do
222 so.
223
224 The MakeMaker team
225
226 END
227 }
228
229 sub WriteMakefile {
230     Carp::croak "WriteMakefile: Need even number of args" if @_ % 2;
231     my %att = @_;
232     MM->new(\%att)->flush;
233 }
234
235 sub new {
236     my($class,$self) = @_;
237     my($key);
238
239     print STDOUT "MakeMaker (v$ExtUtils::MakeMaker::VERSION)\n" if $ExtUtils::MakeMaker::Verbose;
240     if (-f "MANIFEST" && ! -f "Makefile"){
241         check_manifest();
242     }
243
244     $self = {} unless (defined $self);
245
246     check_hints($self);
247
248     my(%initial_att) = %$self; # record initial attributes
249
250     if (defined $self->{CONFIGURE}) {
251         if (ref $self->{CONFIGURE} eq 'CODE') {
252             $self = { %$self, %{&{$self->{CONFIGURE}}}};
253         } else {
254             croak "Attribute 'CONFIGURE' to WriteMakefile() not a code reference\n";
255         }
256     }
257
258     # This is for old Makefiles written pre 5.00, will go away
259     if ( Carp::longmess("") =~ /runsubdirpl/s ){
260         $self->{Correct_relativ_directories}++;
261     } else {
262         $self->{Correct_relativ_directories}=0;
263     }
264
265     my $class = ++$PACKNAME;
266     {
267 #       no strict;
268         print "Blessing Object into class [$class]\n" if $ExtUtils::MakeMaker::Verbose;
269         mv_all_methods("MY",$class);
270         bless $self, $class;
271 ########        tie %::att, ExtUtils::MakeMaker::TieAtt, $self;
272         push @ExtUtils::MakeMaker::Parent, $self;
273         @{"$class\:\:ISA"} = 'MM';
274     }
275
276     if (defined $ExtUtils::MakeMaker::Parent[-2]){
277         $self->{PARENT} = $ExtUtils::MakeMaker::Parent[-2];
278         my $key;
279         for $key (keys %ExtUtils::MakeMaker::Prepend_dot_dot) {
280             next unless defined $self->{PARENT}{$key};
281             $self->{$key} = $self->{PARENT}{$key};
282             $self->{$key} = $self->catdir("..",$self->{$key})
283                 unless $self->{$key} =~ m!^/!;
284         }
285         $self->{PARENT}->{CHILDREN}->{$class} = $self if $self->{PARENT};
286     } else {
287         parse_args($self,@ARGV);
288     }
289
290     $self->{NAME} ||= $self->guess_name;
291
292     ($self->{NAME_SYM} = $self->{NAME}) =~ s/\W+/_/g;
293
294     $self->init_main();
295
296     if (! $self->{PERL_SRC} &&
297         $INC{'Config.pm'} ne $self->catdir($Config::Config{archlibexp},'Config.pm')){
298         (my $pthinks = $INC{'Config.pm'}) =~ s!/Config\.pm$!!;
299         $pthinks =~ s!.*/!!;
300         print STDOUT <<END;
301 Your perl and your Config.pm seem to have different ideas about the architecture
302 they are running on.
303 Perl thinks: [$pthinks]
304 Config says: [$Config::Config{archname}]
305 This may or may not cause problems. Please check your installation of perl if you
306 have problems building this extension.
307 END
308     }
309
310     $self->init_dirscan();
311     $self->init_others();
312
313     push @{$self->{RESULT}}, <<END;
314 # This Makefile is for the $self->{NAME} extension to perl.
315 #
316 # It was generated automatically by MakeMaker version $ExtUtils::MakeMaker::VERSION from the contents
317 # of Makefile.PL. Don't edit this file, edit Makefile.PL instead.
318 #
319 #       ANY CHANGES MADE HERE WILL BE LOST!
320 #
321 #   MakeMaker Parameters:
322 END
323
324     foreach $key (sort keys %initial_att){
325         my($v) = neatvalue($initial_att{$key});
326         $v =~ s/(CODE|HASH|ARRAY|SCALAR)\([\dxa-f]+\)/$1\(...\)/;
327         $v =~ tr/\n/ /s;
328         push @{$self->{RESULT}}, "#     $key => $v";
329     }
330
331     # turn the SKIP array into a SKIPHASH hash
332     my (%skip,$skip);
333     for $skip (@{$self->{SKIP} || []}) {
334         $self->{SKIPHASH}{$skip} = 1;
335     }
336
337     # We run all the subdirectories now. They don't have much to query
338     # from the parent, but the parent has to query them: if they need linking!
339     my($dir);
340     unless ($self->{NORECURS}) {
341         foreach $dir (@{$self->{DIR}}){
342             chdir $dir;
343             package main;
344             local *FH;
345             open FH, "Makefile.PL";
346             eval join "", <FH>;
347             close FH;
348             chdir "..";
349         }
350     }
351
352     tie %::att, ExtUtils::MakeMaker::TieAtt, $self;
353     my $section;
354     foreach $section ( @ExtUtils::MakeMaker::MM_Sections ){
355         print "Processing Makefile '$section' section\n" if ($ExtUtils::MakeMaker::Verbose >= 2);
356         my($skipit) = $self->skipcheck($section);
357         if ($skipit){
358             push @{$self->{RESULT}}, "\n# --- MakeMaker $section section $skipit.";
359         } else { # MEMO: b 329 print "$self->{NAME}**$section**\n" and $section eq 'postamble'
360             my(%a) = %{$self->{$section} || {}};
361             push @{$self->{RESULT}}, "\n# --- MakeMaker $section section:";
362             push @{$self->{RESULT}}, "# " . join ", ", %a if $ExtUtils::MakeMaker::Verbose && %a;
363             push @{$self->{RESULT}}, $self->nicetext($self->$section( %a ));
364         }
365     }
366
367     push @{$self->{RESULT}}, "\n# End.";
368 ########    untie %::att;
369     pop @ExtUtils::MakeMaker::Parent;
370
371     $self;
372 }
373
374 sub check_manifest {
375     eval {require ExtUtils::Manifest};
376     if ($@){
377         print STDOUT "Warning: you have not installed the ExtUtils::Manifest
378          module -- skipping check of the MANIFEST file\n";
379     } else {
380         print STDOUT "Checking if your kit is complete...\n";
381         $ExtUtils::Manifest::Quiet=$ExtUtils::Manifest::Quiet=1; #avoid warning
382         my(@missed)=ExtUtils::Manifest::manicheck();
383         if (@missed){
384             print STDOUT "Warning: the following files are missing in your kit:\n";
385             print "\t", join "\n\t", @missed;
386             print STDOUT "\n";
387             print STDOUT "Please inform the author.\n";
388         } else {
389             print STDOUT "Looks good\n";
390         }
391     }
392 }
393
394 sub parse_args{
395     my($self, @args) = @_;
396     foreach (@args){
397         unless (m/(.*?)=(.*)/){
398             help(),exit 1 if m/^help$/;
399             ++$ExtUtils::MakeMaker::Verbose if m/^verb/;
400             next;
401         }
402         my($name, $value) = ($1, $2);
403         if ($value =~ m/^~(\w+)?/){ # tilde with optional username
404             $value =~ s [^~(\w*)]
405                 [$1 ?
406                  ((getpwnam($1))[7] || "~$1") :
407                  (getpwuid($>))[7]
408                  ]ex;
409         }
410         # This may go away, in mid 1996
411         if ($self->{Correct_relativ_directories}){
412             $value = $self->catdir("..",$value)
413                 if $ExtUtils::MakeMaker::Prepend_dot_dot{$name} && ! $value =~ m!^/!;
414         }
415         $self->{$name} = $value;
416     }
417     # This may go away, in mid 1996
418     delete $self->{Correct_relativ_directories};
419
420     # catch old-style 'potential_libs' and inform user how to 'upgrade'
421     if (defined $self->{potential_libs}){
422         my($msg)="'potential_libs' => '$self->{potential_libs}' should be";
423         if ($self->{potential_libs}){
424             print STDOUT "$msg changed to:\n\t'LIBS' => ['$self->{potential_libs}']\n";
425         } else {
426             print STDOUT "$msg deleted.\n";
427         }
428         $self->{LIBS} = [$self->{potential_libs}];
429         delete $self->{potential_libs};
430     }
431     # catch old-style 'ARMAYBE' and inform user how to 'upgrade'
432     if (defined $self->{ARMAYBE}){
433         my($armaybe) = $self->{ARMAYBE};
434         print STDOUT "ARMAYBE => '$armaybe' should be changed to:\n",
435                         "\t'dynamic_lib' => {ARMAYBE => '$armaybe'}\n";
436         my(%dl) = %{$self->{dynamic_lib} || {}};
437         $self->{dynamic_lib} = { %dl, ARMAYBE => $armaybe};
438         delete $self->{ARMAYBE};
439     }
440     if (defined $self->{LDTARGET}){
441         print STDOUT "LDTARGET should be changed to LDFROM\n";
442         $self->{LDFROM} = $self->{LDTARGET};
443         delete $self->{LDTARGET};
444     }
445     # Turn a DIR argument on the command line into an array
446     if (defined $self->{DIR} && ref \$self->{DIR} eq 'SCALAR') {
447         # So they can choose from the command line, which extensions they want
448         # the grep enables them to have some colons too much in case they
449         # have to build a list with the shell
450         $self->{DIR} = [grep $_, split ":", $self->{DIR}];
451     }
452     my $mmkey;
453     foreach $mmkey (sort keys %$self){
454         print STDOUT "  $mmkey => ", neatvalue($self->{$mmkey}), "\n" if $ExtUtils::MakeMaker::Verbose;
455         print STDOUT "'$mmkey' is not a known MakeMaker parameter name.\n"
456             unless exists $ExtUtils::MakeMaker::Recognized_Att_Keys{$mmkey};
457     }
458 }
459
460 sub check_hints {
461     my($self) = @_;
462     # We allow extension-specific hints files.
463
464     return unless -d "hints";
465
466     # First we look for the best hintsfile we have
467     my(@goodhints);
468     my($hint)="$Config::Config{osname}_$Config::Config{osvers}";
469     $hint =~ s/\./_/g;
470     $hint =~ s/_$//;
471     return unless $hint;
472
473     # Also try without trailing minor version numbers.
474     while (1) {
475         last if -f "hints/$hint.pl";      # found
476     } continue {
477         last unless $hint =~ s/_[^_]*$//; # nothing to cut off
478     }
479     return unless -f "hints/$hint.pl";    # really there
480
481     # execute the hintsfile:
482     local *HINTS;
483     open HINTS, "hints/$hint.pl";
484     @goodhints = <HINTS>;
485     close HINTS;
486     print STDOUT "Processing hints file hints/$hint.pl\n";
487     eval join('',@goodhints);
488     print STDOUT $@ if $@;
489 }
490
491 sub mv_all_methods {
492     my($from,$to) = @_;
493     my($method);
494 #    no strict;
495
496     # Here you see the *current* list of methods that are overridable
497     # from Makefile.PL via MY:: subroutines. As of VERSION 5.07 I'm
498     # still trying to reduce the list to some reasonable minimum --
499     # because I want to make it easier for the user. A.K.
500
501     foreach $method (@ExtUtils::MakeMaker::MM_Sections, qw[ dir_target
502 exescan fileparse fileparse_set_fstype installpm_x libscan makeaperl
503 mksymlists needs_linking runsubdirpl subdir_x test_via_harness
504 test_via_script writedoc ]) {
505
506         # We cannot say "next" here. Nick might call MY->makeaperl
507         # which isn't defined right now
508
509         # next unless defined &{"${from}::$method"};
510
511         *{"${to}::$method"} = \&{"${from}::$method"};
512         my $symtab = \%{"${from}::"};
513
514         # delete would do, if we were sure, nobody ever called
515         # MY->makeaperl directly
516
517         # delete $symtab->{$method};
518
519         # If we delete a method, then it will be undefined and cannot
520         # be called.  But as long as we have Makefile.PLs that rely on
521         # %MY:: being intact, we have to fill the hole with an
522         # inheriting method:
523
524         eval "package MY; sub $method {local *$method; shift->MY::$method(\@_); }";
525
526     }
527
528     # We have to clean out %INC also, because the current directory is
529     # changed frequently and Graham Barr prefers to get his version
530     # out of a History.pl file which is "required" so woudn't get
531     # loaded again in another extension requiring a History.pl
532
533     my $inc;
534     foreach $inc (keys %INC) {
535         next if $ExtUtils::MakeMaker::NORMAL_INC{$inc};
536         #warn "***$inc*** deleted";
537         delete $INC{$inc};
538     }
539
540 }
541
542 sub prompt {
543     my($mess,$def)=@_;
544     BEGIN { my $ISA_TTY = -t STDIN && -t STDOUT }
545     Carp::confess("prompt function called without an argument") unless defined $mess;
546     $def = "" unless defined $def;
547     my $dispdef = "[$def] ";
548     my $ans;
549     if ($ISA_TTY) {
550         local $|=1;
551         print "$mess $dispdef";
552         chop($ans = <STDIN>);
553     }
554     return $ans if defined $ans;
555     return $def;
556 }
557
558 sub attrib_help {
559     return $Attrib_Help if $Attrib_Help;
560     my $switch = 0;
561     my $help;
562     my $line;
563     local *POD;
564 ####    local $/ = ""; # bug in 5.001m
565     open POD, $INC{"ExtUtils/MakeMaker.pm"}
566     or die "Open $INC{'ExtUtils/MakeMaker.pm'}: $!";
567     while ($line = <POD>) {
568         $switch ||= $line =~ /^=item C\s*$/;
569         next unless $switch;
570         last if $line =~ /^=cut/;
571         $help .= $line;
572     }
573     close POD;
574     $Attrib_Help = $help;
575 }
576
577 sub help {print &attrib_help, "\n";}
578
579 sub skipcheck{
580     my($self) = shift;
581     my($section) = @_;
582     if ($section eq 'dynamic') {
583         print STDOUT "Warning (non-fatal): Target 'dynamic' depends on targets ",
584         "in skipped section 'dynamic_bs'\n"
585             if $self->{SKIPHASH}{dynamic_bs} && $ExtUtils::MakeMaker::Verbose;
586         print STDOUT "Warning (non-fatal): Target 'dynamic' depends on targets ",
587         "in skipped section 'dynamic_lib'\n"
588             if $self->{SKIPHASH}{dynamic_lib} && $ExtUtils::MakeMaker::Verbose;
589     }
590     if ($section eq 'dynamic_lib') {
591         print STDOUT "Warning (non-fatal): Target '\$(INST_DYNAMIC)' depends on ",
592         "targets in skipped section 'dynamic_bs'\n"
593             if $self->{SKIPHASH}{dynamic_bs} && $ExtUtils::MakeMaker::Verbose;
594     }
595     if ($section eq 'static') {
596         print STDOUT "Warning (non-fatal): Target 'static' depends on targets ",
597         "in skipped section 'static_lib'\n"
598             if $self->{SKIPHASH}{static_lib} && $ExtUtils::MakeMaker::Verbose;
599     }
600     return 'skipped' if $self->{SKIPHASH}{$section};
601     return '';
602 }
603
604 sub flush {
605     my $self = shift;
606     my($chunk);
607     local *MAKE;
608     print STDOUT "Writing $self->{MAKEFILE} for $self->{NAME}\n";
609
610     unlink($self->{MAKEFILE}, "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : '');
611     open MAKE, ">MakeMaker.tmp" or die "Unable to open MakeMaker.tmp: $!";
612
613     for $chunk (@{$self->{RESULT}}) {
614         print MAKE "$chunk\n";
615     }
616
617     close MAKE;
618     my($finalname) = $Is_VMS ? "Descrip.MMS" : $self->{MAKEFILE};
619     rename("MakeMaker.tmp", $finalname);
620     chmod 0644, $finalname;
621     system("$Config::Config{eunicefix} $finalname") unless $Config::Config{eunicefix} eq ":";
622 }
623
624 sub Version_check {
625     my($checkversion) = @_;
626     die "Your Makefile was built with ExtUtils::MakeMaker v $checkversion.
627 Current Version is $ExtUtils::MakeMaker::VERSION. There have been considerable
628 changes in the meantime.
629 Please rerun 'perl Makefile.PL' to regenerate the Makefile.\n"
630     if $checkversion < $ExtUtils::MakeMaker::Version_OK;
631     printf STDOUT "%s %s %s %s.\n", "Makefile built with ExtUtils::MakeMaker v",
632     $checkversion, "Current Version is", $ExtUtils::MakeMaker::VERSION
633         unless $checkversion == $ExtUtils::MakeMaker::VERSION;
634 }
635
636 sub mksymlists {
637     my $class = shift;
638     my $self = shift;
639     bless $self, $class;
640     tie %att, ExtUtils::MakeMaker::TieAtt, $self;
641     $self->parse_args(@ARGV);
642     $self->mksymlists(@_);
643 }
644
645 # The following mkbootstrap() is only for installations that are calling
646 # the pre-4.1 mkbootstrap() from their old Makefiles. This MakeMaker
647 # writes Makefiles, that use ExtUtils::Mkbootstrap directly.
648 sub mkbootstrap {
649     die <<END;
650 !!! Your Makefile has been built such a long time ago, !!!
651 !!! that is unlikely to work with current MakeMaker.   !!!
652 !!! Please rebuild your Makefile                       !!!
653 END
654 }
655
656 sub neatvalue {
657     my($v) = @_;
658     return "undef" unless defined $v;
659     my($t) = ref $v;
660     return "'$v'" unless $t;
661     if ($t eq 'ARRAY') {
662         my(@m, $elem, @neat);
663         push @m, "[";
664         foreach $elem (@$v) {
665             push @neat, "'$elem'";
666         }
667         push @m, join ", ", @neat;
668         push @m, "]";
669         return join "", @m;
670     }
671     return "$v" unless $t eq 'HASH';
672     my(@m, $key, $val);
673     push(@m,"$key=>".neatvalue($val)) while (($key,$val) = each %$v);
674     return "{ ".join(', ',@m)." }";
675 }
676
677 sub selfdocument {
678     my($self) = @_;
679     my(@m);
680     if ($ExtUtils::MakeMaker::Verbose){
681         push @m, "\n# Full list of MakeMaker attribute values:";
682         foreach $key (sort keys %$self){
683             next if $key eq 'RESULT' || $key =~ /^[A-Z][a-z]/;
684             my($v) = neatvalue($self->{$key});
685             $v =~ s/(CODE|HASH|ARRAY|SCALAR)\([\dxa-f]+\)/$1\(...\)/;
686             $v =~ tr/\n/ /s;
687             push @m, "# $key => $v";
688         }
689     }
690     join "\n", @m;
691 }
692
693
694  #     # #     #         #     #
695  ##   ## ##   ##         #     #  #    #     #    #    #
696  # # # # # # # #         #     #  ##   #     #     #  #
697  #  #  # #  #  #         #     #  # #  #     #      ##
698  #     # #     #         #     #  #  # #     #      ##
699  #     # #     #         #     #  #   ##     #     #  #
700  #     # #     # #######  #####   #    #     #    #    #
701
702 package MM_Unix;
703
704 use Config;
705 use Cwd;
706 use File::Basename;
707 require Exporter;
708
709 Exporter::import('ExtUtils::MakeMaker',
710         qw( $Verbose));
711
712 # These attributes cannot be overridden externally
713 @Other_Att_Keys{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)} = (1) x 3;
714
715 if ($Is_VMS = $Config::Config{osname} eq 'VMS') {
716     require VMS::Filespec;
717     import VMS::Filespec 'vmsify';
718 }
719
720 $Is_OS2 = $ExtUtils::MakeMaker::Is_OS2;
721
722 sub guess_name { # Charles! That's something for MM_VMS
723     my($self) = @_;
724     my $name = fastcwd();
725     if ($Is_VMS) {
726         $name =~ s:.*?([^.\]]+)\]:$1: unless ($name =~ s:.*[.\[]ext\.(.*)\]:$1:i);
727         $name =~ s#[.\]]#::#g;
728     } else {
729         $name =~ s:.*/:: unless ($name =~ s:^.*/ext/::);
730         $name =~ s#/#::#g;
731         $name =~ s#\-\d+\.\d+$##;  # this is new with MM 5.00
732     }
733     $name;
734 }
735
736 sub init_main {
737     my($self) = @_;
738     unless (ref $self){
739         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
740         $self = $ExtUtils::MakeMaker::Parent[-1];
741     }
742
743     # --- Initialize Module Name and Paths
744
745     # NAME    = The perl module name for this extension (eg DBD::Oracle).
746     # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
747     # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
748     # ROOTEXT = Directory part of FULLEXT with leading /.
749     ($self->{FULLEXT} =
750      $self->{NAME}) =~ s!::!/!g ;                            #eg. BSD/Foo/Socket
751
752     # Copied from DynaLoader:
753
754     my(@modparts) = split(/::/,$self->{NAME});
755     my($modfname) = $modparts[-1];
756
757     # Some systems have restrictions on files names for DLL's etc.
758     # mod2fname returns appropriate file base name (typically truncated)
759     # It may also edit @modparts if required.
760     if (defined &DynaLoader::mod2fname) {
761         $modfname = &DynaLoader::mod2fname(\@modparts);
762     } elsif ($Is_OS2) {                # Need manual correction if run with miniperl:-(
763         $modfname = substr($modfname, 0, 7) . '_';
764     }
765
766
767     ($self->{BASEEXT} =
768      $self->{NAME}) =~ s!.*::!! ;                            #eg. Socket
769
770     if (defined &DynaLoader::mod2fname or $Is_OS2) {
771         # As of 5.001m, dl_os2 appends '_'
772         $self->{DLBASE} = $modfname;                    #eg. Socket_
773     } else {
774         $self->{DLBASE} = '$(BASEEXT)';
775     }
776
777     ($self->{ROOTEXT} =
778      $self->{FULLEXT}) =~ s#/?\Q$self->{BASEEXT}\E$## ;      #eg. /BSD/Foo
779
780     $self->{ROOTEXT} = ($Is_VMS ? '' : '/') . $self->{ROOTEXT} if $self->{ROOTEXT};
781
782
783     # --- Initialize PERL_LIB, INST_LIB, PERL_SRC
784
785     # *Real* information: where did we get these two from? ...
786     my $inc_config_dir = dirname($INC{'Config.pm'});
787     my $inc_carp_dir   = dirname($INC{'Carp.pm'});
788
789     # Typically PERL_* and INST_* will be identical but that need
790     # not be the case (e.g., installing into project libraries etc).
791
792     # Perl Macro:    With source    No source
793     # PERL_SRC       ../..          (undefined)
794     # PERL_LIB       PERL_SRC/lib   /usr/local/lib/perl5
795     # PERL_ARCHLIB   PERL_SRC/lib   /usr/local/lib/perl5/sun4-sunos
796
797     # INST Macro:    For standard   for any other
798     #                modules        module
799     # INST_LIB       PERL_SRC/lib   ./blib
800     # INST_ARCHLIB   PERL_SRC/lib   ./blib/<archname>
801
802     unless ($self->{PERL_SRC}){
803         my($dir);
804         foreach $dir (qw(.. ../.. ../../..)){
805             if ( -f "$dir/config.sh"
806                 && -f "$dir/perl.h"
807                 && -f "$dir/lib/Exporter.pm") {
808                 $self->{PERL_SRC}=$dir ;
809                 last;
810             }
811         }
812     }
813     if ($self->{PERL_SRC}){
814         $self->{PERL_LIB}     ||= $self->catdir("$self->{PERL_SRC}","lib");
815         $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
816         $self->{PERL_INC}     = $self->{PERL_SRC};
817         # catch an situation that has occurred a few times in the past:
818         warn <<EOM unless -s "$self->{PERL_SRC}/cflags";
819 You cannot build extensions below the perl source tree after executing
820 a 'make clean' in the perl source tree.
821
822 To rebuild extensions distributed with the perl source you should
823 simply Configure (to include those extensions) and then build perl as
824 normal. After installing perl the source tree can be deleted. It is not
825 needed for building extensions.
826
827 It is recommended that you unpack and build additional extensions away
828 from the perl source tree.
829 EOM
830     } else {
831         # we should also consider $ENV{PERL5LIB} here
832         $self->{PERL_LIB}     = $Config::Config{privlibexp} unless $self->{PERL_LIB};
833         $self->{PERL_ARCHLIB} = $Config::Config{archlibexp} unless $self->{PERL_ARCHLIB};
834         $self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
835         my $perl_h;
836         die <<EOM unless (-f ($perl_h = $self->catfile("$self->{PERL_INC}","perl.h")));
837 Error: Unable to locate installed Perl libraries or Perl source code.
838
839 It is recommended that you install perl in a standard location before
840 building extensions. You can say:
841
842     $^X Makefile.PL PERL_SRC=/path/to/perl/source/directory
843
844 if you have not yet installed perl but still want to build this
845 extension now.
846 (You get this message, because MakeMaker could not find "$perl_h")
847 EOM
848
849 #        print STDOUT "Using header files found in $self->{PERL_INC}\n"
850 #            if $Verbose && $self->needs_linking();
851
852     }
853
854     # INST_LIB typically pre-set if building an extension after
855     # perl has been built and installed. Setting INST_LIB allows
856     # you to build directly into, say $Config::Config{privlibexp}.
857     unless ($self->{INST_LIB}){
858
859
860         ##### XXXXX We have to change this nonsense
861
862         if (defined $self->{PERL_SRC}) {
863             $self->{INST_LIB} = $self->{PERL_LIB};
864         } else {
865             $self->{INST_LIB} = $self->catdir(".","blib");
866         }
867     }
868     # Try to work out what INST_ARCHLIB should be if not set:
869     unless ($self->{INST_ARCHLIB}){
870         my(%archmap) = (
871                         # our private build lib
872             $self->catdir(".","blib")   =>
873                         $self->catdir(".","blib",$Config::Config{archname}),
874             $self->{PERL_LIB}   => $self->{PERL_ARCHLIB},
875             $Config::Config{privlibexp} => $Config::Config{archlibexp},
876             $inc_carp_dir       => $inc_config_dir,
877         );
878         $self->{INST_ARCHLIB} = $archmap{$self->{INST_LIB}};
879         unless($self->{INST_ARCHLIB}){
880             # Oh dear, we'll have to default it and warn the user
881             my($archname) = $Config::Config{archname};
882             if (-d "$self->{INST_LIB}/$archname"){
883                 $self->{INST_ARCHLIB} = $self->catdir("$self->{INST_LIB}","$archname");
884                 print STDOUT "Defaulting INST_ARCHLIB to $self->{INST_ARCHLIB}\n";
885             } else {
886                 $self->{INST_ARCHLIB} = $self->{INST_LIB};
887             }
888         }
889     }
890     $self->{INST_EXE} ||= $self->catdir('.','blib',$Config::Config{archname});
891
892     if ($self->{PREFIX}){
893         $self->{INSTALLPRIVLIB} = $self->catdir($self->{PREFIX},"lib","perl5");
894         $self->{INSTALLBIN} = $self->catdir($self->{PREFIX},"bin");
895         $self->{INSTALLMAN3DIR} = $self->catdir($self->{PREFIX},"perl5","man","man3")
896             unless defined $self->{INSTALLMAN3DIR};
897     }
898
899     if( $self->{INSTALLPRIVLIB} && ! $self->{INSTALLARCHLIB} ){
900         my($archname) = $Config::Config{archname};
901         if (-d $self->catdir($self->{INSTALLPRIVLIB},$archname)){
902             $self->{INSTALLARCHLIB} = $self->catdir($self->{INSTALLPRIVLIB},$archname);
903             print STDOUT "Defaulting INSTALLARCHLIB to $self->{INSTALLARCHLIB}\n";
904         } else {
905             $self->{INSTALLARCHLIB} = $self->{INSTALLPRIVLIB};
906         }
907     }
908     $self->{INSTALLPRIVLIB} ||= $Config::Config{installprivlib};
909     $self->{INSTALLARCHLIB} ||= $Config::Config{installarchlib};
910     $self->{INSTALLBIN}     ||= $Config::Config{installbin};
911
912     $self->{INSTALLMAN1DIR} = $Config::Config{installman1dir}
913         unless defined $self->{INSTALLMAN1DIR};
914     unless (defined $self->{INST_MAN1DIR}){
915         if ($self->{INSTALLMAN1DIR} =~ /^(none|\s*)$/){
916             $self->{INST_MAN1DIR} = $self->{INSTALLMAN1DIR};
917         } else {
918             $self->{INST_MAN1DIR} = $self->catdir('.','blib','man','man1');
919         }
920     }
921     $self->{MAN1EXT} ||= $Config::Config{man1ext};
922
923     $self->{INSTALLMAN3DIR} = $Config::Config{installman3dir}
924         unless defined $self->{INSTALLMAN3DIR};
925     unless (defined $self->{INST_MAN3DIR}){
926         if ($self->{INSTALLMAN3DIR} =~ /^(none|\s*)$/){
927             $self->{INST_MAN3DIR} = $self->{INSTALLMAN3DIR};
928         } else {
929             $self->{INST_MAN3DIR} = $self->catdir('.','blib','man','man3');
930         }
931     }
932     $self->{MAN3EXT} ||= $Config::Config{man3ext};
933
934     print STDOUT "CONFIG must be an array ref\n"
935         if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
936     $self->{CONFIG} = [] unless (ref $self->{CONFIG});
937     push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
938     push(@{$self->{CONFIG}}, 'shellflags') if $Config::Config{shellflags};
939     my(%once_only,$m);
940     foreach $m (@{$self->{CONFIG}}){
941         next if $once_only{$m};
942         print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
943                 unless exists $Config::Config{$m};
944         $self->{uc $m} ||= $Config::Config{$m};
945         $once_only{$m} = 1;
946     }
947
948     # These should never be needed
949     $self->{LD} ||= 'ld';
950     $self->{OBJ_EXT} ||= '.o';
951     $self->{LIB_EXT} ||= '.a';
952
953     $self->{MAP_TARGET} ||= "perl";
954
955     unless ($self->{LIBPERL_A}){
956         if ($Is_VMS) {
957             $self->{LIBPERL_A} = 'libperl.olb';
958         } else {
959             $self->{LIBPERL_A} = "libperl$self->{LIB_EXT}";
960         }
961     }
962
963     # make a few simple checks
964     warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
965         (Exporter.pm not found)"
966         unless (-f $self->catfile("$self->{PERL_LIB}","Exporter.pm"));
967
968     ($self->{DISTNAME}=$self->{NAME}) =~ s#(::)#-#g unless $self->{DISTNAME};
969     $self->{VERSION} = "0.10" unless $self->{VERSION};
970     ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
971
972
973     # --- Initialize Perl Binary Locations
974
975     # Find Perl 5. The only contract here is that both 'PERL' and 'FULLPERL'
976     # will be working versions of perl 5. miniperl has priority over perl
977     # for PERL to ensure that $(PERL) is usable while building ./ext/*
978     my $path_sep = $Is_OS2 ? ";" : $Is_VMS ? "/" : ":";
979     my $path = $ENV{PATH};
980     $path =~ s:\\:/:g if $Is_OS2;
981     my @path = split $path_sep, $path;
982     my ($component,@defpath);
983     foreach $component ($self->{PERL_SRC}, @path, $Config::Config{binexp}) {
984         push @defpath, $component if defined $component;
985     }
986     $self->{PERL} =
987         $self->find_perl(5.0, [ $^X, 'miniperl','perl','perl5',"perl$]" ],
988             \@defpath, $ExtUtils::MakeMaker::Verbose ) unless ($self->{PERL});
989 # don't check, if perl is executable, maybe they
990 # have decided to supply switches with perl
991
992     # Define 'FULLPERL' to be a non-miniperl (used in test: target)
993     ($self->{FULLPERL} = $self->{PERL}) =~ s/miniperl/perl/i
994         unless ($self->{FULLPERL});
995 }
996
997 sub init_dirscan {      # --- File and Directory Lists (.xs .pm .pod etc)
998     my($self) = @_;
999     unless (ref $self){
1000         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1001         $self = $ExtUtils::MakeMaker::Parent[-1];
1002     }
1003     my($name, %dir, %xs, %c, %h, %ignore, %pl_files, %manifypods);
1004     local(%pm); #the sub in find() has to see this hash
1005     $ignore{'test.pl'} = 1;
1006     $ignore{'makefile.pl'} = 1 if $Is_VMS;
1007     foreach $name ($self->lsdir(".")){
1008         next if ($name =~ /^\./ or $ignore{$name});
1009         if (-d $name){
1010             $dir{$name} = $name if (-f "$name/Makefile.PL");
1011         } elsif ($name =~ /\.xs$/){
1012             my($c); ($c = $name) =~ s/\.xs$/.c/;
1013             $xs{$name} = $c;
1014             $c{$c} = 1;
1015         } elsif ($name =~ /\.c$/i){
1016             $c{$name} = 1
1017                 unless $name =~ m/perlmain\.c/; # See MAP_TARGET
1018         } elsif ($name =~ /\.h$/i){
1019             $h{$name} = 1;
1020         } elsif ($name =~ /\.(p[ml]|pod)$/){
1021             $pm{$name} = $self->catfile('$(INST_LIBDIR)',"$name");
1022         } elsif ($name =~ /\.PL$/ && $name ne "Makefile.PL") {
1023             ($pl_files{$name} = $name) =~ s/\.PL$// ;
1024         }
1025     }
1026
1027     # Some larger extensions often wish to install a number of *.pm/pl
1028     # files into the library in various locations.
1029
1030     # The attribute PMLIBDIRS holds an array reference which lists
1031     # subdirectories which we should search for library files to
1032     # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ].  We
1033     # recursively search through the named directories (skipping any
1034     # which don't exist or contain Makefile.PL files).
1035
1036     # For each *.pm or *.pl file found $self->libscan() is called with
1037     # the default installation path in $_[1]. The return value of
1038     # libscan defines the actual installation location.  The default
1039     # libscan function simply returns the path.  The file is skipped
1040     # if libscan returns false.
1041
1042     # The default installation location passed to libscan in $_[1] is:
1043     #
1044     #  ./*.pm           => $(INST_LIBDIR)/*.pm
1045     #  ./xyz/...        => $(INST_LIBDIR)/xyz/...
1046     #  ./lib/...        => $(INST_LIB)/...
1047     #
1048     # In this way the 'lib' directory is seen as the root of the actual
1049     # perl library whereas the others are relative to INST_LIBDIR
1050     # (which includes ROOTEXT). This is a subtle distinction but one
1051     # that's important for nested modules.
1052
1053     $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}]
1054         unless $self->{PMLIBDIRS};
1055
1056     #only existing directories that aren't in $dir are allowed
1057
1058     # Avoid $_ wherever possible:
1059     # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
1060     my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
1061     my ($pmlibdir);
1062     @{$self->{PMLIBDIRS}} = ();
1063     foreach $pmlibdir (@pmlibdirs) {
1064         -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
1065     }
1066
1067     if (@{$self->{PMLIBDIRS}}){
1068         print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
1069             if ($ExtUtils::MakeMaker::Verbose >= 2);
1070         use File::Find;         # try changing to require !
1071         File::Find::find(sub {
1072             if (-d $_){
1073                 if ($_ eq "CVS" || $_ eq "RCS"){
1074                     $File::Find::prune = 1;
1075                 }
1076                 return;
1077             }
1078             my($path, $prefix) = ($File::Find::name, '$(INST_LIBDIR)');
1079             my $striplibpath;
1080             $prefix =  '$(INST_LIB)' if (($striplibpath = $path) =~ s:^lib/::);
1081             my($inst) = $self->catdir($prefix,$striplibpath);
1082             local($_) = $inst; # for backwards compatibility
1083             $inst = $self->libscan($inst);
1084             print "libscan($path) => '$inst'\n" if ($ExtUtils::MakeMaker::Verbose >= 2);
1085             return unless $inst;
1086             $pm{$path} = $inst;
1087         }, @{$self->{PMLIBDIRS}});
1088     }
1089
1090     $self->{DIR} = [sort keys %dir] unless $self->{DIR};
1091     $self->{XS}  = \%xs             unless $self->{XS};
1092     $self->{PM}  = \%pm             unless $self->{PM};
1093     $self->{C}   = [sort keys %c]   unless $self->{C};
1094     my(@o_files) = @{$self->{C}};
1095     $self->{O_FILES} = [grep s/\.c$/$self->{OBJ_EXT}/i, @o_files] ;
1096     $self->{H}   = [sort keys %h]   unless $self->{H};
1097     $self->{PL_FILES} = \%pl_files unless $self->{PL_FILES};
1098
1099     # Set up names of manual pages to generate from pods
1100     if ($self->{MAN1PODS}) {
1101     } elsif ( $self->{INST_MAN1DIR} =~ /^(none|\s*)$/ ) {
1102         $self->{MAN1PODS} = {};
1103     } else {
1104         my %manifypods = ();
1105         foreach $name (@{$self->{EXE_FILES}}) {
1106             local(*TESTPOD);
1107             my($ispod)=0;
1108             if (open(TESTPOD,"<$name")) {
1109                 my $testpodline;
1110                 while ($testpodline = <TESTPOD>) {
1111                     if($testpodline =~ /^=head/) {
1112                         $ispod=1;
1113                         last;
1114                     }
1115                 }
1116                 close(TESTPOD);
1117             } else {
1118                 # If it doesn't exist yet, we assume, it has pods in it
1119                 $ispod = 1;
1120             }
1121             if( $ispod ) {
1122                 $manifypods{$name} = '$(INST_MAN1DIR)'.basename($name).'$(MAN1EXT)';
1123             }
1124         }
1125
1126         $self->{MAN1PODS} = \%manifypods;
1127     }
1128     if ($self->{MAN3PODS}) {
1129     } elsif ( $self->{INST_MAN3DIR} =~ /^(none|\s*)$/ ) {
1130         $self->{MAN3PODS} = {};
1131     } else {
1132         my %manifypods = (); # we collect the keys first, i.e. the files
1133                              # we have to convert to pod
1134         foreach $name (keys %{$self->{PM}}) {
1135             if ($name =~ /\.pod$/ ) {
1136                 $manifypods{$name} = $self->{PM}{$name};
1137             } elsif ($name =~ /\.p[ml]$/ ) {
1138                 local(*TESTPOD);
1139                 my($ispod)=0;
1140                 open(TESTPOD,"<$name");
1141                 my $testpodline;
1142                 while ($testpodline = <TESTPOD>) {
1143                     if($testpodline =~ /^=head/) {
1144                         $ispod=1;
1145                         last;
1146                     }
1147                     #Speculation on the future (K.A., not A.K. :)
1148                     #if(/^=don't\S+install/) { $ispod=0; last}
1149                 }
1150                 close(TESTPOD);
1151
1152                 if( $ispod ) {
1153                     $manifypods{$name} = $self->{PM}{$name};
1154                 }
1155             }
1156         }
1157
1158         # Remove "Configure.pm" and similar, if it's not the only pod listed
1159         # To force inclusion, just name it "Configure.pod", or override MAN3PODS
1160         foreach $name (keys %manifypods) {
1161             if ($name =~ /(config|install|setup).*\.pm/i) {
1162                 delete $manifypods{$name};
1163                 next;
1164             }
1165             my($manpagename) = $name;
1166             unless ($manpagename =~ s!^lib/!!) {
1167                 $manpagename = join("/",$self->{ROOTEXT},$manpagename);
1168             }
1169             $manpagename =~ s/\.p(od|m|l)$//;
1170             # Strip leading slashes
1171             $manpagename =~ s!^/+!!;
1172             # Turn other slashes into colons
1173 #           $manpagename =~ s,/+,::,g;
1174             $manpagename = $self->replace_manpage_seperator($manpagename);
1175             $manifypods{$name} = "\$(INST_MAN3DIR)/$manpagename.\$(MAN3EXT)";
1176         }
1177         $self->{MAN3PODS} = \%manifypods;
1178     }
1179 }
1180
1181 sub lsdir {
1182     my($self) = shift;
1183     my($dir, $regex) = @_;
1184     local(*DIR, @ls);
1185     opendir(DIR, $dir || ".") or return ();
1186     @ls = readdir(DIR);
1187     closedir(DIR);
1188     @ls = grep(/$regex/, @ls) if $regex;
1189     @ls;
1190 }
1191
1192 sub replace_manpage_seperator {
1193     my($self,$man) = @_;
1194     $man =~ s,/+,::,g;
1195     $man;
1196 }
1197
1198 sub libscan {
1199     my($self,$path) = @_;
1200     return '' if $path =~ m:/RCS/: ;
1201     $path;
1202 }
1203
1204 sub init_others {       # --- Initialize Other Attributes
1205     my($self) = shift;
1206     unless (ref $self){
1207         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1208         $self = $ExtUtils::MakeMaker::Parent[-1];
1209     }
1210
1211     # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
1212     # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
1213     # undefined. In any case we turn it into an anon array:
1214     $self->{LIBS}=[] unless $self->{LIBS};
1215     $self->{LIBS}=[$self->{LIBS}] if ref \$self->{LIBS} eq SCALAR;
1216     $self->{LD_RUN_PATH} = "";
1217     my($libs);
1218     foreach $libs ( @{$self->{LIBS}} ){
1219         $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
1220         my(@libs) = $self->extliblist($libs);
1221         if ($libs[0] or $libs[1] or $libs[2]){
1222             # LD_RUN_PATH now computed by ExtUtils::Liblist
1223             ($self->{EXTRALIBS}, $self->{BSLOADLIBS}, $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
1224             last;
1225         }
1226     }
1227
1228     unless ( $self->{OBJECT} ){
1229         # init_dirscan should have found out, if we have C files
1230         $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
1231     }
1232     $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
1233     $self->{BOOTDEP}  = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
1234     $self->{PERLMAINCC} ||= '$(CC)';
1235     $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
1236
1237     # Sanity check: don't define LINKTYPE = dynamic if we're skipping
1238     # the 'dynamic' section of MM.  We don't have this problem with
1239     # 'static', since we either must use it (%Config says we can't
1240     # use dynamic loading) or the caller asked for it explicitly.
1241     if (!$self->{LINKTYPE}) {
1242        $self->{LINKTYPE} = grep(/dynamic/,@{$self->{SKIP} || []})
1243                         ? 'static'
1244                         : ($Config::Config{usedl} ? 'dynamic' : 'static');
1245     };
1246
1247     # These get overridden for VMS and maybe some other systems
1248     $self->{NOOP}  = "";
1249     $self->{FIRST_MAKEFILE} ||= "Makefile";
1250     $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE};
1251     $self->{MAKE_APERL_FILE} ||= "Makefile.aperl";
1252     $self->{RM_F}  = "rm -f";
1253     $self->{RM_RF} = "rm -rf";
1254     $self->{TOUCH} = "touch";
1255     $self->{CP} = "cp";
1256     $self->{MV} = "mv";
1257     $self->{CHMOD} = "chmod";
1258     $self->{UMASK_NULL} = "umask 0";
1259 }
1260
1261 sub find_perl{
1262     my($self, $ver, $names, $dirs, $trace) = @_;
1263     unless (ref $self){
1264         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1265         $self = $ExtUtils::MakeMaker::Parent[-1];
1266     }
1267     my($name, $dir);
1268     if ($trace >= 2){
1269         print "Looking for perl $ver by these names:
1270 @$names
1271 in these dirs:
1272 @$dirs
1273 ";
1274     }
1275     foreach $dir (@$dirs){
1276         next unless defined $dir; # $self->{PERL_SRC} may be undefined
1277         foreach $name (@$names){
1278             my $abs;
1279             if ($name =~ m|^/|) {
1280                 $abs = $name;
1281             } elsif ($name =~ m|/|) {
1282                 $abs = $self->catfile(".", $name); # not absolute
1283             } else {
1284                 $abs = $self->catfile($dir, $name);
1285             }
1286             print "Checking $abs\n" if ($trace >= 2);
1287             next unless $self->maybe_command($abs);
1288             print "Executing $abs\n" if ($trace >= 2);
1289             if (`$abs -e 'require $ver; print "VER_OK\n" ' 2>&1` =~ /VER_OK/) {
1290                 print "Using PERL=$abs\n" if $trace;
1291                 return $abs;
1292             }
1293         }
1294     }
1295     print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
1296     0; # false and not empty
1297 }
1298
1299 sub maybe_command {
1300     my($self,$file) = @_;
1301     return 1 if -x $file && ! -d $file;
1302     return;
1303 }
1304
1305 sub post_initialize {
1306     my($self) = shift;
1307     unless (ref $self){
1308         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1309         $self = $ExtUtils::MakeMaker::Parent[-1];
1310     }
1311     "";
1312 }
1313
1314 # --- Constants Sections ---
1315
1316 sub const_config {
1317     my($self) = shift;
1318     unless (ref $self){
1319         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1320         $self = $ExtUtils::MakeMaker::Parent[-1];
1321     }
1322     my(@m,$m);
1323     push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
1324     push(@m,"\n# They may have been overridden via Makefile.PL or on the command line\n");
1325     my(%once_only);
1326     foreach $m (@{$self->{CONFIG}}){
1327         next if $once_only{$m};
1328         push @m, "\U$m\E = ".$self->{uc $m}."\n";
1329         $once_only{$m} = 1;
1330     }
1331     join('', @m);
1332 }
1333
1334 sub constants {
1335     my($self) = @_;
1336     unless (ref $self){
1337         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1338         $self = $ExtUtils::MakeMaker::Parent[-1];
1339     }
1340     unless (ref $self){
1341         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1342         $self = $ExtUtils::MakeMaker::Parent[-1];
1343     }
1344     my(@m,$tmp);
1345
1346     push @m, "
1347 NAME = $self->{NAME}
1348 DISTNAME = $self->{DISTNAME}
1349 NAME_SYM = $self->{NAME_SYM}
1350 VERSION = $self->{VERSION}
1351 VERSION_SYM = $self->{VERSION_SYM}
1352 VERSION_MACRO = VERSION
1353 DEFINE_VERSION = -D\$(VERSION_MACRO)=\\\"\$(VERSION)\\\"
1354
1355 # In which directory should we put this extension during 'make'?
1356 # This is typically ./blib.
1357 # (also see INST_LIBDIR and relationship to ROOTEXT)
1358 INST_LIB = $self->{INST_LIB}
1359 INST_ARCHLIB = $self->{INST_ARCHLIB}
1360 INST_EXE = $self->{INST_EXE}
1361
1362 # AFS users will want to set the installation directories for
1363 # the final 'make install' early without setting INST_LIB,
1364 # INST_ARCHLIB, and INST_EXE for the testing phase
1365 INSTALLPRIVLIB = $self->{INSTALLPRIVLIB}
1366 INSTALLARCHLIB = $self->{INSTALLARCHLIB}
1367 INSTALLBIN = $self->{INSTALLBIN}
1368
1369 # Perl library to use when building the extension
1370 PERL_LIB = $self->{PERL_LIB}
1371 PERL_ARCHLIB = $self->{PERL_ARCHLIB}
1372 LIBPERL_A = $self->{LIBPERL_A}
1373
1374 MAKEMAKER = \$(PERL_LIB)/ExtUtils/MakeMaker.pm
1375 MM_VERSION = $ExtUtils::MakeMaker::VERSION
1376 FIRST_MAKEFILE  = $self->{FIRST_MAKEFILE}
1377 MAKE_APERL_FILE = $self->{MAKE_APERL_FILE}
1378
1379 PERLMAINCC = $self->{PERLMAINCC}
1380 ";
1381
1382     push @m, "
1383 # Where is the perl source code located?
1384 PERL_SRC = $self->{PERL_SRC}\n" if $self->{PERL_SRC};
1385
1386     push @m, "
1387 # Perl header files (will eventually be under PERL_LIB)
1388 PERL_INC = $self->{PERL_INC}
1389 # Perl binaries
1390 PERL = $self->{PERL}
1391 FULLPERL = $self->{FULLPERL}
1392 ";
1393     push @m, "
1394 # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
1395 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
1396 # ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
1397 # DLBASE  = Basename part of dynamic library. May be just equal BASEEXT.
1398 FULLEXT = $self->{FULLEXT}
1399 BASEEXT = $self->{BASEEXT}
1400 ROOTEXT = $self->{ROOTEXT}
1401 DLBASE  = $self->{DLBASE}
1402 ";
1403     push @m, "
1404 INC = $self->{INC}
1405 DEFINE = $self->{DEFINE}
1406 OBJECT = $self->{OBJECT}
1407 LDFROM = $self->{LDFROM}
1408 LINKTYPE = $self->{LINKTYPE}
1409
1410 # Handy lists of source code files:
1411 XS_FILES= ".join(" \\\n\t", sort keys %{$self->{XS}})."
1412 C_FILES = ".join(" \\\n\t", @{$self->{C}})."
1413 O_FILES = ".join(" \\\n\t", @{$self->{O_FILES}})."
1414 H_FILES = ".join(" \\\n\t", @{$self->{H}})."
1415 MAN1PODS = ".join(" \\\n\t", sort keys %{$self->{MAN1PODS}})."
1416 MAN3PODS = ".join(" \\\n\t", sort keys %{$self->{MAN3PODS}})."
1417
1418 # Man installation stuff:
1419 INST_MAN1DIR    = $self->{INST_MAN1DIR}
1420 INSTALLMAN1DIR  = $self->{INSTALLMAN1DIR}
1421 MAN1EXT = $self->{MAN1EXT}
1422
1423 INST_MAN3DIR    = $self->{INST_MAN3DIR}
1424 INSTALLMAN3DIR  = $self->{INSTALLMAN3DIR}
1425 MAN3EXT = $self->{MAN3EXT}
1426
1427
1428 # work around a famous dec-osf make(1) feature(?):
1429 makemakerdflt: all
1430
1431 .SUFFIXES: .xs .c .C \$(OBJ_EXT)
1432
1433 # .PRECIOUS: Makefile    # seems to be not necessary anymore
1434
1435 .PHONY: all config static dynamic test linkext
1436
1437 # This extension may link to it's own library (see SDBM_File)
1438 MYEXTLIB = $self->{MYEXTLIB}
1439
1440 # Where is the Config information that we are using/depend on
1441 CONFIGDEP = \$(PERL_ARCHLIB)/Config.pm \$(PERL_INC)/config.h
1442 ";
1443
1444     push @m, '
1445 # Where to put things:
1446 INST_LIBDIR     = $(INST_LIB)$(ROOTEXT)
1447 INST_ARCHLIBDIR = $(INST_ARCHLIB)$(ROOTEXT)
1448
1449 INST_AUTODIR      = $(INST_LIB)/auto/$(FULLEXT)
1450 INST_ARCHAUTODIR  = $(INST_ARCHLIB)/auto/$(FULLEXT)
1451 ';
1452
1453     if ($self->has_link_code()) {
1454         push @m, '
1455 INST_STATIC  = $(INST_ARCHAUTODIR)/$(BASEEXT)$(LIB_EXT)
1456 INST_DYNAMIC = $(INST_ARCHAUTODIR)/$(DLBASE).$(DLEXT)
1457 INST_BOOT    = $(INST_ARCHAUTODIR)/$(BASEEXT).bs
1458 ';
1459     } else {
1460         push @m, '
1461 INST_STATIC  =
1462 INST_DYNAMIC =
1463 INST_BOOT    =
1464 ';
1465     }
1466
1467     if ($Is_OS2) {
1468         $tmp = "$self->{BASEEXT}.def";
1469     } else {
1470         $tmp = "";
1471     }
1472     push @m, "
1473 EXPORT_LIST = $tmp
1474 ";
1475
1476     if ($Is_OS2) {
1477         $tmp = "\$(PERL_INC)/libperl.lib";
1478     } else {
1479         $tmp = "";
1480     }
1481     push @m, "
1482 PERL_ARCHIVE = $tmp
1483 ";
1484
1485     push @m, '
1486 INST_PM = '.join(" \\\n\t", sort values %{$self->{PM}}).'
1487 ';
1488
1489     join('',@m);
1490 }
1491
1492 sub const_loadlibs {
1493     my($self) = shift;
1494     unless (ref $self){
1495         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1496         $self = $ExtUtils::MakeMaker::Parent[-1];
1497     }
1498     return "" unless $self->needs_linking;
1499     # This description can be deleted after ExtUtils::Liblist is in
1500     # the perl dist with pods
1501     "
1502 # $self->{NAME} might depend on some other libraries:
1503 # (These comments may need revising:)
1504 #
1505 # Dependent libraries can be linked in one of three ways:
1506 #
1507 #  1.  (For static extensions) by the ld command when the perl binary
1508 #      is linked with the extension library. See EXTRALIBS below.
1509 #
1510 #  2.  (For dynamic extensions) by the ld command when the shared
1511 #      object is built/linked. See LDLOADLIBS below.
1512 #
1513 #  3.  (For dynamic extensions) by the DynaLoader when the shared
1514 #      object is loaded. See BSLOADLIBS below.
1515 #
1516 # EXTRALIBS =   List of libraries that need to be linked with when
1517 #               linking a perl binary which includes this extension
1518 #               Only those libraries that actually exist are included.
1519 #               These are written to a file and used when linking perl.
1520 #
1521 # LDLOADLIBS =  List of those libraries which can or must be linked into
1522 #               the shared library when created using ld. These may be
1523 #               static or dynamic libraries.
1524 #               LD_RUN_PATH is a colon separated list of the directories
1525 #               in LDLOADLIBS. It is passed as an environment variable to
1526 #               the process that links the shared library.
1527 #
1528 # BSLOADLIBS =  List of those libraries that are needed but can be
1529 #               linked in dynamically at run time on this platform.
1530 #               SunOS/Solaris does not need this because ld records
1531 #               the information (from LDLOADLIBS) into the object file.
1532 #               This list is used to create a .bs (bootstrap) file.
1533 #
1534 EXTRALIBS  = $self->{EXTRALIBS}
1535 LDLOADLIBS = $self->{LDLOADLIBS}
1536 BSLOADLIBS = $self->{BSLOADLIBS}
1537 LD_RUN_PATH= $self->{LD_RUN_PATH}
1538 ";
1539 }
1540
1541 sub const_cccmd {
1542     my($self,$libperl)=@_;
1543     unless (ref $self){
1544         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1545         $self = $ExtUtils::MakeMaker::Parent[-1];
1546     }
1547     return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
1548     return '' unless $self->needs_linking();
1549     $libperl or $libperl = $self->{LIBPERL_A} || "libperl$self->{LIB_EXT}" ;
1550     $libperl =~ s/\.\$\(A\)$/$self->{LIB_EXT}/;
1551     # This is implemented in the same manner as extliblist,
1552     # e.g., do both and compare results during the transition period.
1553     my($cc,$ccflags,$optimize,$large,$split, $shflags)
1554         = @Config{qw(cc ccflags optimize large split shellflags)};
1555     my($optdebug) = "";
1556
1557     $shflags = '' unless $shflags;
1558     my($prog, $uc, $perltype);
1559
1560     my(%map) =  (
1561                 D =>   '-DDEBUGGING',
1562                 E =>   '-DEMBED',
1563                 DE =>  '-DDEBUGGING -DEMBED',
1564                 M =>   '-DEMBED -DMULTIPLICITY',
1565                 DM =>  '-DDEBUGGING -DEMBED -DMULTIPLICITY',
1566                 );
1567
1568     if ($libperl =~ /libperl(\w*)\Q$self->{LIB_EXT}/){
1569         $uc = uc($1);
1570     } else {
1571         $uc = ""; # avoid warning
1572     }
1573     $perltype = $map{$uc} ? $map{$uc} : "";
1574
1575     if ($uc =~ /^D/) {
1576         $optdebug = "-g";
1577     }
1578
1579
1580     my($name);
1581     ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
1582     if ($prog = $Config::Config{$name}) {
1583         # Expand hints for this extension via the shell
1584         print STDOUT "Processing $name hint:\n" if $ExtUtils::MakeMaker::Verbose;
1585         my(@o)=`cc=\"$cc\"
1586           ccflags=\"$ccflags\"
1587           optimize=\"$optimize\"
1588           perltype=\"$perltype\"
1589           optdebug=\"$optdebug\"
1590           large=\"$large\"
1591           split=\"$split\"
1592           eval '$prog'
1593           echo cc=\$cc
1594           echo ccflags=\$ccflags
1595           echo optimize=\$optimize
1596           echo perltype=\$perltype
1597           echo optdebug=\$optdebug
1598           echo large=\$large
1599           echo split=\$split
1600           `;
1601         my(%cflags,$line);
1602         foreach $line (@o){
1603             chomp $line;
1604             if ($line =~ /(.*?)=\s*(.*)\s*$/){
1605                 $cflags{$1} = $2;
1606                 print STDOUT "  $1 = $2\n" if $ExtUtils::MakeMaker::Verbose;
1607             } else {
1608                 print STDOUT "Unrecognised result from hint: '$line'\n";
1609             }
1610         }
1611         (    $cc,$ccflags,$perltype,$optdebug,$optimize,$large,$split )=@cflags{
1612           qw( cc  ccflags  perltype  optdebug  optimize  large  split)};
1613     }
1614
1615     if ($optdebug) {
1616         $optimize = $optdebug;
1617     }
1618
1619     my($new) = "$cc -c \$(INC) $ccflags $optimize $perltype $large $split";
1620     $new =~ s/^\s+//; $new =~ s/\s+/ /g; $new =~ s/\s+$//;
1621
1622     my($cccmd) = $new;
1623     $cccmd =~ s/^\s*\Q$Config::Config{cc}\E\s/\$(CC) /;
1624     $cccmd .= " \$(DEFINE_VERSION)";
1625     $self->{CONST_CCCMD} = "CCCMD = $cccmd\n";
1626 }
1627
1628 # --- Tool Sections ---
1629
1630 sub tool_autosplit {
1631     my($self, %attribs) = @_;
1632     unless (ref $self){
1633         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1634         $self = $ExtUtils::MakeMaker::Parent[-1];
1635     }
1636     my($asl) = "";
1637     $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
1638     q{
1639 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
1640 AUTOSPLITFILE = $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e 'use AutoSplit;}.$asl.q{autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) ;'
1641 };
1642 }
1643
1644 sub tool_xsubpp {
1645     my($self) = shift;
1646     unless (ref $self){
1647         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1648         $self = $ExtUtils::MakeMaker::Parent[-1];
1649     }
1650     my($xsdir)  = "$self->{PERL_LIB}/ExtUtils";
1651     # drop back to old location if xsubpp is not in new location yet
1652     $xsdir = "$self->{PERL_SRC}/ext" unless (-f "$self->{PERL_LIB}/ExtUtils/xsubpp");
1653     my(@tmdeps) = ('$(XSUBPPDIR)/typemap');
1654     if( $self->{TYPEMAPS} ){
1655         my $typemap;
1656         foreach $typemap (@{$self->{TYPEMAPS}}){
1657                 if( ! -f  $typemap ){
1658                         warn "Typemap $typemap not found.\n";
1659                 }
1660                 else{
1661                         push(@tmdeps,  $typemap);
1662                 }
1663         }
1664     }
1665     push(@tmdeps, "typemap") if -f "typemap";
1666     my(@tmargs) = map("-typemap $_", @tmdeps);
1667     if( exists $self->{XSOPT} ){
1668         unshift( @tmargs, $self->{XSOPT} );
1669     }
1670
1671     my $xsubpp_version = $self->xsubpp_version("$xsdir/xsubpp");
1672
1673     # What are the correct thresholds for version 1 && 2 Paul?
1674     if ( $xsubpp_version > 1.923 ){
1675         $self->{XSPROTOARG} = "-noprototypes" unless defined $self->{XSPROTOARG};
1676     } else {
1677         if (defined $self->{XSPROTOARG} && $self->{XSPROTOARG} =~ /\-prototypes/) {
1678             print STDOUT qq{Warning: This extension wants to pass the switch "-prototypes" to xsubpp.
1679         Your version of xsubpp is $xsubpp_version and cannot handle this.
1680         Please upgrade to a more recent version of xsubpp.
1681 };
1682         } else {
1683             $self->{XSPROTOARG} = "";
1684         }
1685     }
1686
1687     "
1688 XSUBPPDIR = $xsdir
1689 XSUBPP = \$(XSUBPPDIR)/xsubpp
1690 XSPROTOARG = $self->{XSPROTOARG}
1691 XSUBPPDEPS = @tmdeps
1692 XSUBPPARGS = @tmargs
1693 ";
1694 };
1695
1696 sub xsubpp_version
1697 {
1698     my($self,$xsubpp) = @_;
1699     my ($version) ;
1700
1701     # try to figure out the version number of the xsubpp on the system
1702
1703     # first try the -v flag, introduced in 1.921 & 2.000a2
1704
1705     my $command = "$self->{PERL} $xsubpp -v 2>&1";
1706     print "Running: $command\n" if $Verbose;
1707     $version = `$command` ;
1708     warn "Running '$command' exits with status " . $?>>8 if $?;
1709     chop $version ;
1710
1711     return $1 if $version =~ /^xsubpp version (.*)/ ;
1712
1713     # nope, then try something else
1714
1715     my $counter = '000';
1716     my ($file) = 'temp' ;
1717     $counter++ while -e "$file$counter"; # don't overwrite anything
1718     $file .= $counter;
1719
1720     open(F, ">$file") or die "Cannot open file '$file': $!\n" ;
1721     print F <<EOM ;
1722 MODULE = fred PACKAGE = fred
1723
1724 int
1725 fred(a)
1726         int     a;
1727 EOM
1728
1729     close F ;
1730
1731     $command = "$self->{PERL} $xsubpp $file 2>&1";
1732     print "Running: $command\n" if $Verbose;
1733     my $text = `$command` ;
1734     warn "Running '$command' exits with status " . $?>>8 if $?;
1735     unlink $file ;
1736
1737     # gets 1.2 -> 1.92 and 2.000a1
1738     return $1 if $text =~ /automatically by xsubpp version ([\S]+)\s*/  ;
1739
1740     # it is either 1.0 or 1.1
1741     return 1.1 if $text =~ /^Warning: ignored semicolon/ ;
1742
1743     # none of the above, so 1.0
1744     return "1.0" ;
1745 }
1746
1747 sub tools_other {
1748     my($self) = shift;
1749     unless (ref $self){
1750         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1751         $self = $ExtUtils::MakeMaker::Parent[-1];
1752     }
1753     "
1754 SHELL = /bin/sh
1755 LD = $self->{LD}
1756 TOUCH = $self->{TOUCH}
1757 CP = $self->{CP}
1758 MV = $self->{MV}
1759 RM_F  = $self->{RM_F}
1760 RM_RF = $self->{RM_RF}
1761 CHMOD = $self->{CHMOD}
1762 UMASK_NULL = $self->{UMASK_NULL}
1763 ".q{
1764 # The following is a portable way to say mkdir -p
1765 # To see which directories are created, change the if 0 to if 1
1766 MKPATH = $(PERL) -wle '$$"="/"; foreach $$p (@ARGV){' \\
1767 -e 'next if -d $$p; my(@p); foreach(split(/\//,$$p)){' \\
1768 -e 'push(@p,$$_); next if -d "@p/"; print "mkdir @p" if 0;' \\
1769 -e 'mkdir("@p",0777)||die $$! } } exit 0;'
1770 };
1771 }
1772
1773 sub dist {
1774     my($self, %attribs) = @_;
1775     unless (ref $self){
1776         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1777         $self = $ExtUtils::MakeMaker::Parent[-1];
1778     }
1779     my(@m);
1780     # VERSION should be sanitised before use as a file name
1781     my($name)     = $attribs{NAME}     || '$(DISTVNAME)';
1782     my($tar)      = $attribs{TAR}      || 'tar';        # eg /usr/bin/gnutar
1783     my($tarflags) = $attribs{TARFLAGS} || 'cvf';
1784     my($compress) = $attribs{COMPRESS} || 'compress';   # eg gzip
1785     my($suffix)   = $attribs{SUFFIX}   || 'Z';          # eg gz
1786     my($shar)     = $attribs{SHAR}     || 'shar';       # eg "shar --gzip"
1787     my($preop)    = $attribs{PREOP}    || '@ true';     # eg update MANIFEST
1788     my($postop)   = $attribs{POSTOP}   || '@ true';     # eg remove the distdir
1789     my($ci)       = $attribs{CI}       || 'ci -u';
1790     my($rcs_label)= $attribs{RCS_LABEL}|| 'rcs -Nv$(VERSION_SYM): -q';
1791     my($dist_cp)  = $attribs{DIST_CP}  || 'best';
1792     my($dist_default) = $attribs{DIST_DEFAULT} || 'tardist';
1793
1794     push @m, "
1795 DISTVNAME = \$(DISTNAME)-\$(VERSION)
1796 TAR  = $tar
1797 TARFLAGS = $tarflags
1798 COMPRESS = $compress
1799 SUFFIX = $suffix
1800 SHAR = $shar
1801 PREOP = $preop
1802 POSTOP = $postop
1803 CI = $ci
1804 RCS_LABEL = $rcs_label
1805 DIST_CP = $dist_cp
1806 DIST_DEFAULT = $dist_default
1807 ";
1808     join "", @m;
1809 }
1810
1811 sub macro {
1812     my($self,%attribs) = @_;
1813     unless (ref $self){
1814         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1815         $self = $ExtUtils::MakeMaker::Parent[-1];
1816     }
1817     my(@m,$key,$val);
1818     while (($key,$val) = each %attribs){
1819         push @m, "$key = $val\n";
1820     }
1821     join "", @m;
1822 }
1823
1824 sub post_constants{
1825     my($self) = shift;
1826     unless (ref $self){
1827         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1828         $self = $ExtUtils::MakeMaker::Parent[-1];
1829     }
1830     "";
1831 }
1832
1833 sub pasthru {
1834     my($self) = shift;
1835     unless (ref $self){
1836         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1837         $self = $ExtUtils::MakeMaker::Parent[-1];
1838     }
1839     my(@m,$key);
1840
1841     my(@pasthru);
1842
1843     foreach $key (qw(INSTALLPRIVLIB INSTALLARCHLIB INSTALLBIN
1844                      INSTALLMAN1DIR INSTALLMAN3DIR LIBPERL_A
1845                      LINKTYPE)){
1846         push @pasthru, "$key=\"\$($key)\"";
1847     }
1848
1849     push @m, "\nPASTHRU = ", join ("\\\n\t", @pasthru), "\n";
1850     join "", @m;
1851 }
1852
1853 # --- Translation Sections ---
1854
1855 sub c_o {
1856     my($self) = shift;
1857     unless (ref $self){
1858         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1859         $self = $ExtUtils::MakeMaker::Parent[-1];
1860     }
1861     return '' unless $self->needs_linking();
1862     my(@m);
1863     push @m, '
1864 .c$(OBJ_EXT):
1865         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
1866
1867 .C$(OBJ_EXT):
1868         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.C
1869 ';
1870     join "", @m;
1871 }
1872
1873 sub xs_c {
1874     my($self) = shift;
1875     unless (ref $self){
1876         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1877         $self = $ExtUtils::MakeMaker::Parent[-1];
1878     }
1879     return '' unless $self->needs_linking();
1880     '
1881 .xs.c:
1882         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >$*.tc && mv $*.tc $@
1883 ';
1884 }
1885
1886 sub xs_o {      # many makes are too dumb to use xs_c then c_o
1887     my($self) = shift;
1888     unless (ref $self){
1889         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1890         $self = $ExtUtils::MakeMaker::Parent[-1];
1891     }
1892     return '' unless $self->needs_linking();
1893     '
1894 .xs$(OBJ_EXT):
1895         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $*.c
1896         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
1897 ';
1898 }
1899
1900 # --- Target Sections ---
1901
1902 sub top_targets {
1903     my($self) = shift;
1904     unless (ref $self){
1905         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1906         $self = $ExtUtils::MakeMaker::Parent[-1];
1907     }
1908     unless (ref $self){
1909         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1910         $self = $ExtUtils::MakeMaker::Parent[-1];
1911     }
1912     my(@m);
1913     push @m, '
1914 all ::  config $(INST_PM) subdirs linkext manifypods
1915
1916 subdirs :: $(MYEXTLIB)
1917
1918 '.$self->{NOOP}.'
1919
1920 config :: '.$self->{MAKEFILE}.' $(INST_LIBDIR)/.exists
1921
1922 config :: $(INST_ARCHAUTODIR)/.exists Version_check
1923
1924 config :: $(INST_AUTODIR)/.exists
1925 ';
1926
1927     push @m, $self->dir_target(qw[$(INST_AUTODIR) $(INST_LIBDIR) $(INST_ARCHAUTODIR)]);
1928
1929     if (%{$self->{MAN1PODS}}) {
1930         push @m, q[
1931 config :: $(INST_MAN1DIR)/.exists
1932
1933 ];
1934         push @m, $self->dir_target(qw[$(INST_MAN1DIR)]);
1935     }
1936     if (%{$self->{MAN3PODS}}) {
1937         push @m, q[
1938 config :: $(INST_MAN3DIR)/.exists
1939
1940 ];
1941         push @m, $self->dir_target(qw[$(INST_MAN3DIR)]);
1942     }
1943
1944     push @m, '
1945 $(O_FILES): $(H_FILES)
1946 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
1947
1948     push @m, q{
1949 help:
1950         perldoc ExtUtils::MakeMaker
1951 };
1952
1953     push @m, q{
1954 Version_check:
1955         @$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
1956                 -e 'use ExtUtils::MakeMaker qw($$Version &Version_check);' \
1957                 -e '&Version_check("$(MM_VERSION)")'
1958 };
1959
1960     join('',@m);
1961 }
1962
1963 sub linkext {
1964     my($self, %attribs) = @_;
1965     unless (ref $self){
1966         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1967         $self = $ExtUtils::MakeMaker::Parent[-1];
1968     }
1969     # LINKTYPE => static or dynamic or ''
1970     my($linktype) = defined $attribs{LINKTYPE} ?
1971       $attribs{LINKTYPE} : '$(LINKTYPE)';
1972     "
1973 linkext :: $linktype
1974 $self->{NOOP}
1975 ";
1976 }
1977
1978 sub dlsyms {
1979     my($self,%attribs) = @_;
1980     unless (ref $self){
1981         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
1982         $self = $ExtUtils::MakeMaker::Parent[-1];
1983     }
1984
1985     return '' if ($Config::Config{osname} ne 'aix');
1986
1987     my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
1988     my($vars)  = $attribs{DL_VARS} || $self->{DL_VARS} || [];
1989     my(@m);
1990
1991     push(@m,"
1992 dynamic :: $self->{BASEEXT}.exp
1993
1994 ") unless $self->{SKIPHASH}{dynamic};
1995
1996     push(@m,"
1997 static :: $self->{BASEEXT}.exp
1998
1999 ") unless $self->{SKIPHASH}{static};
2000
2001     push(@m,"
2002 $self->{BASEEXT}.exp: Makefile.PL
2003 ",'     $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e \'use ExtUtils::MakeMaker qw(&mksymlists); \\
2004         MM->new()->mksymlists({DL_FUNCS => ',
2005         %$funcs ? neatvalue($funcs) : '""',', DL_VARS => ',
2006         @$vars  ? neatvalue($vars)  : '""', ", NAME => \"$self->{NAME}\"})'
2007 ");
2008
2009     join('',@m);
2010 }
2011
2012 # --- Dynamic Loading Sections ---
2013
2014 sub dynamic {
2015     my($self) = shift;
2016     unless (ref $self){
2017         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2018         $self = $ExtUtils::MakeMaker::Parent[-1];
2019     }
2020     '
2021 # $(INST_PM) has been moved to the all: target.
2022 # It remains here for awhile to allow for old usage: "make dynamic"
2023 dynamic :: '.$self->{MAKEFILE}.' $(INST_DYNAMIC) $(INST_BOOT) $(INST_PM)
2024 '.$self->{NOOP}.'
2025 ';
2026 }
2027
2028 sub dynamic_bs {
2029     my($self, %attribs) = @_;
2030     unless (ref $self){
2031         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2032         $self = $ExtUtils::MakeMaker::Parent[-1];
2033     }
2034     return '' unless $self->needs_linking();
2035     '
2036 BOOTSTRAP = '."$self->{BASEEXT}.bs".'
2037
2038 # As Mkbootstrap might not write a file (if none is required)
2039 # we use touch to prevent make continually trying to remake it.
2040 # The DynaLoader only reads a non-empty file.
2041 $(BOOTSTRAP): '."$self->{MAKEFILE} $self->{BOOTDEP}".'
2042         @ echo "Running Mkbootstrap for $(NAME) ($(BSLOADLIBS))"
2043         @ $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" \
2044                 -e \'use ExtUtils::Mkbootstrap;\' \
2045                 -e \'Mkbootstrap("$(BASEEXT)","$(BSLOADLIBS)");\'
2046         @ $(TOUCH) $(BOOTSTRAP)
2047         $(CHMOD) 644 $@
2048         @echo $@ >> $(INST_ARCHAUTODIR)/.packlist
2049
2050 $(INST_BOOT): $(BOOTSTRAP)
2051         @ '.$self->{RM_RF}.' $(INST_BOOT)
2052         -'.$self->{CP}.' $(BOOTSTRAP) $(INST_BOOT)
2053         $(CHMOD) 644 $@
2054         @echo $@ >> $(INST_ARCHAUTODIR)/.packlist
2055 ';
2056 }
2057
2058 sub dynamic_lib {
2059     my($self, %attribs) = @_;
2060     unless (ref $self){
2061         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2062         $self = $ExtUtils::MakeMaker::Parent[-1];
2063     }
2064     return '' unless $self->needs_linking(); #might be because of a subdir
2065
2066     return '
2067 $(INST_DYNAMIC):
2068 ' unless ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB});
2069
2070     my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
2071     my($armaybe) = $attribs{ARMAYBE} || $self->{ARMAYBE} || ":";
2072     my($ldfrom) = '$(LDFROM)';
2073     my($osname) = $Config::Config{osname};
2074     $armaybe = 'ar' if ($osname eq 'dec_osf' and $armaybe eq ':');
2075     my(@m);
2076     push(@m,'
2077 # This section creates the dynamically loadable $(INST_DYNAMIC)
2078 # from $(OBJECT) and possibly $(MYEXTLIB).
2079 ARMAYBE = '.$armaybe.'
2080 OTHERLDFLAGS = '.$otherldflags.'
2081
2082 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)/.exists $(EXPORT_LIST) $(PERL_ARCHIVE)
2083 ');
2084     if ($armaybe ne ':'){
2085         $ldfrom = 'tmp$(LIB_EXT)';
2086         push(@m,'       $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
2087         push(@m,'       $(RANLIB) '."$ldfrom\n");
2088     }
2089     $ldfrom = "-all $ldfrom -none" if ($osname eq 'dec_osf');
2090     push(@m,'   LD_RUN_PATH="$(LD_RUN_PATH)" $(LD) -o $@ $(LDDLFLAGS) '.$ldfrom.
2091                 ' $(OTHERLDFLAGS) $(MYEXTLIB) $(LDLOADLIBS) $(EXPORT_LIST) $(PERL_ARCHIVE)');
2092     push @m, '
2093         $(CHMOD) 755 $@
2094         @echo $@ >> $(INST_ARCHAUTODIR)/.packlist
2095 ';
2096
2097     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
2098     join('',@m);
2099 }
2100
2101 # --- Static Loading Sections ---
2102
2103 sub static {
2104     my($self) = shift;
2105     unless (ref $self){
2106         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2107         $self = $ExtUtils::MakeMaker::Parent[-1];
2108     }
2109     '
2110 # $(INST_PM) has been moved to the all: target.
2111 # It remains here for awhile to allow for old usage: "make static"
2112 static :: '.$self->{MAKEFILE}.' $(INST_STATIC) $(INST_PM)
2113 '.$self->{NOOP}.'
2114 ';
2115 }
2116
2117 sub static_lib {
2118     my($self) = @_;
2119     unless (ref $self){
2120         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2121         $self = $ExtUtils::MakeMaker::Parent[-1];
2122     }
2123     return '' unless $self->needs_linking(); #might be because of a subdir
2124
2125     return '
2126 $(INST_DYNAMIC):
2127 ' unless ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB});
2128
2129     my(@m);
2130     push(@m, <<'END');
2131 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)/.exists
2132 END
2133     # If this extension has it's own library (eg SDBM_File)
2134     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
2135     push(@m, "  $self->{CP} \$(MYEXTLIB) \$\@\n") if $self->{MYEXTLIB};
2136
2137     push(@m, <<'END');
2138         $(AR) cr $@ $(OBJECT) && $(RANLIB) $@
2139         @echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
2140         $(CHMOD) 755 $@
2141         @echo $@ >> $(INST_ARCHAUTODIR)/.packlist
2142 END
2143
2144 # Old mechanism - still available:
2145
2146     push(@m, <<'END') if $self->{PERL_SRC};
2147         @ echo "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
2148 END
2149
2150     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
2151     join('', "\n",@m);
2152 }
2153
2154 sub installpm {
2155     my($self, %attribs) = @_;
2156     unless (ref $self){
2157         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2158         $self = $ExtUtils::MakeMaker::Parent[-1];
2159     }
2160     # By default .pm files are split into the architecture independent
2161     # library. This is a good thing. If a specific module requires that
2162     # it's .pm files are split into the architecture specific library
2163     # then it should use: installpm => {SPLITLIB=>'$(INST_ARCHLIB)'}
2164     # Note that installperl currently interferes with this (Config.pm)
2165     # User can disable split by saying: installpm => {SPLITLIB=>''}
2166     my($splitlib) = '$(INST_LIB)'; # NOT arch specific by default
2167     $splitlib = $attribs{SPLITLIB} if exists $attribs{SPLITLIB};
2168     my(@m, $dist);
2169     push @m, "inst_pm :: \$(INST_PM)\n\n";
2170     foreach $dist (sort keys %{$self->{PM}}){
2171         my($inst) = $self->{PM}->{$dist};
2172         push(@m, "\n# installpm: $dist => $inst, splitlib=$splitlib\n");
2173         push(@m, $self->installpm_x($dist, $inst, $splitlib));
2174         push(@m, "\n");
2175     }
2176     join('', @m);
2177 }
2178
2179 sub installpm_x { # called by installpm per file
2180     my($self, $dist, $inst, $splitlib) = @_;
2181     unless (ref $self){
2182         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2183         $self = $ExtUtils::MakeMaker::Parent[-1];
2184     }
2185     warn "Warning: Most probably 'make' will have problems processing this file: $inst\n"
2186         if $inst =~ m![:#]!;
2187     my($instdir) = $inst =~ m|(.*)/|;
2188     my(@m);
2189     push(@m,"
2190 $inst: $dist $self->{MAKEFILE} $instdir/.exists
2191 ".'     @ '.$self->{RM_F}.' $@
2192         $(UMASK_NULL) && '."$self->{CP} $dist".' $@
2193         @ echo $@ >> $(INST_ARCHAUTODIR)/.packlist
2194 ');
2195     push(@m, "\t\@\$(AUTOSPLITFILE) \$@ $splitlib/auto\n")
2196         if ($splitlib and $inst =~ m/\.pm$/);
2197
2198     push @m, $self->dir_target($instdir);
2199     join('', @m);
2200 }
2201
2202 sub manifypods {
2203     my($self, %attribs) = @_;
2204     unless (ref $self){
2205         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2206         $self = $ExtUtils::MakeMaker::Parent[-1];
2207     }
2208     return "\nmanifypods :\n" unless %{$self->{MAN3PODS}};
2209     my($dist);
2210     my($pod2man_exe);
2211     if (defined $self->{PERL_SRC}) {
2212         $pod2man_exe = "$self->{PERL_SRC}/pod/pod2man";
2213     } else {
2214         $pod2man_exe = "$Config{bin}/pod2man";
2215     }
2216     unless ($self->maybe_command($pod2man_exe)) {
2217         # No pod2man but some MAN3PODS to be installed
2218         print <<END;
2219
2220 Warning: I could not locate your pod2man program. Please make sure,
2221          your pod2man program is in your PATH before you execute 'make'
2222
2223 END
2224         $pod2man_exe = "-S pod2man";
2225     }
2226     my(@m);
2227     push @m,
2228 qq[POD2MAN_EXE = $pod2man_exe\n],
2229 q[POD2MAN = $(PERL) -we '%m=@ARGV;for (keys %m){' \\
2230 -e 'next if -e $$m{$$_} && -M $$m{$$_} < -M $$_ && -M $$m{$$_} < -M "].$self->{MAKEFILE}.q[";' \\
2231 -e 'print "Installing $$m{$$_}\n";' \\
2232 -e 'system("$(PERL) $(POD2MAN_EXE) $$_>$$m{$$_}")==0 or warn "Couldn\\047t install $$m{$$_}\n";' \\
2233 -e 'chmod 0644, $$m{$$_} or warn "chmod 644 $$m{$$_}: $$!\n";}'
2234 ];
2235     push @m, "\nmanifypods :";
2236
2237     push(@m,"\n");
2238     if (%{$self->{MAN1PODS}} || %{$self->{MAN3PODS}}) {
2239         push @m, "\t\@\$(POD2MAN) \\\n\t";
2240         push @m, join " \\\n\t", %{$self->{MAN1PODS}}, %{$self->{MAN3PODS}};
2241     }
2242     join('', @m);
2243 }
2244
2245 sub processPL {
2246     my($self) = shift;
2247     unless (ref $self){
2248         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2249         $self = $ExtUtils::MakeMaker::Parent[-1];
2250     }
2251     return "" unless $self->{PL_FILES};
2252     my(@m, $plfile);
2253     foreach $plfile (sort keys %{$self->{PL_FILES}}) {
2254         push @m, "
2255 all :: $self->{PL_FILES}->{$plfile}
2256
2257 $self->{PL_FILES}->{$plfile} :: $plfile
2258         \$(PERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) $plfile
2259 ";
2260     }
2261     join "", @m;
2262 }
2263
2264 sub installbin {
2265     my($self) = shift;
2266     return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
2267     my(@m, $from, $to, %fromto, @to);
2268     push @m, $self->dir_target(qw[$(INST_EXE)]);
2269     for $from (@{$self->{EXE_FILES}}) {
2270         my($path)= '$(INST_EXE)/' . basename($from);
2271         local($_) = $path; # for backwards compatibility
2272         $to = $self->exescan($path);
2273         print "exescan($from) => '$to'\n" if ($ExtUtils::MakeMaker::Verbose >=2);
2274         $fromto{$from}=$to;
2275     }
2276     @to   = values %fromto;
2277     push(@m, "
2278 EXE_FILES = @{$self->{EXE_FILES}}
2279
2280 all :: @to
2281
2282 realclean ::
2283         $self->{RM_F} @to
2284 ");
2285
2286     while (($from,$to) = each %fromto) {
2287         my $todir = dirname($to);
2288         push @m, "
2289 $to: $from $self->{MAKEFILE} $todir/.exists
2290         $self->{CP} $from $to
2291 ";
2292     }
2293     join "", @m;
2294 }
2295
2296 sub exescan {
2297     my($self,$path) = @_;
2298     $path;
2299 }
2300 # --- Sub-directory Sections ---
2301
2302 sub subdirs {
2303     my($self) = shift;
2304     unless (ref $self){
2305         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2306         $self = $ExtUtils::MakeMaker::Parent[-1];
2307     }
2308     my(@m,$dir);
2309     # This method provides a mechanism to automatically deal with
2310     # subdirectories containing further Makefile.PL scripts.
2311     # It calls the subdir_x() method for each subdirectory.
2312     foreach $dir (@{$self->{DIR}}){
2313         push(@m, $self->subdir_x($dir));
2314 ####    print "Including $dir subdirectory\n";
2315     }
2316     if (@m){
2317         unshift(@m, "
2318 # The default clean, realclean and test targets in this Makefile
2319 # have automatically been given entries for each subdir.
2320
2321 ");
2322     } else {
2323         push(@m, "\n# none")
2324     }
2325     join('',@m);
2326 }
2327
2328 sub runsubdirpl{        # Experimental! See subdir_x section
2329     my($self,$subdir) = @_;
2330     unless (ref $self){
2331         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2332         $self = $ExtUtils::MakeMaker::Parent[-1];
2333     }
2334     chdir($subdir) or die "chdir($subdir): $!";
2335     package main;
2336     require "Makefile.PL";
2337 }
2338
2339 sub subdir_x {
2340     my($self, $subdir) = @_;
2341     unless (ref $self){
2342         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2343         $self = $ExtUtils::MakeMaker::Parent[-1];
2344     }
2345     my(@m);
2346     qq{
2347
2348 subdirs ::
2349         \@-cd $subdir && \$(MAKE) all \$(PASTHRU)
2350
2351 };
2352 }
2353
2354 # --- Cleanup and Distribution Sections ---
2355
2356 sub clean {
2357     my($self, %attribs) = @_;
2358     unless (ref $self){
2359         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2360         $self = $ExtUtils::MakeMaker::Parent[-1];
2361     }
2362     my(@m,$dir);
2363     push(@m, '
2364 # Delete temporary files but do not touch installed files. We don\'t delete
2365 # the Makefile here so a later make realclean still has a makefile to use.
2366
2367 clean ::
2368 ');
2369     # clean subdirectories first
2370     for $dir (@{$self->{DIR}}) {
2371         push @m, "\t-cd $dir && test -f $self->{MAKEFILE} && \$(MAKE) clean\n";
2372     }
2373
2374     my(@otherfiles) = values %{$self->{XS}}; # .c files from *.xs files
2375     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
2376     push(@otherfiles, qw[./blib Makeaperlfile $(INST_ARCHAUTODIR)/extralibs.all
2377                          perlmain.c mon.out core so_locations
2378                          *~ */*~ */*/*~
2379                          *$(OBJ_EXT) *$(LIB_EXT)
2380                          perl.exe $(BOOTSTRAP) $(BASEEXT).bso $(BASEEXT).def $(BASEEXT).exp
2381                         ]);
2382     push @m, "\t-$self->{RM_RF} @otherfiles\n";
2383     # See realclean and ext/utils/make_ext for usage of Makefile.old
2384     push(@m,
2385          "\t-$self->{MV} $self->{MAKEFILE} $self->{MAKEFILE}.old 2>/dev/null\n");
2386     push(@m,
2387          "\t$attribs{POSTOP}\n")   if $attribs{POSTOP};
2388     join("", @m);
2389 }
2390
2391 sub realclean {
2392     my($self, %attribs) = @_;
2393     unless (ref $self){
2394         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2395         $self = $ExtUtils::MakeMaker::Parent[-1];
2396     }
2397     my(@m);
2398     push(@m,'
2399 # Delete temporary files (via clean) and also delete installed files
2400 realclean purge ::  clean
2401 ');
2402     # realclean subdirectories first (already cleaned)
2403     my $sub = "\t-cd %s && test -f %s && \$(MAKE) %s realclean\n";
2404     foreach(@{$self->{DIR}}){
2405         push(@m, sprintf($sub,$_,"$self->{MAKEFILE}.old","-f $self->{MAKEFILE}.old"));
2406         push(@m, sprintf($sub,$_,"$self->{MAKEFILE}",''));
2407     }
2408     push(@m, "  $self->{RM_RF} \$(INST_AUTODIR) \$(INST_ARCHAUTODIR)\n");
2409     push(@m, "  $self->{RM_F} \$(INST_DYNAMIC) \$(INST_BOOT)\n");
2410     push(@m, "  $self->{RM_F} \$(INST_STATIC) \$(INST_PM)\n");
2411     my(@otherfiles) = ($self->{MAKEFILE},
2412                        "$self->{MAKEFILE}.old"); # Makefiles last
2413     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
2414     push(@m, "  $self->{RM_RF} @otherfiles\n") if @otherfiles;
2415     push(@m, "  $attribs{POSTOP}\n")       if $attribs{POSTOP};
2416     join("", @m);
2417 }
2418
2419 sub dist_basics {
2420     my($self) = shift;
2421     unless (ref $self){
2422         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2423         $self = $ExtUtils::MakeMaker::Parent[-1];
2424     }
2425     my @m;
2426     push @m, q{
2427 distclean :: realclean distcheck
2428 };
2429
2430     push @m, q{
2431 distcheck :
2432         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e 'use ExtUtils::Manifest "&fullcheck";' \\
2433                 -e 'fullcheck();'
2434 };
2435
2436     push @m, q{
2437 skipcheck :
2438         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e 'use ExtUtils::Manifest "&skipcheck";' \\
2439                 -e 'skipcheck();'
2440 };
2441
2442     push @m, q{
2443 manifest :
2444         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e 'use ExtUtils::Manifest "&mkmanifest";' \\
2445                 -e 'mkmanifest();'
2446 };
2447     join "", @m;
2448 }
2449
2450 sub dist_core {
2451     my($self) = shift;
2452     unless (ref $self){
2453         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2454         $self = $ExtUtils::MakeMaker::Parent[-1];
2455     }
2456     my @m;
2457     push @m, q{
2458 dist : $(DIST_DEFAULT)
2459
2460 tardist : $(DISTVNAME).tar.$(SUFFIX)
2461
2462 $(DISTVNAME).tar.$(SUFFIX) : distdir
2463         $(PREOP)
2464         $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
2465         $(RM_RF) $(DISTVNAME)
2466         $(COMPRESS) $(DISTVNAME).tar
2467         $(POSTOP)
2468
2469 uutardist : $(DISTVNAME).tar.$(SUFFIX)
2470         uuencode $(DISTVNAME).tar.$(SUFFIX) \\
2471                 $(DISTVNAME).tar.$(SUFFIX) > \\
2472                 $(DISTVNAME).tar.$(SUFFIX).uu
2473
2474 shdist : distdir
2475         $(PREOP)
2476         $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar
2477         $(RM_RF) $(DISTVNAME)
2478         $(POSTOP)
2479 };
2480     join "", @m;
2481 }
2482
2483 sub dist_dir {
2484     my($self) = shift;
2485     unless (ref $self){
2486         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2487         $self = $ExtUtils::MakeMaker::Parent[-1];
2488     }
2489     my @m;
2490     push @m, q{
2491 distdir :
2492         $(RM_RF) $(DISTVNAME)
2493         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e 'use ExtUtils::Manifest "/mani/";' \\
2494                 -e 'manicopy(maniread(),"$(DISTVNAME)", "$(DIST_CP)");'
2495 };
2496     join "", @m;
2497 }
2498
2499 sub dist_test {
2500     my($self) = shift;
2501     unless (ref $self){
2502         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2503         $self = $ExtUtils::MakeMaker::Parent[-1];
2504     }
2505     my @m;
2506     push @m, q{
2507 disttest : distdir
2508         cd $(DISTVNAME) && $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) Makefile.PL
2509         cd $(DISTVNAME) && $(MAKE)
2510         cd $(DISTVNAME) && $(MAKE) test
2511 };
2512     join "", @m;
2513 }
2514
2515 sub dist_ci {
2516     my($self) = shift;
2517     unless (ref $self){
2518         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2519         $self = $ExtUtils::MakeMaker::Parent[-1];
2520     }
2521     my @m;
2522     push @m, q{
2523 ci :
2524         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e 'use ExtUtils::Manifest "&maniread";' \\
2525                 -e '@all = keys %{ maniread() };' \\
2526                 -e 'print("Executing $(CI) @all\n"); system("$(CI) @all");' \\
2527                 -e 'print("Executing $(RCS_LABEL) ...\n"); system("$(RCS_LABEL) @all");'
2528 };
2529     join "", @m;
2530 }
2531
2532 sub install {
2533     my($self, %attribs) = @_;
2534     unless (ref $self){
2535         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2536         $self = $ExtUtils::MakeMaker::Parent[-1];
2537     }
2538     my(@m);
2539     push @m, q{
2540 doc_install ::
2541         @ echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
2542         @ $(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB)  \\
2543                 -e "use ExtUtils::MakeMaker; MY->new({})->writedoc('Module', '$(NAME)', \\
2544                 'LINKTYPE=$(LINKTYPE)', 'VERSION=$(VERSION)', \\
2545                 'EXE_FILES=$(EXE_FILES)')" >> $(INSTALLARCHLIB)/perllocal.pod
2546 };
2547
2548     push(@m, "
2549 install :: pure_install doc_install
2550
2551 pure_install ::
2552 ");
2553     # install subdirectories first
2554     push(@m, map("\tcd $_ && test -f $self->{MAKEFILE} && \$(MAKE) install\n",
2555                  @{$self->{DIR}}));
2556
2557     push(@m, "\t\@\$(PERL) \"-I\$(PERL_ARCHLIB)\" \"-I\$(PERL_LIB)\" -e 'require File::Path;' \\
2558         -e '\$\$message = q[ You do not have permissions to install into];' \\
2559         -e 'File::Path::mkpath(\@ARGV);' \\
2560         -e 'foreach (\@ARGV){ die qq{ \$\$message \$\$_\\n} unless -w \$\$_}' \\
2561             \$(INSTALLPRIVLIB) \$(INSTALLARCHLIB)
2562         \$(MAKE) INST_LIB=\$(INSTALLPRIVLIB) INST_ARCHLIB=\$(INSTALLARCHLIB) INST_EXE=\$(INSTALLBIN) INST_MAN1DIR=\$(INSTALLMAN1DIR) INST_MAN3DIR=\$(INSTALLMAN3DIR) all
2563         \@\$(PERL) -i.bak -lne 'print unless \$\$seen{ \$\$_ }++' \$(INSTALLARCHLIB)/auto/\$(FULLEXT)/.packlist
2564 ");
2565
2566     push @m, '
2567 #### UNINSTALL IS STILL EXPERIMENTAL ####
2568 uninstall ::
2569 ';
2570
2571     push(@m, map("\tcd $_ && test -f $self->{MAKEFILE} && \$(MAKE) uninstall\n",
2572                  @{$self->{DIR}}));
2573     push @m, "\t".'$(RM_RF) `cat $(INSTALLARCHLIB)/auto/$(FULLEXT)/.packlist`
2574 ';
2575
2576     join("",@m);
2577 }
2578
2579
2580 sub force {
2581     my($self) = shift;
2582     unless (ref $self){
2583         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2584         $self = $ExtUtils::MakeMaker::Parent[-1];
2585     }
2586     '# Phony target to force checking subdirectories.
2587 FORCE:
2588 ';
2589 }
2590
2591
2592 sub perldepend {
2593     my($self) = shift;
2594     unless (ref $self){
2595         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2596         $self = $ExtUtils::MakeMaker::Parent[-1];
2597     }
2598     my(@m);
2599     push(@m,'
2600 PERL_HDRS = $(PERL_INC)/EXTERN.h $(PERL_INC)/INTERN.h \
2601     $(PERL_INC)/XSUB.h  $(PERL_INC)/av.h        $(PERL_INC)/cop.h \
2602     $(PERL_INC)/cv.h    $(PERL_INC)/dosish.h    $(PERL_INC)/embed.h \
2603     $(PERL_INC)/form.h  $(PERL_INC)/gv.h        $(PERL_INC)/handy.h \
2604     $(PERL_INC)/hv.h    $(PERL_INC)/keywords.h  $(PERL_INC)/mg.h \
2605     $(PERL_INC)/op.h    $(PERL_INC)/opcode.h    $(PERL_INC)/patchlevel.h \
2606     $(PERL_INC)/perl.h  $(PERL_INC)/perly.h     $(PERL_INC)/pp.h \
2607     $(PERL_INC)/proto.h $(PERL_INC)/regcomp.h   $(PERL_INC)/regexp.h \
2608     $(PERL_INC)/scope.h $(PERL_INC)/sv.h        $(PERL_INC)/unixish.h \
2609     $(PERL_INC)/util.h  $(PERL_INC)/config.h
2610
2611 ');
2612
2613     push @m, '
2614 $(OBJECT) : $(PERL_HDRS)
2615 ' if $self->{OBJECT};
2616
2617     push(@m,'
2618 # Check for unpropogated config.sh changes. Should never happen.
2619 # We do NOT just update config.h because that is not sufficient.
2620 # An out of date config.h is not fatal but complains loudly!
2621 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
2622         -@echo "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
2623
2624 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
2625         @echo "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
2626         cd $(PERL_SRC) && $(MAKE) lib/Config.pm
2627 ') if $self->{PERL_SRC};
2628
2629     push(@m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n")
2630         if %{$self->{XS}};
2631     join("\n",@m);
2632 }
2633
2634 sub makefile {
2635     my($self) = shift;
2636     unless (ref $self){
2637         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2638         $self = $ExtUtils::MakeMaker::Parent[-1];
2639     }
2640     my @m;
2641     # We do not know what target was originally specified so we
2642     # must force a manual rerun to be sure. But as it should only
2643     # happen very rarely it is not a significant problem.
2644     push @m, '
2645 $(OBJECT) : $(FIRST_MAKEFILE)
2646 ' if $self->{OBJECT};
2647
2648     push @m, '
2649 # We take a very conservative approach here, but it\'s worth it.
2650 # We move Makefile to Makefile.old here to avoid gnu make looping.
2651 '.$self->{MAKEFILE}.' : Makefile.PL $(CONFIGDEP)
2652         @echo "Makefile out-of-date with respect to $?"
2653         @echo "Cleaning current config before rebuilding Makefile..."
2654         -@mv '."$self->{MAKEFILE} $self->{MAKEFILE}.old".'
2655         -$(MAKE) -f '.$self->{MAKEFILE}.'.old clean >/dev/null 2>&1 || true
2656         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" Makefile.PL '."@ARGV".'
2657         @echo ">>> Your Makefile has been rebuilt. <<<"
2658         @echo ">>> Please rerun the make command.  <<<"; false
2659 ';
2660
2661     join "", @m;
2662 }
2663
2664 sub staticmake {
2665     my($self, %attribs) = @_;
2666     unless (ref $self){
2667         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2668         $self = $ExtUtils::MakeMaker::Parent[-1];
2669     }
2670     my(@static);
2671
2672     my(%searchdirs)=($self->{PERL_ARCHLIB} => 1,  $self->{INST_ARCHLIB} => 1);
2673     my(@searchdirs)=keys %searchdirs;
2674
2675     # And as it's not yet built, we add the current extension
2676     # but only if it has some C code (or XS code, which implies C code)
2677     if (@{$self->{C}}) {
2678         @static="$self->{INST_ARCHLIB}/auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}";
2679     }
2680
2681     # Either we determine now, which libraries we will produce in the
2682     # subdirectories or we do it at runtime of the make.
2683
2684     # We could ask all subdir objects, but I cannot imagine, why it
2685     # would be necessary.
2686
2687     # Instead we determine all libraries for the new perl at
2688     # runtime.
2689     my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
2690
2691     $self->makeaperl(MAKE       => $self->{MAKEFILE},
2692                      DIRS       => \@searchdirs,
2693                      STAT       => \@static,
2694                      INCL       => \@perlinc,
2695                      TARGET     => $self->{MAP_TARGET},
2696                      TMP        => "",
2697                      LIBPERL    => $self->{LIBPERL_A}
2698                     );
2699 }
2700
2701 # --- Test and Installation Sections ---
2702
2703 sub test {
2704     my($self, %attribs) = @_;
2705     unless (ref $self){
2706         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2707         $self = $ExtUtils::MakeMaker::Parent[-1];
2708     }
2709     my($tests) = $attribs{TESTS} || (-d "t" ? "t/*.t" : "");
2710     my(@m);
2711     push(@m,"
2712 TEST_VERBOSE=0
2713 TEST_TYPE=test_\$(LINKTYPE)
2714
2715 test :: \$(TEST_TYPE)
2716 ");
2717     push(@m, map("\t\@cd $_ && test -f $self->{MAKEFILE} && \$(MAKE) test \$(PASTHRU)\n",
2718                  @{$self->{DIR}}));
2719     push(@m, "\t\@echo 'No tests defined for \$(NAME) extension.'\n")
2720         unless $tests or -f "test.pl" or @{$self->{DIR}};
2721     push(@m, "\n");
2722
2723     push(@m, "test_dynamic :: all\n");
2724     push(@m, $self->test_via_harness('$(FULLPERL)', $tests)) if $tests;
2725     push(@m, $self->test_via_script('$(FULLPERL)', 'test.pl')) if -f "test.pl";
2726     push(@m, "\n");
2727
2728     # Occasionally we may face this degenerated target:
2729     push @m, "test_ : test_dynamic\n\n";
2730
2731     if ($self->needs_linking()) {
2732         push(@m, "test_static :: all \$(MAP_TARGET)\n");
2733         push(@m, $self->test_via_harness('./$(MAP_TARGET)', $tests)) if $tests;
2734         push(@m, $self->test_via_script('./$(MAP_TARGET)', 'test.pl')) if -f "test.pl";
2735         push(@m, "\n");
2736     } else {
2737         push @m, "test_static :: test_dynamic\n";
2738     }
2739     join("", @m);
2740 }
2741
2742 sub test_via_harness {
2743     my($self, $perl, $tests) = @_;
2744     unless (ref $self){
2745         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2746         $self = $ExtUtils::MakeMaker::Parent[-1];
2747     }
2748     "\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";
2749 }
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     "\tPERL_DL_NONLAZY=1 $perl".' -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) test.pl
2758 ';
2759 }
2760
2761
2762 sub postamble {
2763     my($self) = shift;
2764     unless (ref $self){
2765         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2766         $self = $ExtUtils::MakeMaker::Parent[-1];
2767     }
2768     "";
2769 }
2770
2771 sub makeaperl {
2772     my($self, %attribs) = @_;
2773     unless (ref $self){
2774         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2775         $self = $ExtUtils::MakeMaker::Parent[-1];
2776     }
2777     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
2778         @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
2779     my(@m);
2780     push @m, "
2781 # --- MakeMaker makeaperl section ---
2782 MAP_TARGET    = $target
2783 FULLPERL      = $self->{FULLPERL}
2784 ";
2785     return join '', @m if $self->{PARENT};
2786
2787     my($dir) = join ":", @{$self->{DIR}};
2788
2789     unless ($self->{MAKEAPERL}) {
2790         push @m, q{
2791 $(MAP_TARGET) :: $(MAKE_APERL_FILE)
2792         $(MAKE) -f Makefile.aperl static $@
2793
2794 $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE)
2795         @ echo Writing \"Makefile.aperl\" for this $(MAP_TARGET)
2796         @ $(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
2797                 Makefile.PL DIR=}, $dir, q{ \
2798                 MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
2799                 MAKEAPERL=1 NORECURS=1};
2800
2801         push @m, map( " \\\n\t\t$_", @ARGV );
2802         push @m, "\n";
2803
2804         return join '', @m;
2805     }
2806
2807
2808
2809     my($cccmd, $linkcmd, $lperl);
2810
2811
2812     $cccmd = $self->const_cccmd($libperl);
2813     $cccmd =~ s/^CCCMD\s*=\s*//;
2814     $cccmd =~ s/\$\(INC\)/ -I$self->{PERL_INC} /;
2815     $cccmd .= " $Config::Config{cccdlflags}" if ($Config::Config{d_shrplib});
2816     $cccmd =~ s/\n/ /g; # yes I've seen "\n", don't ask me where it came from. A.K.
2817     $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
2818
2819     # The front matter of the linkcommand...
2820     $linkcmd = join ' ', "\$(CC)",
2821             grep($_, @Config{qw(large split ldflags ccdlflags)});
2822     $linkcmd =~ s/\s+/ /g;
2823
2824     # Which *.a files could we make use of...
2825     local(%static);
2826     File::Find::find(sub {
2827         return unless m/\Q$self->{LIB_EXT}$/;
2828         return if m/^libperl/;
2829         # don't include the installed version of this extension. I
2830         # leave this line here, although it is not necessary anymore:
2831         # I patched minimod.PL instead, so that Miniperl.pm won't
2832         # enclude duplicates
2833
2834         # Once the patch to minimod.PL is in the distribution, I can
2835         # drop it
2836         return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}$:;
2837         $static{fastcwd() . "/" . $_}++;
2838     }, grep( -d $_, @{$searchdirs || []}) );
2839
2840     # We trust that what has been handed in as argument, will be buildable
2841     $static = [] unless $static;
2842     @static{@{$static}} = (1) x @{$static};
2843
2844     $extra = [] unless $extra && ref $extra eq 'ARRAY';
2845     for (sort keys %static) {
2846         next unless /\Q$self->{LIB_EXT}$/;
2847         $_ = dirname($_) . "/extralibs.ld";
2848         push @$extra, $_;
2849     }
2850
2851     grep(s/^/-I/, @{$perlinc || []});
2852
2853     $target = "perl" unless $target;
2854     $tmp = "." unless $tmp;
2855
2856 # MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
2857 # regenerate the Makefiles, MAP_STATIC and the dependencies for
2858 # extralibs.all are computed correctly
2859     push @m, "
2860 MAP_LINKCMD   = $linkcmd
2861 MAP_PERLINC   = @{$perlinc || []}
2862 MAP_STATIC    = ",
2863 join(" \\\n\t", reverse sort keys %static), "
2864
2865 MAP_PRELIBS   = $Config::Config{libs} $Config::Config{cryptlib}
2866 ";
2867
2868     if (defined $libperl) {
2869         ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
2870     }
2871     unless ($libperl && -f $lperl) { # Could quite follow your idea her, Ilya
2872         my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
2873         $libperl ||= "libperl$self->{LIB_EXT}";
2874         $libperl   = "$dir/$libperl";
2875         $lperl   ||= "libperl$self->{LIB_EXT}";
2876         $lperl     = "$dir/$lperl";
2877         print STDOUT "Warning: $libperl not found
2878     If you're going to build a static perl binary, make sure perl is installed
2879     otherwise ignore this warning\n"
2880                 unless (-f $lperl || defined($self->{PERL_SRC}));
2881     }
2882
2883     push @m, "
2884 MAP_LIBPERL = $libperl
2885 ";
2886
2887     push @m, "
2888 \$(INST_ARCHAUTODIR)/extralibs.all: \$(INST_ARCHAUTODIR)/.exists ".join(" \\\n\t", @$extra)."
2889         \@ $self->{RM_F} \$\@
2890         \@ \$(TOUCH) \$\@
2891 ";
2892
2893     my $catfile;
2894     foreach $catfile (@$extra){
2895         push @m, "\tcat $catfile >> \$\@\n";
2896     }
2897
2898     push @m, "
2899 \$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all
2900         \$(MAP_LINKCMD) -o \$\@ $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS)
2901         @ echo 'To install the new \"\$(MAP_TARGET)\" binary, call'
2902         @ echo '    make -f $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
2903         @ echo 'To remove the intermediate files say'
2904         @ echo '    make -f $makefilename map_clean'
2905
2906 $tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c
2907 ";
2908     push @m, "\tcd $tmp && $cccmd -I\$(PERL_INC) perlmain.c\n";
2909
2910     push @m, qq{
2911 $tmp/perlmain.c: $makefilename}, q{
2912         @ echo Writing $@
2913         @ $(PERL) $(MAP_PERLINC) -e 'use ExtUtils::Miniperl; \\
2914                 writemain(grep s#.*/auto/##, qw|$(MAP_STATIC)|)' > $@.tmp && mv $@.tmp $@
2915
2916 };
2917
2918 # We write EXTRA outside the perl program to have it eval'd by the shell
2919     push @m, q{
2920 doc_inst_perl:
2921         @ echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
2922         @ $(FULLPERL) -e 'use ExtUtils::MakeMaker; MY->new->writedoc("Perl binary",' \\
2923                 -e '"$(MAP_TARGET)", "MAP_STATIC=$(MAP_STATIC)",' \\
2924                 -e '"MAP_EXTRA=@ARGV", "MAP_LIBPERL=$(MAP_LIBPERL)")' \\
2925                 -- `cat $(INST_ARCHAUTODIR)/extralibs.all` >> $(INSTALLARCHLIB)/perllocal.pod
2926 };
2927
2928     push @m, qq{
2929 inst_perl: pure_inst_perl doc_inst_perl
2930
2931 pure_inst_perl: \$(MAP_TARGET)
2932         $self->{CP} \$(MAP_TARGET) \$(INSTALLBIN)/\$(MAP_TARGET)
2933
2934 clean :: map_clean
2935
2936 map_clean :
2937         $self->{RM_F} $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
2938 };
2939
2940     join '', @m;
2941 }
2942
2943 sub extliblist {
2944     my($self,$libs) = @_;
2945     unless (ref $self){
2946         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2947         $self = $ExtUtils::MakeMaker::Parent[-1];
2948     }
2949     require ExtUtils::Liblist;
2950     ExtUtils::Liblist::ext($libs, $ExtUtils::MakeMaker::Verbose);
2951 }
2952
2953 sub mksymlists {
2954     my($self) = shift;
2955     unless (ref $self){
2956         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2957         $self = $ExtUtils::MakeMaker::Parent[-1];
2958     }
2959     my($pkg);
2960
2961     # only AIX requires a symbol list at this point
2962     # (so does VMS, but that's handled by the MM_VMS package)
2963     return '' unless $Config::Config{osname} eq 'aix';
2964
2965     $self->init_main(@ARGV) unless defined $self->{BASEEXT};
2966     if (! $self->{DL_FUNCS}) {
2967         my($bootfunc);
2968         ($bootfunc = $self->{NAME}) =~ s/\W/_/g;
2969         $self->{DL_FUNCS} = {$self->{BASEEXT} => ["boot_$bootfunc"]};
2970     }
2971     rename "$self->{BASEEXT}.exp", "$self->{BASEEXT}.exp_old";
2972
2973     open(EXP,">$self->{BASEEXT}.exp") or die $!;
2974     print EXP join("\n",@{$self->{DL_VARS}}, "\n") if $self->{DL_VARS};
2975     foreach $pkg (keys %{$self->{DL_FUNCS}}) {
2976         (my($prefix) = $pkg) =~ s/\W/_/g;
2977         my $func;
2978         foreach $func (@{$self->{DL_FUNCS}->{$pkg}}) {
2979             $func = "XS_${prefix}_$func" unless $func =~ /^boot_/;
2980             print EXP "$func\n";
2981         }
2982     }
2983     close EXP;
2984 }
2985
2986 # --- Make-Directories section (internal method) ---
2987 # dir_target(@array) returns a Makefile entry for the file .exists in each
2988 # named directory. Returns nothing, if the entry has already been processed.
2989 # We're helpless though, if the same directory comes as $(FOO) _and_ as "bar".
2990 # Both of them get an entry, that's why we use "::". I chose '$(PERL)' as the
2991 # prerequisite, because there has to be one, something that doesn't change
2992 # too often :)
2993
2994 sub dir_target {
2995     my($self,@dirs) = @_;
2996     unless (ref $self){
2997         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
2998         $self = $ExtUtils::MakeMaker::Parent[-1];
2999     }
3000     my(@m,$dir);
3001     foreach $dir (@dirs) {
3002         next if $self->{DIR_TARGET}{$self}{$dir}++;
3003         push @m, "
3004 $dir/.exists :: \$(PERL)
3005         \@ \$(MKPATH) $dir
3006         \@ \$(TOUCH) $dir/.exists
3007         \@-\$(CHMOD) 755 $dir
3008 ";
3009     }
3010     join "", @m;
3011 }
3012
3013 # --- Output postprocessing section ---
3014 # nicetext is included to make VMS support easier
3015 sub nicetext { # Just return the input - no action needed
3016     my($self,$text) = @_;
3017     unless (ref $self){
3018         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
3019         $self = $ExtUtils::MakeMaker::Parent[-1];
3020     }
3021     $text;
3022 }
3023
3024 sub needs_linking { # Does this module need linking? Looks into
3025                     # subdirectory objects (see also has_link_code()
3026     my($self) = shift;
3027     my($child,$caller);
3028     $caller = (caller(0))[3];
3029     unless (ref $self){
3030         ExtUtils::MakeMaker::TieAtt::warndirectuse($caller);
3031         $self = $ExtUtils::MakeMaker::Parent[-1];
3032     }
3033     Carp::confess("Needs_linking called too early") if $caller =~ /^ExtUtils::MakeMaker::/;
3034     return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
3035 #    print "DEBUG:\n";
3036 #    print Carp::longmess();
3037 #    print "EO_DEBUG\n";
3038     if ($self->has_link_code or $self->{MAKEAPERL}){
3039         $self->{NEEDS_LINKING} = 1;
3040         return 1;
3041     }
3042     foreach $child (keys %{$self->{CHILDREN}}) {
3043         if ($self->{CHILDREN}->{$child}->needs_linking) {
3044             $self->{NEEDS_LINKING} = 1;
3045             return 1;
3046         }
3047     }
3048     return $self->{NEEDS_LINKING} = 0;
3049 }
3050
3051 sub has_link_code {
3052     my($self) = shift;
3053     return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE};
3054     if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){
3055         $self->{HAS_LINK_CODE} = 1;
3056         return 1;
3057     }
3058     return $self->{HAS_LINK_CODE} = 0;
3059 }
3060
3061 # --- perllocal.pod section ---
3062 sub writedoc {
3063     my($self,$what,$name,@attribs)=@_;
3064     unless (ref $self){
3065         ExtUtils::MakeMaker::TieAtt::warndirectuse((caller(0))[3]);
3066         $self = $ExtUtils::MakeMaker::Parent[-1];
3067     }
3068     my($time);
3069     require "ctime.pl";
3070     chop($time = ctime(time));
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 sub catdir  { shift; join('/',@_); }
3077 sub catfile { shift; join('/',@_); }
3078
3079 package ExtUtils::MM_OS2;
3080
3081 #use Config;
3082 #use Cwd;
3083 #use File::Basename;
3084 require Exporter;
3085
3086 Exporter::import('ExtUtils::MakeMaker',
3087        qw( $Verbose));
3088
3089 sub dlsyms {
3090     my($self,%attribs) = @_;
3091
3092     my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
3093     my($vars)  = $attribs{DL_VARS} || $self->{DL_VARS} || [];
3094     my(@m);
3095     (my $boot = $self->{NAME}) =~ s/:/_/g;
3096
3097     if (not $self->{SKIPHASH}{'dynamic'}) {
3098         push(@m,"
3099 $self->{BASEEXT}.def: Makefile.PL"
3100           . '
3101         echo "LIBRARY ' . "'$self->{DLBASE}'" . ' INITINSTANCE TERMINSTANCE" > $@ ; \\
3102         echo "CODE LOADONCALL" >> $@ ; \\
3103         echo "DATA LOADONCALL NONSHARED MULTIPLE" >> $@ ; \\
3104         echo "EXPORTS" >> $@ ; \\
3105         echo "  ' . "boot_$boot" . '" >> $@');
3106         foreach $sym (keys %$funcs, @$vars) {
3107             push(@m, " ; \\
3108        echo \"  $sym\" >> \$@");
3109         }
3110         push(@m,"\n");
3111     }
3112
3113     join('',@m);
3114 }
3115
3116 sub replace_manpage_seperator {
3117     my($self,$man) = @_;
3118     $man =~ s,/+,.,g;
3119     $man;
3120 }
3121
3122 sub maybe_command {
3123     my($self,$file) = @_;
3124     return 1 if -x $file && ! -d _;
3125     return 1 if -x "$file.exe" && ! -d _;
3126     return;
3127 }
3128
3129 # the following keeps AutoSplit happy
3130 package ExtUtils::MakeMaker;
3131 1;
3132
3133 __END__
3134
3135 =head1 NAME
3136
3137 ExtUtils::MakeMaker - create an extension Makefile
3138
3139 =head1 SYNOPSIS
3140
3141 C<use ExtUtils::MakeMaker;>
3142
3143 C<WriteMakefile( ATTRIBUTE =E<gt> VALUE [, ...] );>
3144
3145 which is really
3146
3147 C<MM-E<gt>new(\%att)-E<gt>flush;>
3148
3149 =head1 DESCRIPTION
3150
3151 This utility is designed to write a Makefile for an extension module
3152 from a Makefile.PL. It is based on the Makefile.SH model provided by
3153 Andy Dougherty and the perl5-porters.
3154
3155 It splits the task of generating the Makefile into several subroutines
3156 that can be individually overridden.  Each subroutine returns the text
3157 it wishes to have written to the Makefile.
3158
3159 =head2 Hintsfile support
3160
3161 MakeMaker.pm uses the architecture specific information from
3162 Config.pm. In addition it evaluates architecture specific hints files
3163 in a C<hints/> directory. The hints files are expected to be named
3164 like their counterparts in C<PERL_SRC/hints>, but with an C<.pl> file
3165 name extension (eg. C<next_3_2.pl>). They are simply C<eval>ed by
3166 MakeMaker within the WriteMakefile() subroutine, and can be used to
3167 execute commands as well as to include special variables. The rules
3168 which hintsfile is chosen are the same as in Configure.
3169
3170 The hintsfile is eval()ed immediately after the arguments given to
3171 WriteMakefile are stuffed into a hash reference $self but before this
3172 reference becomes blessed. So if you want to do the equivalent to
3173 override or create an attribute you would say something like
3174
3175     $self->{LIBS} = ['-ldbm -lucb -lc'];
3176
3177 =head2 What's new in version 5 of MakeMaker
3178
3179 MakeMaker 5 is pure object oriented. This allows us to write an
3180 unlimited number of Makefiles with a single perl process. 'perl
3181 Makefile.PL' with MakeMaker 5 goes through all subdirectories
3182 immediately and evaluates any Makefile.PL found in the next level
3183 subdirectories. The benefit of this approach comes in useful for both
3184 single and multi directories extensions.
3185
3186 Multi directory extensions have an immediately visible speed
3187 advantage, because there's no startup penalty for any single
3188 subdirectory Makefile.
3189
3190 Single directory packages benefit from the much improved
3191 needs_linking() method. As the main Makefile knows everything about
3192 the subdirectories, a needs_linking() method can now query all
3193 subdirectories if there is any linking involved down in the tree. The
3194 speedup for PM-only Makefiles seems to be around 1 second on my
3195 Indy 100 MHz.
3196
3197 =head2 Incompatibilities between MakeMaker 5.00 and 4.23
3198
3199 There are no incompatibilities in the short term, as all changes are
3200 accompanied by short-term workarounds that guarantee full backwards
3201 compatibility.
3202
3203 You are likely to face a few warnings that expose deprecations which
3204 will result in incompatibilities in the long run:
3205
3206 You should not use %att directly anymore. Instead any subroutine you
3207 override in the MY package will be called by the object method, so you
3208 can access all object attributes directly via the object in $_[0].
3209
3210 You should not call the class methos MM->something anymore. Instead
3211 you should call the superclass. Something like
3212
3213     sub MY::constants {
3214         my $self = shift;
3215         $self->MM::constants();
3216     }
3217
3218 Especially the libscan() and exescan() methods should be altered
3219 towards OO programming, that means do not expect that $_ to contain
3220 the path but rather $_[1].
3221
3222 You should program with more care. Watch out for any MakeMaker
3223 variables. Do not try to alter them, somebody else might depend on
3224 them. E.g. do not overwrite the ExtUtils::MakeMaker::VERSION variable
3225 (this happens if you import it and then set it to the version number
3226 of your package), do not expect that the INST_LIB variable will be
3227 ./blib (do not 'unshift @INC, "./blib" and do not use
3228 "blib/FindBin.pm"). Do not croak in your Makefile.PL, let it fail with
3229 a warning instead.
3230
3231 Try to build several extensions simultanously to debug your
3232 Makefile.PL. You can unpack a bunch of distributed packages, so your
3233 directory looks like
3234
3235     Alias-1.00/         Net-FTP-1.01a/      Set-Scalar-0.001/
3236     ExtUtils-Peek-0.4/  Net-Ping-1.00/      SetDualVar-1.0/
3237     Filter-1.06/        NetTools-1.01a/     Storable-0.1/
3238     GD-1.00/            Religion-1.04/      Sys-Domain-1.05/
3239     MailTools-1.03/     SNMP-1.5b/          Term-ReadLine-0.7/
3240
3241 and write a dummy Makefile.PL that contains nothing but
3242
3243     use ExtUtils::MakeMaker;
3244     WriteMakefile();
3245
3246 That's actually fun to watch :)
3247
3248 Final suggestion: Try to delete all of your MY:: subroutines and
3249 watch, if you really still need them. MakeMaker might already do what
3250 you want without them. That's all about it.
3251
3252
3253 =head2 Default Makefile Behaviour
3254
3255 The automatically generated Makefile enables the user of the extension
3256 to invoke
3257
3258   perl Makefile.PL # optionally "perl Makefile.PL verbose"
3259   make
3260   make test        # optionally set TEST_VERBOSE=1
3261   make install     # See below
3262
3263 The Makefile to be produced may be altered by adding arguments of the
3264 form C<KEY=VALUE>. If the user wants to work with a different perl
3265 than the default, this can be achieved with
3266
3267   perl Makefile.PL PERL=/tmp/myperl5
3268
3269 Other interesting targets in the generated Makefile are
3270
3271   make config     # to check if the Makefile is up-to-date
3272   make clean      # delete local temp files (Makefile gets renamed)
3273   make realclean  # delete derived files (including ./blib)
3274   make dist       # see below the Distribution Support section
3275
3276 =head2 Special case make install
3277
3278 make alone puts all relevant files into directories that are named by
3279 the macros INST_LIB, INST_ARCHLIB, INST_EXE, INST_MAN1DIR, and
3280 INST_MAN3DIR. All these default to ./blib or something below blib if
3281 you are I<not> building below the perl source directory. If you I<are>
3282 building below the perl source, INST_LIB and INST_ARCHLIB default to
3283  ../../lib, and INST_EXE is not defined.
3284
3285 The I<install> target of the generated Makefile is a recursive call to
3286 make which sets
3287
3288     INST_LIB     to INSTALLPRIVLIB
3289     INST_ARCHLIB to INSTALLARCHLIB
3290     INST_EXE     to INSTALLBIN
3291     INST_MAN1DIR to INSTALLMAN1DIR
3292     INST_MAN3DIR to INSTALLMAN3DIR
3293
3294 The INSTALL... macros in turn default to their %Config
3295 ($Config{installprivlib}, $Config{installarchlib}, etc.) counterparts.
3296
3297 The recommended way to proceed is to set only the INSTALL* macros, not
3298 the INST_* targets. In doing so, you give room to the compilation
3299 process without affecting important directories. Usually a make
3300 test will succeed after the make, and a make install can finish
3301 the game.
3302
3303 MakeMaker gives you much more freedom than needed to configure
3304 internal variables and get different results. It is worth to mention,
3305 that make(1) also lets you configure most of the variables that are
3306 used in the Makefile. But in the majority of situations this will not
3307 be necessary, and should only be done, if the author of a package
3308 recommends it.
3309
3310 The usual relationship between INSTALLPRIVLIB and INSTALLARCHLIB is
3311 that the latter is a subdirectory of the former with the name
3312 C<$Config{archname}>, MakeMaker supports the user who sets
3313 INSTALLPRIVLIB. If INSTALLPRIVLIB is set, but INSTALLARCHLIB not, then
3314 MakeMaker defaults the latter to be INSTALLPRIVLIB/ARCHNAME if that
3315 directory exists, otherwise it defaults to INSTALLPRIVLIB.
3316
3317
3318 =head2 PREFIX attribute
3319
3320 The PREFIX attribute can be used to set the INSTALL* attributes
3321 (except INSTALLMAN1DIR) in one go. The quickest way to install a
3322 module in a non-standard place
3323
3324     perl Makefile.PL PREFIX=~
3325
3326 is identical to
3327
3328     perl Makefile.PL INSTALLPRIVLIB=~/perl5/lib INSTALLBIN=~/bin \
3329                      INSTALLMAN3DIR=~/perl5/man/man3
3330
3331 Note, that the tilde expansion is done by MakeMaker, not by perl by
3332 default, nor by make.
3333
3334 It is important to know, that the INSTALL* macros should be absolute
3335 paths, never relativ ones. Packages with multiple Makefile.PLs in
3336 different directories get the contents of the INSTALL* macros
3337 propagated verbatim. (The INST_* macros will be corrected, if they are
3338 relativ paths, but not the INSTALL* macros.)
3339
3340 If the user has superuser privileges, and is not working on AFS
3341 (Andrew File System) or relatives, then the defaults for
3342 INSTALLPRIVLIB, INSTALLARCHLIB, INSTALLBIN, etc. will be appropriate,
3343 and this incantation will be the best:
3344
3345     perl Makefile.PL; make; make test
3346     make install
3347
3348 make install per default writes some documentation of what has been
3349 done into the file C<$(INSTALLARCHLIB)/perllocal.pod>. This is
3350 an experimental feature. It can be bypassed by calling make
3351 pure_install.
3352
3353 =head2 AFS users
3354
3355 will have to specify the installation directories as these most
3356 probably have changed since perl itself has been installed. They will
3357 have to do this by calling
3358
3359     perl Makefile.PL INSTALLPRIVLIB=/afs/here/today \
3360         INSTALLBIN=/afs/there/now INSTALLMAN3DIR=/afs/for/manpages
3361     make
3362
3363 In nested extensions with many subdirectories, the INSTALL* arguments
3364 will get propagated to the subdirectories. Be careful to repeat this
3365 procedure every time you recompile an extension, unless you are sure
3366 the AFS istallation directories are still valid.
3367
3368
3369
3370 =head2 Static Linking of a new Perl Binary
3371
3372 An extension that is built with the above steps is ready to use on
3373 systems supporting dynamic loading. On systems that do not support
3374 dynamic loading, any newly created extension has to be linked together
3375 with the available resources. MakeMaker supports the linking process
3376 by creating appropriate targets in the Makefile whenever an extension
3377 is built. You can invoke the corresponding section of the makefile with
3378
3379     make perl
3380
3381 That produces a new perl binary in the current directory with all
3382 extensions linked in that can be found in INST_ARCHLIB (which usually
3383 is C<./blib>) and PERL_ARCHLIB. To do that, MakeMaker writes a new
3384 Makefile, on UNIX, this is called Makefile.aperl (may be system
3385 dependent). If you want to force the creation of a new perl, it is
3386 recommended, that you delete this Makefile.aperl, so INST_ARCHLIB and
3387 PERL_ARCHLIB are searched-through for linkable libraries again.
3388
3389 The binary can be installed into the directory where perl normally
3390 resides on your machine with
3391
3392     make inst_perl
3393
3394 To produce a perl binary with a different name than C<perl>, either say
3395
3396     perl Makefile.PL MAP_TARGET=myperl
3397     make myperl
3398     make inst_perl
3399
3400 or say
3401
3402     perl Makefile.PL
3403     make myperl MAP_TARGET=myperl
3404     make inst_perl MAP_TARGET=myperl
3405
3406 In any case you will be prompted with the correct invocation of the
3407 C<inst_perl> target that installs the new binary into INSTALLBIN.
3408
3409 Note, that there is a C<makeaperl> scipt in the perl distribution,
3410 that supports the linking of a new perl binary in a similar fashion,
3411 but with more options.
3412
3413 make inst_perl per default writes some documentation of what has been
3414 done into the file C<$(INSTALLARCHLIB)/perllocal.pod>. This
3415 can be bypassed by calling make pure_inst_perl.
3416
3417 Warning: the inst_perl: target is rather mighty and will probably
3418 overwrite your existing perl binary. Use with care!
3419
3420 Sometimes you might want to build a statically linked perl although
3421 your system supports dynamic loading. In this case you may explicitly
3422 set the linktype with the invocation of the Makefile.PL or make:
3423
3424     perl Makefile.PL LINKTYPE=static    # recommended
3425
3426 or
3427
3428     make LINKTYPE=static                # works on most systems
3429
3430 =head2 Determination of Perl Library and Installation Locations
3431
3432 MakeMaker needs to know, or to guess, where certain things are
3433 located.  Especially INST_LIB and INST_ARCHLIB (where to install files
3434 into), PERL_LIB and PERL_ARCHLIB (where to read existing modules
3435 from), and PERL_INC (header files and C<libperl*.*>).
3436
3437 Extensions may be built either using the contents of the perl source
3438 directory tree or from an installed copy of the perl library. The
3439 recommended way is to build extensions after you have run 'make
3440 install' on perl itself. Do that in a directory that is not below the
3441 perl source tree. The support for extensions below the ext directory
3442 of the perl distribution is only good for the standard extensions that
3443 come with perl.
3444
3445 If an extension is being built below the C<ext/> directory of the perl
3446 source then MakeMaker will set PERL_SRC automatically (e.g., C<../..>).
3447 If PERL_SRC is defined then other variables default to the following:
3448
3449   PERL_INC     = PERL_SRC
3450   PERL_LIB     = PERL_SRC/lib
3451   PERL_ARCHLIB = PERL_SRC/lib
3452   INST_LIB     = PERL_LIB
3453   INST_ARCHLIB = PERL_ARCHLIB
3454
3455 If an extension is being built away from the perl source then MakeMaker
3456 will leave PERL_SRC undefined and default to using the installed copy
3457 of the perl library. The other variables default to the following:
3458
3459   PERL_INC     = $archlib/CORE
3460   PERL_LIB     = $privlib
3461   PERL_ARCHLIB = $archlib
3462   INST_LIB     = ./blib
3463   INST_ARCHLIB = ./blib/<archname>
3464
3465 If perl has not yet been installed then PERL_SRC can be defined on the
3466 command line as shown in the previous section.
3467
3468 =head2 Useful Default Makefile Macros
3469
3470 FULLEXT = Pathname for extension directory (eg DBD/Oracle).
3471
3472 BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
3473
3474 ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
3475
3476 INST_LIBDIR = C<$(INST_LIB)$(ROOTEXT)>
3477
3478 INST_AUTODIR = C<$(INST_LIB)/auto/$(FULLEXT)>
3479
3480 INST_ARCHAUTODIR = C<$(INST_ARCHLIB)/auto/$(FULLEXT)>
3481
3482 =head2 Using Attributes (and Parameters)
3483
3484 The following attributes can be specified as arguments to WriteMakefile()
3485 or as NAME=VALUE pairs on the command line:
3486
3487 =cut
3488
3489 # The following "=item C" is used by the attrib_help routine
3490 # likewise the "=back" below. So be careful when changing it!
3491
3492 =over 2
3493
3494 =item C
3495
3496 Ref to array of *.c file names. Initialised from a directory scan
3497 and the values portion of the XS attribute hash. This is not
3498 currently used by MakeMaker but may be handy in Makefile.PLs.
3499
3500 =item CONFIG
3501
3502 Arrayref. E.g. [qw(archname manext)] defines ARCHNAME & MANEXT from
3503 config.sh. MakeMaker will add to CONFIG the following values anyway:
3504 ar
3505 cc
3506 cccdlflags
3507 ccdlflags
3508 dlext
3509 dlsrc
3510 ld
3511 lddlflags
3512 ldflags
3513 libc
3514 lib_ext
3515 obj_ext
3516 ranlib
3517 so
3518
3519 =item CONFIGURE
3520
3521 CODE reference. Extension writers are requested to do all their
3522 initializing within that subroutine. The subroutine
3523 should return a hash reference. The hash may contain
3524 further attributes, e.g. {LIBS => ...}, that have to
3525 be determined by some evaluation method.
3526
3527 =item DEFINE
3528
3529 Something like C<"-DHAVE_UNISTD_H">
3530
3531 =item DIR
3532
3533 Ref to array of subdirectories containing Makefile.PLs e.g. [ 'sdbm'
3534 ] in ext/SDBM_File
3535
3536 =item DISTNAME
3537
3538 Your name for distributing the package (by tar file) This defaults to
3539 NAME above.
3540
3541 =item DL_FUNCS
3542
3543 Hashref of symbol names for routines to be made available as
3544 universal symbols.  Each key/value pair consists of the package name
3545 and an array of routine names in that package.  Used only under AIX
3546 (export lists) and VMS (linker options) at present.  The routine
3547 names supplied will be expanded in the same way as XSUB names are
3548 expanded by the XS() macro.  Defaults to
3549
3550   {"$(NAME)" => ["boot_$(NAME)" ] }
3551
3552 e.g.
3553
3554   {"RPC" => [qw( boot_rpcb rpcb_gettime getnetconfigent )],
3555    "NetconfigPtr" => [ 'DESTROY'] }
3556
3557 =item DL_VARS
3558
3559 Array of symbol names for variables to be made available as
3560 universal symbols.  Used only under AIX (export lists) and VMS
3561 (linker options) at present.  Defaults to [].  (e.g. [ qw(
3562 Foo_version Foo_numstreams Foo_tree ) ])
3563
3564 =item EXE_FILES
3565
3566 Ref to array of executable files. The files will be copied to the
3567 INST_EXE directory. Make realclean will delete them from there
3568 again.
3569
3570 =item FIRST_MAKEFILE
3571
3572 The name of the Makefile to be produced. Defaults to the contents of
3573 MAKEFILE, but can be overridden. This is used for the second Makefile
3574 that will be produced for the MAP_TARGET.
3575
3576 =item FULLPERL
3577
3578 Perl binary able to run this extension.
3579
3580 =item H
3581
3582 Ref to array of *.h file names. Similar to C.
3583
3584 =item INC
3585
3586 Include file dirs eg: C<"-I/usr/5include -I/path/to/inc">
3587
3588 =item INSTALLARCHLIB
3589
3590 Used by 'make install', which sets INST_ARCHLIB to this value.
3591
3592 =item INSTALLBIN
3593
3594 Used by 'make install' which sets INST_EXE to this value.
3595
3596 =item INSTALLMAN1DIR
3597
3598 This directory gets the man pages at 'make install' time. Defaults to
3599 $Config{installman1dir}.
3600
3601 =item INSTALLMAN3DIR
3602
3603 This directory gets the man pages at 'make install' time. Defaults to
3604 $Config{installman3dir}.
3605
3606 =item INSTALLPRIVLIB
3607
3608 Used by 'make install', which sets INST_LIB to this value.
3609
3610 =item INST_ARCHLIB
3611
3612 Same as INST_LIB for architecture dependent files.
3613
3614 =item INST_EXE
3615
3616 Directory, where executable scripts should be installed during
3617 'make'. Defaults to "./blib/ARCHNAME", just to have a dummy
3618 location during testing. make install will set
3619 INST_EXE to INSTALLBIN.
3620
3621 =item INST_LIB
3622
3623 Directory where we put library files of this extension while building
3624 it.
3625
3626 =item INST_MAN1DIR
3627
3628 Directory to hold the man pages at 'make' time
3629
3630 =item INST_MAN3DIR
3631
3632 Directory to hold the man pages at 'make' time
3633
3634 =item LDFROM
3635
3636 defaults to "$(OBJECT)" and is used in the ld command to specify
3637 what files to link/load from (also see dynamic_lib below for how to
3638 specify ld flags)
3639
3640 =item LIBPERL_A
3641
3642 The filename of the perllibrary that will be used together with this
3643 extension. Defaults to libperl.a.
3644
3645 =item LIBS
3646
3647 An anonymous array of alternative library
3648 specifications to be searched for (in order) until
3649 at least one library is found. E.g.
3650
3651   'LIBS' => ["-lgdbm", "-ldbm -lfoo", "-L/path -ldbm.nfs"]
3652
3653 Mind, that any element of the array
3654 contains a complete set of arguments for the ld
3655 command. So do not specify
3656
3657   'LIBS' => ["-ltcl", "-ltk", "-lX11"]
3658
3659 See ODBM_File/Makefile.PL for an example, where an array is needed. If
3660 you specify a scalar as in
3661
3662   'LIBS' => "-ltcl -ltk -lX11"
3663
3664 MakeMaker will turn it into an array with one element.
3665
3666 =item LINKTYPE
3667
3668 'static' or 'dynamic' (default unless usedl=undef in config.sh) Should
3669 only be used to force static linking (also see
3670 linkext below).
3671
3672 =item MAKEAPERL
3673
3674 Boolean which tells MakeMaker, that it should include the rules to
3675 make a perl. This is handled automatically as a switch by
3676 MakeMaker. The user normally does not need it.
3677
3678 =item MAKEFILE
3679
3680 The name of the Makefile to be produced.
3681
3682 =item MAN1PODS
3683
3684 Hashref of pod-containing files. MakeMaker will default this to all
3685 EXE_FILES files that include POD directives. The files listed
3686 here will be converted to man pages and installed as was requested
3687 at Configure time.
3688
3689 =item MAN3PODS
3690
3691 Hashref of .pm and .pod files. MakeMaker will default this to all
3692  .pod and any .pm files that include POD directives. The files listed
3693 here will be converted to man pages and installed as was requested
3694 at Configure time.
3695
3696 =item MAP_TARGET
3697
3698 If it is intended, that a new perl binary be produced, this variable
3699 may hold a name for that binary. Defaults to perl
3700
3701 =item MYEXTLIB
3702
3703 If the extension links to a library that it builds set this to the
3704 name of the library (see SDBM_File)
3705
3706 =item NAME
3707
3708 Perl module name for this extension (DBD::Oracle). This will default
3709 to the directory name but should be explicitly defined in the
3710 Makefile.PL.
3711
3712 =item NEEDS_LINKING
3713
3714 MakeMaker will figure out, if an extension contains linkable code
3715 anywhere down the directory tree, and will set this variable
3716 accordingly, but you can speed it up a very little bit, if you define
3717 this boolean variable yourself.
3718
3719 =item NORECURS
3720
3721 Boolean. Experimental attribute to inhibit descending into
3722 subdirectories.
3723
3724 =item OBJECT
3725
3726 List of object files, defaults to '$(BASEEXT)$(OBJ_EXT)', but can be a long
3727 string containing all object files, e.g. "tkpBind.o
3728 tkpButton.o tkpCanvas.o"
3729
3730 =item PERL
3731
3732 Perl binary for tasks that can be done by miniperl
3733
3734 =item PERLMAINCC
3735
3736 The call to the program that is able to compile perlmain.c. Defaults
3737 to $(CC).
3738
3739 =item PERL_ARCHLIB
3740
3741 Same as above for architecture dependent files
3742
3743 =item PERL_LIB
3744
3745 Directory containing the Perl library to use.
3746
3747 =item PERL_SRC
3748
3749 Directory containing the Perl source code (use of this should be
3750 avoided, it may be undefined)
3751
3752 =item PL_FILES
3753
3754 Ref to hash of files to be processed as perl programs. MakeMaker
3755 will default to any found *.PL file (except Makefile.PL) being keys
3756 and the basename of the file being the value. E.g.
3757
3758   {'foobar.PL' => 'foobar'}
3759
3760 The *.PL files are expected to produce output to the target files
3761 themselves.
3762
3763 =item PM
3764
3765 Hashref of .pm files and *.pl files to be installed.  e.g.
3766
3767   {'name_of_file.pm' => '$(INST_LIBDIR)/install_as.pm'}
3768
3769 By default this will include *.pm and *.pl. If a lib directory
3770 exists and is not listed in DIR (above) then any *.pm and *.pl files
3771 it contains will also be included by default.  Defining PM in the
3772 Makefile.PL will override PMLIBDIRS.
3773
3774 =item PMLIBDIRS
3775
3776 Ref to array of subdirectories containing library files.  Defaults to
3777 [ 'lib', $(BASEEXT) ]. The directories will be scanned and any files
3778 they contain will be installed in the corresponding location in the
3779 library.  A libscan() method can be used to alter the behaviour.
3780 Defining PM in the Makefile.PL will override PMLIBDIRS.
3781
3782 =item PREFIX
3783
3784 Can be used to set the three INSTALL* attributes in one go (except for
3785 INSTALLMAN1DIR).  They will have PREFIX as a common directory node and
3786 will branch from that node into lib/, lib/ARCHNAME, and bin/ unless
3787 you override one of them.
3788
3789 =item PREREQ
3790
3791 Placeholder, not yet implemented. Will eventually be a hashref: Names
3792 of modules that need to be available to run this extension (e.g. Fcntl
3793 for SDBM_File) are the keys of the hash and the desired version is the
3794 value. Needs further evaluation, should probably allow to define
3795 prerequisites among header files, libraries, perl version, etc.
3796
3797 =item SKIP
3798
3799 Arryref. E.g. [qw(name1 name2)] skip (do not write) sections of the
3800 Makefile
3801
3802 =item TYPEMAPS
3803
3804 Ref to array of typemap file names.  Use this when the typemaps are
3805 in some directory other than the current directory or when they are
3806 not named B<typemap>.  The last typemap in the list takes
3807 precedence.  A typemap in the current directory has highest
3808 precedence, even if it isn't listed in TYPEMAPS.  The default system
3809 typemap has lowest precedence.
3810
3811 =item VERSION
3812
3813 Your version number for distributing the package.  This defaults to
3814 0.1.
3815
3816 =item XS
3817
3818 Hashref of .xs files. MakeMaker will default this.  e.g.
3819
3820   {'name_of_file.xs' => 'name_of_file.c'}
3821
3822 The .c files will automatically be included in the list of files
3823 deleted by a make clean.
3824
3825 =item XSOPT
3826
3827 String of options to pass to xsubpp.  This might include C<-C++> or
3828 C<-extern>.  Do not include typemaps here; the TYPEMAP parameter exists for
3829 that purpose.
3830
3831 =item XSPROTOARG
3832
3833 May be set to an empty string, C<-prototypes>, or
3834 C<-noprototypes>. See the xsubpp documentation for details. MakeMaker
3835 defaults to the empty string for older versions of xsubpp and to
3836 C<-noprototypes> for more recent ones. The default will change to
3837 C<-prototypes> really soon now. So do not rely on the default when
3838 writing extensions. Better armour your extension with prototype
3839 support from the start.
3840
3841 =back
3842
3843 =head2 Additional lowercase attributes
3844
3845 can be used to pass parameters to the methods which implement that
3846 part of the Makefile. These are not normally required:
3847
3848 =over 2
3849
3850 =item clean
3851
3852   {FILES => "*.xyz foo"}
3853
3854 =item dist
3855
3856   {TARFLAGS => 'cvfF', COMPRESS => 'gzip', SUFFIX => 'gz',
3857   SHAR => 'shar -m', DIST_CP => 'ln'}
3858
3859 If you specify COMPRESS, then SUFFIX should also be altered, as it is
3860 needed to tell make the target file of the compression. Setting
3861 DIST_CP to ln can be useful, if you need to preserve the timestamps on
3862 your files. DIST_CP can take the values 'cp', which copies the file,
3863 'ln', which links the file, and 'best' which copies symbolic links and
3864 links the rest. Default is 'best'.
3865
3866 =item dynamic_lib
3867
3868   {ARMAYBE => 'ar', OTHERLDFLAGS => '...'}
3869
3870 =item installpm
3871
3872   {SPLITLIB => '$(INST_LIB)' (default) or '$(INST_ARCHLIB)'}
3873
3874 =item linkext
3875
3876   {LINKTYPE => 'static', 'dynamic' or ''}
3877
3878 NB: Extensions that have nothing but *.pm files had to say
3879
3880   {LINKTYPE => ''}
3881
3882 with Pre-5.0 MakeMakers. Since version 5.00 of MakeMaker such a line
3883 can be deleted safely. MakeMaker recognizes, when there's nothing to
3884 be linked.
3885
3886 =item macro
3887
3888   {ANY_MACRO => ANY_VALUE, ...}
3889
3890 =item realclean
3891
3892   {FILES => '$(INST_ARCHAUTODIR)/*.xyz'}
3893
3894 =item tool_autosplit
3895
3896   {MAXLEN =E<gt> 8}
3897
3898 =back
3899
3900 =cut
3901
3902 # bug in pod2html, so leave the =back
3903
3904 # Don't delete this cut, MM depends on it!
3905
3906 =head2 Overriding MakeMaker Methods
3907
3908 If you cannot achieve the desired Makefile behaviour by specifying
3909 attributes you may define private subroutines in the Makefile.PL.
3910 Each subroutines returns the text it wishes to have written to
3911 the Makefile. To override a section of the Makefile you can
3912 either say:
3913
3914         sub MY::c_o { "new literal text" }
3915
3916 or you can edit the default by saying something like:
3917
3918         sub MY::c_o {
3919             my $self = shift;
3920             local *c_o;
3921             $_=$self->MM::c_o;
3922             s/old text/new text/;
3923             $_;
3924         }
3925
3926 Both methods above are available for backwards compatibility with
3927 older Makefile.PLs.
3928
3929 If you still need a different solution, try to develop another
3930 subroutine, that fits your needs and submit the diffs to
3931 F<perl5-porters@nicoh.com> or F<comp.lang.perl.misc> as appropriate.
3932
3933 =head2 Distribution Support
3934
3935 For authors of extensions MakeMaker provides several Makefile
3936 targets. Most of the support comes from the ExtUtils::Manifest module,
3937 where additional documentation can be found.
3938
3939 =over 4
3940
3941 =item    make distcheck
3942
3943 reports which files are below the build directory but not in the
3944 MANIFEST file and vice versa. (See ExtUtils::Manifest::fullcheck() for
3945 details)
3946
3947 =item    make skipcheck
3948
3949 reports which files are skipped due to the entries in the
3950 C<MANIFEST.SKIP> file (See ExtUtils::Manifest::skipcheck() for
3951 details)
3952
3953 =item    make distclean
3954
3955 does a realclean first and then the distcheck. Note that this is not
3956 needed to build a new distribution as long as you are sure, that the
3957 MANIFEST file is ok.
3958
3959 =item    make manifest
3960
3961 rewrites the MANIFEST file, adding all remaining files found (See
3962 ExtUtils::Manifest::mkmanifest() for details)
3963
3964 =item    make distdir
3965
3966 Copies all the files that are in the MANIFEST file to a newly created
3967 directory with the name C<$(DISTNAME)-$(VERSION)>. If that directory
3968 exists, it will be removed first.
3969
3970 =item   make disttest
3971
3972 Makes a distdir first, and runs a C<perl Makefile.PL>, a make, and
3973 a make test in that directory.
3974
3975 =item    make tardist
3976
3977 First does a command $(PREOP) which defaults to a null command. Does a
3978 distdir next and runs C<tar> on that directory into a tarfile. Then
3979 deletes the distdir. Finishes with a command $(POSTOP) which defaults
3980 to a null command.
3981
3982 =item    make dist
3983
3984 Defaults to $(DIST_DEFAULT) which in turn defaults to tardist.
3985
3986 =item    make uutardist
3987
3988 Runs a tardist first and uuencodes the tarfile.
3989
3990 =item    make shdist
3991
3992 First does a command $(PREOP) which defaults to a null command. Does a
3993 distdir next and runs C<shar> on that directory into a sharfile. Then
3994 deletes the distdir. Finishes with a command $(POSTOP) which defaults
3995 to a null command.  Note: For shdist to work properly a C<shar>
3996 program that can handle directories is mandatory.
3997
3998 =item    make ci
3999
4000 Does a $(CI) and a $(RCS_LABEL) on all files in the MANIFEST file.
4001
4002 =back
4003
4004 Customization of the dist targets can be done by specifying a hash
4005 reference to the dist attribute of the WriteMakefile call. The
4006 following parameters are recognized:
4007
4008     CI           ('ci -u')
4009     COMPRESS     ('compress')
4010     POSTOP       ('@ :')
4011     PREOP        ('@ :')
4012     RCS_LABEL    ('rcs -q -Nv$(VERSION_SYM):')
4013     SHAR         ('shar')
4014     SUFFIX       ('Z')
4015     TAR          ('tar')
4016     TARFLAGS     ('cvf')
4017
4018 An example:
4019
4020     WriteMakefile( 'dist' => { COMPRESS=>"gzip", SUFFIX=>"gz" })
4021
4022
4023 =head1 AUTHORS 
4024
4025 Andy Dougherty F<E<lt>doughera@lafcol.lafayette.eduE<gt>>, Andreas
4026 KE<ouml>nig F<E<lt>A.Koenig@franz.ww.TU-Berlin.DEE<gt>>, Tim Bunce
4027 F<E<lt>Tim.Bunce@ig.co.ukE<gt>>.  VMS support by Charles Bailey
4028 F<E<lt>bailey@HMIVAX.HUMGEN.UPENN.EDUE<gt>>. Contact the makemaker
4029 mailing list C<mailto:makemaker@franz.ww.tu-berlin.de>, if you have any
4030 questions.
4031
4032 =head1 MODIFICATION HISTORY
4033
4034 For a more complete documentation see the file Changes in the
4035 MakeMaker distribution package.
4036
4037 =head1 TODO
4038
4039 See the file Todo in the MakeMaker distribution package.
4040
4041 =cut