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