perl 5.003_02: [no incremental changelog available]
[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) $(MAB) $(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) $(MAB) $(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}" if ($Config::Config{d_shrplib});
1964     $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
1965
1966     # The front matter of the linkcommand...
1967     $linkcmd = join ' ', "\$(CC)",
1968             grep($_, @Config{qw(large split ldflags ccdlflags)});
1969     $linkcmd =~ s/\s+/ /g;
1970     $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
1971
1972     # Which *.a files could we make use of...
1973     local(%static);
1974     require File::Find;
1975     File::Find::find(sub {
1976         return unless m/\Q$self->{LIB_EXT}\E$/;
1977         return if m/^libperl/;
1978
1979         if( exists $self->{INCLUDE_EXT} ){
1980                 my $found = 0;
1981                 my $incl;
1982                 my $xx;
1983
1984                 ($xx = $File::Find::name) =~ s,.*?/auto/,,;
1985                 $xx =~ s,/?$_,,;
1986                 $xx =~ s,/,::,g;
1987
1988                 # Throw away anything not explicitly marked for inclusion.
1989                 # DynaLoader is implied.
1990                 foreach $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
1991                         if( $xx eq $incl ){
1992                                 $found++;
1993                                 last;
1994                         }
1995                 }
1996                 return unless $found;
1997         }
1998         elsif( exists $self->{EXCLUDE_EXT} ){
1999                 my $excl;
2000                 my $xx;
2001
2002                 ($xx = $File::Find::name) =~ s,.*?/auto/,,;
2003                 $xx =~ s,/?$_,,;
2004                 $xx =~ s,/,::,g;
2005
2006                 # Throw away anything explicitly marked for exclusion
2007                 foreach $excl (@{$self->{EXCLUDE_EXT}}){
2008                         return if( $xx eq $excl );
2009                 }
2010         }
2011
2012         # don't include the installed version of this extension. I
2013         # leave this line here, although it is not necessary anymore:
2014         # I patched minimod.PL instead, so that Miniperl.pm won't
2015         # enclude duplicates
2016
2017         # Once the patch to minimod.PL is in the distribution, I can
2018         # drop it
2019         return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}$:;
2020         use Cwd 'cwd';
2021         $static{cwd() . "/" . $_}++;
2022     }, grep( -d $_, @{$searchdirs || []}) );
2023
2024     # We trust that what has been handed in as argument, will be buildable
2025     $static = [] unless $static;
2026     @static{@{$static}} = (1) x @{$static};
2027
2028     $extra = [] unless $extra && ref $extra eq 'ARRAY';
2029     for (sort keys %static) {
2030         next unless /\Q$self->{LIB_EXT}\E$/;
2031         $_ = dirname($_) . "/extralibs.ld";
2032         push @$extra, $_;
2033     }
2034
2035     grep(s/^/-I/, @{$perlinc || []});
2036
2037     $target = "perl" unless $target;
2038     $tmp = "." unless $tmp;
2039
2040 # MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
2041 # regenerate the Makefiles, MAP_STATIC and the dependencies for
2042 # extralibs.all are computed correctly
2043     push @m, "
2044 MAP_LINKCMD   = $linkcmd
2045 MAP_PERLINC   = @{$perlinc || []}
2046 MAP_STATIC    = ",
2047 join(" \\\n\t", reverse sort keys %static), "
2048
2049 MAP_PRELIBS   = $Config::Config{libs} $Config::Config{cryptlib}
2050 ";
2051
2052     if (defined $libperl) {
2053         ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
2054     }
2055     unless ($libperl && -f $lperl) { # Ilya's code...
2056         my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
2057         $libperl ||= "libperl$self->{LIB_EXT}";
2058         $libperl   = "$dir/$libperl";
2059         $lperl   ||= "libperl$self->{LIB_EXT}";
2060         $lperl     = "$dir/$lperl";
2061         print STDOUT "Warning: $libperl not found
2062     If you're going to build a static perl binary, make sure perl is installed
2063     otherwise ignore this warning\n"
2064                 unless (-f $lperl || defined($self->{PERL_SRC}));
2065     }
2066
2067     push @m, "
2068 MAP_LIBPERL = $libperl
2069 ";
2070
2071     push @m, "
2072 \$(INST_ARCHAUTODIR)/extralibs.all: \$(INST_ARCHAUTODIR)/.exists ".join(" \\\n\t", @$extra)."
2073         $self->{NOECHO}$self->{RM_F} \$\@
2074         $self->{NOECHO}\$(TOUCH) \$\@
2075 ";
2076
2077     my $catfile;
2078     foreach $catfile (@$extra){
2079         push @m, "\tcat $catfile >> \$\@\n";
2080     }
2081
2082     push @m, "
2083 \$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all
2084         \$(MAP_LINKCMD) -o \$\@ \$(OPTIMIZE) $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS)
2085         $self->{NOECHO}echo 'To install the new \"\$(MAP_TARGET)\" binary, call'
2086         $self->{NOECHO}echo '    make -f $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
2087         $self->{NOECHO}echo 'To remove the intermediate files say'
2088         $self->{NOECHO}echo '    make -f $makefilename map_clean'
2089
2090 $tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c
2091 ";
2092     push @m, "\tcd $tmp && $cccmd -I\$(PERL_INC) perlmain.c\n";
2093
2094     push @m, qq{
2095 $tmp/perlmain.c: $makefilename}, q{
2096         }.$self->{NOECHO}.q{echo Writing $@
2097         }.$self->{NOECHO}.q{$(PERL) $(MAP_PERLINC) -e 'use ExtUtils::Miniperl; \\
2098                 writemain(grep s#.*/auto/##, qw|$(MAP_STATIC)|)' > $@.tmp && mv $@.tmp $@
2099
2100 };
2101
2102     push @m, q{
2103 doc_inst_perl:
2104         }.$self->{NOECHO}.q{echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
2105         }.$self->{NOECHO}.q{$(DOC_INSTALL) \
2106                 "Perl binary $(MAP_TARGET)" \
2107                 MAP_STATIC "$(MAP_STATIC)" \
2108                 MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
2109                 MAP_LIBPERL "$(MAP_LIBPERL)" \
2110                 >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
2111
2112 };
2113
2114     push @m, q{
2115 inst_perl: pure_inst_perl doc_inst_perl
2116
2117 pure_inst_perl: $(MAP_TARGET)
2118         }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(INSTALLBIN)','$(MAP_TARGET)').q{
2119
2120 clean :: map_clean
2121
2122 map_clean :
2123         }.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
2124 };
2125
2126     join '', @m;
2127 }
2128
2129 =item makefile (o)
2130
2131 Defines how to rewrite the Makefile.
2132
2133 =cut
2134
2135 sub makefile {
2136     my($self) = shift;
2137     my @m;
2138     # We do not know what target was originally specified so we
2139     # must force a manual rerun to be sure. But as it should only
2140     # happen very rarely it is not a significant problem.
2141     push @m, '
2142 $(OBJECT) : $(FIRST_MAKEFILE)
2143 ' if $self->{OBJECT};
2144
2145     push @m, q{
2146 # We take a very conservative approach here, but it\'s worth it.
2147 # We move Makefile to Makefile.old here to avoid gnu make looping.
2148 }.$self->{MAKEFILE}.q{ : Makefile.PL $(CONFIGDEP)
2149         }.$self->{NOECHO}.q{echo "Makefile out-of-date with respect to $?"
2150         }.$self->{NOECHO}.q{echo "Cleaning current config before rebuilding Makefile..."
2151         -}.$self->{NOECHO}.q{mv }."$self->{MAKEFILE} $self->{MAKEFILE}.old".q{
2152         -$(MAKE) -f }.$self->{MAKEFILE}.q{.old clean >/dev/null 2>&1 || true
2153         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" Makefile.PL }.join(" ",map(qq["$_"],@ARGV)).q{
2154         }.$self->{NOECHO}.q{echo ">>> Your Makefile has been rebuilt. <<<"
2155         }.$self->{NOECHO}.q{echo ">>> Please rerun the make command.  <<<"; false
2156
2157 # To change behavior to :: would be nice, but would break Tk b9.02
2158 # so you find such a warning below the dist target.
2159 #}.$self->{MAKEFILE}.q{ :: $(VERSION_FROM)
2160 #       }.$self->{NOECHO}.q{echo "Warning: Makefile possibly out of date with $(VERSION_FROM)"
2161 };
2162
2163     join "", @m;
2164 }
2165
2166 =item manifypods (o)
2167
2168 Defines targets and routines to translate the pods into manpages and
2169 put them into the INST_* directories.
2170
2171 =cut
2172
2173 sub manifypods {
2174     my($self, %attribs) = @_;
2175     return "\nmanifypods :\n\t$self->{NOECHO}\$(NOOP)\n" unless %{$self->{MAN3PODS}} or %{$self->{MAN1PODS}};
2176     my($dist);
2177     my($pod2man_exe);
2178     if (defined $self->{PERL_SRC}) {
2179         $pod2man_exe = $self->catfile($self->{PERL_SRC},'pod','pod2man');
2180     } else {
2181         $pod2man_exe = $self->catfile($Config{scriptdirexp},'pod2man');
2182     }
2183     unless ($self->perl_script($pod2man_exe)) {
2184         # No pod2man but some MAN3PODS to be installed
2185         print <<END;
2186
2187 Warning: I could not locate your pod2man program. Please make sure,
2188          your pod2man program is in your PATH before you execute 'make'
2189
2190 END
2191         $pod2man_exe = "-S pod2man";
2192     }
2193     my(@m);
2194     push @m,
2195 qq[POD2MAN_EXE = $pod2man_exe\n],
2196 q[POD2MAN = $(PERL) -we '%m=@ARGV;for (keys %m){' \\
2197 -e 'next if -e $$m{$$_} && -M $$m{$$_} < -M $$_ && -M $$m{$$_} < -M "].$self->{MAKEFILE}.q[";' \\
2198 -e 'print "Manifying $$m{$$_}\n";' \\
2199 -e 'system(qq[$$^X ].q["-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" $(POD2MAN_EXE) ].qq[$$_>$$m{$$_}])==0 or warn "Couldn\\047t install $$m{$$_}\n";' \\
2200 -e 'chmod 0644, $$m{$$_} or warn "chmod 644 $$m{$$_}: $$!\n";}'
2201 ];
2202     push @m, "\nmanifypods : ";
2203     push @m, join " \\\n\t", keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}};
2204
2205     push(@m,"\n");
2206     if (%{$self->{MAN1PODS}} || %{$self->{MAN3PODS}}) {
2207         push @m, "\t$self->{NOECHO}\$(POD2MAN) \\\n\t";
2208         push @m, join " \\\n\t", %{$self->{MAN1PODS}}, %{$self->{MAN3PODS}};
2209     }
2210     join('', @m);
2211 }
2212
2213 =item maybe_command
2214
2215 Returns true, if the argument is likely to be a command.
2216
2217 =cut
2218
2219 sub maybe_command {
2220     my($self,$file) = @_;
2221     return $file if -x $file && ! -d $file;
2222     return;
2223 }
2224
2225 =item maybe_command_in_dirs
2226
2227 method under development. Not yet used. Ask Ilya :-)
2228
2229 =cut
2230
2231 sub maybe_command_in_dirs {     # $ver is optional argument if looking for perl
2232 # Ilya's suggestion. Not yet used, want to understand it first, but at least the code is here
2233     my($self, $names, $dirs, $trace, $ver) = @_;
2234     my($name, $dir);
2235     foreach $dir (@$dirs){
2236         next unless defined $dir; # $self->{PERL_SRC} may be undefined
2237         foreach $name (@$names){
2238             my($abs,$tryabs);
2239             if ($self->file_name_is_absolute($name)) { # /foo/bar
2240                 $abs = $name;
2241             } elsif ($self->canonpath($name) eq $self->canonpath(basename($name))) { # bar
2242                 $abs = $self->catfile($dir, $name);
2243             } else { # foo/bar
2244                 $abs = $self->catfile($self->curdir, $name);
2245             }
2246             print "Checking $abs for $name\n" if ($trace >= 2);
2247             next unless $tryabs = $self->maybe_command($abs);
2248             print "Substituting $tryabs instead of $abs\n"
2249                 if ($trace >= 2 and $tryabs ne $abs);
2250             $abs = $tryabs;
2251             if (defined $ver) {
2252                 print "Executing $abs\n" if ($trace >= 2);
2253                 if (`$abs -e 'require $ver; print "VER_OK\n" ' 2>&1` =~ /VER_OK/) {
2254                     print "Using PERL=$abs\n" if $trace;
2255                     return $abs;
2256                 }
2257             } else { # Do not look for perl
2258                 return $abs;
2259             }
2260         }
2261     }
2262 }
2263
2264 =item needs_linking (o)
2265
2266 Does this module need linking? Looks into subdirectory objects (see
2267 also has_link_code())
2268
2269 =cut
2270
2271 sub needs_linking {
2272     my($self) = shift;
2273     my($child,$caller);
2274     $caller = (caller(0))[3];
2275     Carp::confess("Needs_linking called too early") if $caller =~ /^ExtUtils::MakeMaker::/;
2276     return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
2277     if ($self->has_link_code or $self->{MAKEAPERL}){
2278         $self->{NEEDS_LINKING} = 1;
2279         return 1;
2280     }
2281     foreach $child (keys %{$self->{CHILDREN}}) {
2282         if ($self->{CHILDREN}->{$child}->needs_linking) {
2283             $self->{NEEDS_LINKING} = 1;
2284             return 1;
2285         }
2286     }
2287     return $self->{NEEDS_LINKING} = 0;
2288 }
2289
2290 =item nicetext
2291
2292 misnamed method (will have to be changed). The MM_Unix method just
2293 returns the argument without further processing.
2294
2295 On VMS used to insure that colons marking targets are preceded by
2296 space - most Unix Makes don't need this, but it's necessary under VMS
2297 to distinguish the target delimiter from a colon appearing as part of
2298 a filespec.
2299
2300 =cut
2301
2302 sub nicetext {
2303     my($self,$text) = @_;
2304     $text;
2305 }
2306
2307 =item parse_version
2308
2309 parse a file and return what you think is $VERSION in this file set to
2310
2311 =cut
2312
2313 sub parse_version {
2314     my($self,$parsefile) = @_;
2315     my $result;
2316     local *FH;
2317     local $/ = "\n";
2318     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
2319     my $inpod = 0;
2320     while (<FH>) {
2321         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2322         next if $inpod;
2323         chop;
2324         next unless /\$(([\w\:\']*)\bVERSION)\b.*\=/;
2325         local $ExtUtils::MakeMaker::module_version_variable = $1;
2326         my($thispackage) = $2 || $current_package;
2327         $thispackage =~ s/:+$//;
2328         my($eval) = "$_;";
2329         eval $eval;
2330         die "Could not eval '$eval' in $parsefile: $@" if $@;
2331         $result = $ {$ExtUtils::MakeMaker::module_version_variable} || 0;
2332         last;
2333     }
2334     close FH;
2335     return $result;
2336 }
2337
2338
2339 =item pasthru (o)
2340
2341 Defines the string that is passed to recursive make calls in
2342 subdirectories.
2343
2344 =cut
2345
2346 sub pasthru {
2347     my($self) = shift;
2348     my(@m,$key);
2349
2350     my(@pasthru);
2351
2352     foreach $key (qw(LIBPERL_A LINKTYPE PREFIX OPTIMIZE)){
2353         push @pasthru, "$key=\"\$($key)\"";
2354     }
2355
2356     push @m, "\nPASTHRU = ", join ("\\\n\t", @pasthru), "\n";
2357     join "", @m;
2358 }
2359
2360 =item path
2361
2362 Takes no argument, returns the environment variable PATH as an array.
2363
2364 =cut
2365
2366 sub path {
2367     my($self) = @_;
2368     my $path_sep = $Is_OS2 ? ";" : ":";
2369     my $path = $ENV{PATH};
2370     $path =~ s:\\:/:g if $Is_OS2;
2371     my @path = split $path_sep, $path;
2372     foreach(@path) { $_ = '.' if $_ eq '' }
2373     @path;
2374 }
2375
2376 =item perl_script
2377
2378 Takes one argument, a file name, and returns the file name, if the
2379 argument is likely to be a perl script. On MM_Unix this is true for
2380 any ordinary, readable file.
2381
2382 =cut
2383
2384 sub perl_script {
2385     my($self,$file) = @_;
2386     return $file if -r $file && -f _;
2387     return;
2388 }
2389
2390 =item perldepend (o)
2391
2392 Defines the dependency from all *.h files that come with the perl
2393 distribution.
2394
2395 =cut
2396
2397 sub perldepend {
2398     my($self) = shift;
2399     my(@m);
2400     push @m, q{
2401 # Check for unpropogated config.sh changes. Should never happen.
2402 # We do NOT just update config.h because that is not sufficient.
2403 # An out of date config.h is not fatal but complains loudly!
2404 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
2405         -}.$self->{NOECHO}.q{echo "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
2406
2407 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
2408         }.$self->{NOECHO}.q{echo "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
2409         cd $(PERL_SRC) && $(MAKE) lib/Config.pm
2410 } if $self->{PERL_SRC};
2411
2412     return join "", @m unless $self->needs_linking;
2413
2414     push @m, q{
2415 PERL_HDRS = \
2416 $(PERL_INC)/EXTERN.h       $(PERL_INC)/gv.h           $(PERL_INC)/pp.h       \
2417 $(PERL_INC)/INTERN.h       $(PERL_INC)/handy.h        $(PERL_INC)/proto.h    \
2418 $(PERL_INC)/XSUB.h         $(PERL_INC)/hv.h           $(PERL_INC)/regcomp.h  \
2419 $(PERL_INC)/av.h           $(PERL_INC)/keywords.h     $(PERL_INC)/regexp.h   \
2420 $(PERL_INC)/config.h       $(PERL_INC)/mg.h           $(PERL_INC)/scope.h    \
2421 $(PERL_INC)/cop.h          $(PERL_INC)/op.h           $(PERL_INC)/sv.h       \
2422 $(PERL_INC)/cv.h           $(PERL_INC)/opcode.h       $(PERL_INC)/unixish.h  \
2423 $(PERL_INC)/dosish.h       $(PERL_INC)/patchlevel.h   $(PERL_INC)/util.h     \
2424 $(PERL_INC)/embed.h        $(PERL_INC)/perl.h                                \
2425 $(PERL_INC)/form.h         $(PERL_INC)/perly.h
2426
2427 $(OBJECT) : $(PERL_HDRS)
2428 } if $self->{OBJECT};
2429
2430     push @m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
2431
2432     join "\n", @m;
2433 }
2434
2435 =item pm_to_blib
2436
2437 Defines target that copies all files in the hash PM to their
2438 destination and autosplits them. See L<ExtUtils::Install/pm_to_blib>
2439
2440 =cut
2441
2442 sub pm_to_blib {
2443     my $self = shift;
2444     my($autodir) = $self->catdir('$(INST_LIB)','auto');
2445     return q{
2446 pm_to_blib: $(TO_INST_PM)
2447         }.$self->{NOECHO}.q{$(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" \
2448         "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MExtUtils::Install \
2449         -e 'pm_to_blib({qw{$(PM_TO_BLIB)}},"}.$autodir.q{")'
2450         }.$self->{NOECHO}.q{$(TOUCH) $@
2451 };
2452 }
2453
2454 =item post_constants (o)
2455
2456 Returns an empty string per default. Dedicated to overrides from
2457 within Makefile.PL after all constants have been defined.
2458
2459 =cut
2460
2461 sub post_constants{
2462     my($self) = shift;
2463     "";
2464 }
2465
2466 =item post_initialize (o)
2467
2468 Returns an ampty string per default. Used in Makefile.PLs to add some
2469 chunk of text to the Makefile after the object is initialized.
2470
2471 =cut
2472
2473 sub post_initialize {
2474     my($self) = shift;
2475     "";
2476 }
2477
2478 =item postamble (o)
2479
2480 Returns an empty string. Can be used in Makefile.PLs to write some
2481 text to the Makefile at the end.
2482
2483 =cut
2484
2485 sub postamble {
2486     my($self) = shift;
2487     "";
2488 }
2489
2490 =item prefixify
2491
2492 Check a path variable in $self from %Config, if it contains a prefix,
2493 and replace it with another one.
2494
2495 Takes as arguments an attribute name, a search prefix and a
2496 replacement prefix. Changes the attribute in the object.
2497
2498 =cut
2499
2500 sub prefixify {
2501     my($self,$var,$sprefix,$rprefix) = @_;
2502     $self->{uc $var} ||= $Config{lc $var};
2503     $self->{uc $var} = VMS::Filespec::unixpath($self->{uc $var}) if $Is_VMS;
2504     $self->{uc $var} =~ s/\Q$sprefix\E/$rprefix/;
2505 }
2506
2507 =item processPL (o)
2508
2509 Defines targets to run *.PL files.
2510
2511 =cut
2512
2513 sub processPL {
2514     my($self) = shift;
2515     return "" unless $self->{PL_FILES};
2516     my(@m, $plfile);
2517     foreach $plfile (sort keys %{$self->{PL_FILES}}) {
2518         push @m, "
2519 all :: $self->{PL_FILES}->{$plfile}
2520
2521 $self->{PL_FILES}->{$plfile} :: $plfile
2522         \$(PERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) $plfile
2523 ";
2524     }
2525     join "", @m;
2526 }
2527
2528 =item realclean (o)
2529
2530 Defines the realclean target.
2531
2532 =cut
2533
2534 sub realclean {
2535     my($self, %attribs) = @_;
2536     my(@m);
2537     push(@m,'
2538 # Delete temporary files (via clean) and also delete installed files
2539 realclean purge ::  clean
2540 ');
2541     # realclean subdirectories first (already cleaned)
2542     my $sub = "\t-cd %s && test -f %s && \$(MAKE) %s realclean\n";
2543     foreach(@{$self->{DIR}}){
2544         push(@m, sprintf($sub,$_,"$self->{MAKEFILE}.old","-f $self->{MAKEFILE}.old"));
2545         push(@m, sprintf($sub,$_,"$self->{MAKEFILE}",''));
2546     }
2547     push(@m, "  $self->{RM_RF} \$(INST_AUTODIR) \$(INST_ARCHAUTODIR)\n");
2548     if( $self->has_link_code ){
2549         push(@m, "      $self->{RM_F} \$(INST_DYNAMIC) \$(INST_BOOT)\n");
2550         push(@m, "      $self->{RM_F} \$(INST_STATIC)\n");
2551     }
2552     push(@m, "  $self->{RM_F} " . join(" ", values %{$self->{PM}}) . "\n");
2553     my(@otherfiles) = ($self->{MAKEFILE},
2554                        "$self->{MAKEFILE}.old"); # Makefiles last
2555     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
2556     push(@m, "  $self->{RM_RF} @otherfiles\n") if @otherfiles;
2557     push(@m, "  $attribs{POSTOP}\n")       if $attribs{POSTOP};
2558     join("", @m);
2559 }
2560
2561 =item replace_manpage_separator
2562
2563 Takes the name of a package, which may be a nested package, in the
2564 form Foo/Bar and replaces the slash with C<::>. Returns the replacement.
2565
2566 =cut
2567
2568 sub replace_manpage_separator {
2569     my($self,$man) = @_;
2570     $man =~ s,/+,::,g;
2571     $man;
2572 }
2573
2574 =item static (o)
2575
2576 Defines the static target.
2577
2578 =cut
2579
2580 sub static {
2581 # --- Static Loading Sections ---
2582
2583     my($self) = shift;
2584     '
2585 ## $(INST_PM) has been moved to the all: target.
2586 ## It remains here for awhile to allow for old usage: "make static"
2587 #static :: '.$self->{MAKEFILE}.' $(INST_STATIC) $(INST_PM)
2588 static :: '.$self->{MAKEFILE}.' $(INST_STATIC)
2589         '.$self->{NOECHO}.'$(NOOP)
2590 ';
2591 }
2592
2593 =item static_lib (o)
2594
2595 Defines how to produce the *.a (or equivalent) files.
2596
2597 =cut
2598
2599 sub static_lib {
2600     my($self) = @_;
2601 # Come to think of it, if there are subdirs with linkcode, we still have no INST_STATIC
2602 #    return '' unless $self->needs_linking(); #might be because of a subdir
2603
2604     return '' unless $self->has_link_code;
2605
2606     my(@m);
2607     push(@m, <<'END');
2608 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)/.exists
2609         $(RM_RF) $@
2610 END
2611     # If this extension has it's own library (eg SDBM_File)
2612     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
2613     push(@m, "\t$self->{CP} \$(MYEXTLIB) \$\@\n") if $self->{MYEXTLIB};
2614
2615     push @m,
2616 q{      $(AR) $(AR_STATIC_ARGS) $@ $(OBJECT) && $(RANLIB) $@
2617         }.$self->{NOECHO}.q{echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
2618         $(CHMOD) 755 $@
2619 };
2620
2621 # Old mechanism - still available:
2622
2623     push @m, "\t$self->{NOECHO}".q{echo "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs}."\n\n"
2624         if $self->{PERL_SRC};
2625
2626     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
2627     join('', "\n",@m);
2628 }
2629
2630 =item staticmake (o)
2631
2632 Calls makeaperl.
2633
2634 =cut
2635
2636 sub staticmake {
2637     my($self, %attribs) = @_;
2638     my(@static);
2639
2640     my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
2641
2642     # And as it's not yet built, we add the current extension
2643     # but only if it has some C code (or XS code, which implies C code)
2644     if (@{$self->{C}}) {
2645         @static = $self->catfile($self->{INST_ARCHLIB},
2646                                  "auto",
2647                                  $self->{FULLEXT},
2648                                  "$self->{BASEEXT}$self->{LIB_EXT}"
2649                                 );
2650     }
2651
2652     # Either we determine now, which libraries we will produce in the
2653     # subdirectories or we do it at runtime of the make.
2654
2655     # We could ask all subdir objects, but I cannot imagine, why it
2656     # would be necessary.
2657
2658     # Instead we determine all libraries for the new perl at
2659     # runtime.
2660     my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
2661
2662     $self->makeaperl(MAKE       => $self->{MAKEFILE},
2663                      DIRS       => \@searchdirs,
2664                      STAT       => \@static,
2665                      INCL       => \@perlinc,
2666                      TARGET     => $self->{MAP_TARGET},
2667                      TMP        => "",
2668                      LIBPERL    => $self->{LIBPERL_A}
2669                     );
2670 }
2671
2672 =item subdir_x (o)
2673
2674 Helper subroutine for subdirs
2675
2676 =cut
2677
2678 sub subdir_x {
2679     my($self, $subdir) = @_;
2680     my(@m);
2681     qq{
2682
2683 subdirs ::
2684         $self->{NOECHO}cd $subdir && \$(MAKE) all \$(PASTHRU)
2685
2686 };
2687 }
2688
2689 =item subdirs (o)
2690
2691 Defines targets to process subdirectories.
2692
2693 =cut
2694
2695 sub subdirs {
2696 # --- Sub-directory Sections ---
2697     my($self) = shift;
2698     my(@m,$dir);
2699     # This method provides a mechanism to automatically deal with
2700     # subdirectories containing further Makefile.PL scripts.
2701     # It calls the subdir_x() method for each subdirectory.
2702     foreach $dir (@{$self->{DIR}}){
2703         push(@m, $self->subdir_x($dir));
2704 ####    print "Including $dir subdirectory\n";
2705     }
2706     if (@m){
2707         unshift(@m, "
2708 # The default clean, realclean and test targets in this Makefile
2709 # have automatically been given entries for each subdir.
2710
2711 ");
2712     } else {
2713         push(@m, "\n# none")
2714     }
2715     join('',@m);
2716 }
2717
2718 =item test (o)
2719
2720 Defines the test targets.
2721
2722 =cut
2723
2724 sub test {
2725 # --- Test and Installation Sections ---
2726
2727     my($self, %attribs) = @_;
2728     my($tests) = $attribs{TESTS} || (-d "t" ? "t/*.t" : "");
2729     my(@m);
2730     push(@m,"
2731 TEST_VERBOSE=0
2732 TEST_TYPE=test_\$(LINKTYPE)
2733 TEST_FILE = test.pl
2734 TESTDB_SW = -d
2735
2736 testdb :: testdb_\$(LINKTYPE)
2737
2738 test :: \$(TEST_TYPE)
2739 ");
2740     push(@m, map("\t$self->{NOECHO}cd $_ && test -f $self->{MAKEFILE} && \$(MAKE) test \$(PASTHRU)\n",
2741                  @{$self->{DIR}}));
2742     push(@m, "\t$self->{NOECHO}echo 'No tests defined for \$(NAME) extension.'\n")
2743         unless $tests or -f "test.pl" or @{$self->{DIR}};
2744     push(@m, "\n");
2745
2746     push(@m, "test_dynamic :: pure_all\n");
2747     push(@m, $self->test_via_harness('$(FULLPERL)', $tests)) if $tests;
2748     push(@m, $self->test_via_script('$(FULLPERL)', 'test.pl')) if -f "test.pl";
2749     push(@m, "\n");
2750
2751     push(@m, "testdb_dynamic :: pure_all\n");
2752     push(@m, $self->test_via_script('$(FULLPERL) $(TESTDB_SW)', '$(TEST_FILE)'));
2753     push(@m, "\n");
2754
2755     # Occasionally we may face this degenerate target:
2756     push @m, "test_ : test_dynamic\n\n";
2757
2758     if ($self->needs_linking()) {
2759         push(@m, "test_static :: pure_all \$(MAP_TARGET)\n");
2760         push(@m, $self->test_via_harness('./$(MAP_TARGET)', $tests)) if $tests;
2761         push(@m, $self->test_via_script('./$(MAP_TARGET)', 'test.pl')) if -f "test.pl";
2762         push(@m, "\n");
2763         push(@m, "testdb_static :: pure_all \$(MAP_TARGET)\n");
2764         push(@m, $self->test_via_script('./$(MAP_TARGET) $(TESTDB_SW)', '$(TEST_FILE)'));
2765         push(@m, "\n");
2766     } else {
2767         push @m, "test_static :: test_dynamic\n";
2768         push @m, "testdb_static :: testdb_dynamic\n";
2769     }
2770     join("", @m);
2771 }
2772
2773 =item test_via_harness (o)
2774
2775 Helper method to write the test targets
2776
2777 =cut
2778
2779 sub test_via_harness {
2780     my($self, $perl, $tests) = @_;
2781     "\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";
2782 }
2783
2784 =item test_via_script (o)
2785
2786 Other helper method for test.
2787
2788 =cut
2789
2790 sub test_via_script {
2791     my($self, $perl, $script) = @_;
2792     qq{\tPERL_DL_NONLAZY=1 $perl}.q{ -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) }.qq{$script
2793 };
2794 }
2795
2796 =item tool_autosplit (o)
2797
2798 Defines a simple perl call that runs autosplit. May be deprecated by
2799 pm_to_blib soon.
2800
2801 =cut
2802
2803 sub tool_autosplit {
2804 # --- Tool Sections ---
2805
2806     my($self, %attribs) = @_;
2807     my($asl) = "";
2808     $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
2809     q{
2810 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
2811 AUTOSPLITFILE = $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e 'use AutoSplit;}.$asl.q{autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) ;'
2812 };
2813 }
2814
2815 =item tools_other (o)
2816
2817 Defines SHELL, LD, TOUCH, CP, MV, RM_F, RM_RF, CHMOD, UMASK_NULL in
2818 the Makefile. Also defines the perl programs MKPATH,
2819 WARN_IF_OLD_PACKLIST, MOD_INSTALL. DOC_INSTALL, and UNINSTALL.
2820
2821 =cut
2822
2823 sub tools_other {
2824     my($self) = shift;
2825     my @m;
2826     my $bin_sh = $Config{sh} || '/bin/sh';
2827     push @m, qq{
2828 SHELL = $bin_sh
2829 };
2830
2831     for (qw/ CHMOD CP LD MV NOOP RM_F RM_RF TOUCH UMASK_NULL / ) {
2832         push @m, "$_ = $self->{$_}\n";
2833     }
2834
2835
2836     push @m, q{
2837 # The following is a portable way to say mkdir -p
2838 # To see which directories are created, change the if 0 to if 1
2839 MKPATH = $(PERL) -wle '$$"="/"; foreach $$p (@ARGV){' \\
2840 -e 'next if -d $$p; my(@p); foreach(split(/\//,$$p)){' \\
2841 -e 'push(@p,$$_); next if -d "@p/"; print "mkdir @p" if 0;' \\
2842 -e 'mkdir("@p",0777)||die $$! } } exit 0;'
2843
2844 # This helps us to minimize the effect of the .exists files A yet
2845 # better solution would be to have a stable file in the perl
2846 # distribution with a timestamp of zero. But this solution doesn't
2847 # need any changes to the core distribution and works with older perls
2848 EQUALIZE_TIMESTAMP = $(PERL) -we 'open F, ">$$ARGV[1]"; close F;' \\
2849 -e 'utime ((stat("$$ARGV[0]"))[8,9], $$ARGV[1])'
2850 };
2851
2852     return join "", @m if $self->{PARENT};
2853
2854     push @m, q{
2855 # Here we warn users that an old packlist file was found somewhere,
2856 # and that they should call some uninstall routine
2857 WARN_IF_OLD_PACKLIST = $(PERL) -we 'exit unless -f $$ARGV[0];' \\
2858 -e 'print "WARNING: I have found an old package in\n";' \\
2859 -e 'print "\t$$ARGV[0].\n";' \\
2860 -e 'print "Please make sure the two installations are not conflicting\n";'
2861
2862 UNINST=0
2863 VERBINST=1
2864
2865 MOD_INSTALL = $(PERL) -I$(INST_LIB) -I$(PERL_LIB) -MExtUtils::Install \
2866 -e 'install({@ARGV},"$(VERBINST)",0,"$(UNINST)");'
2867
2868 DOC_INSTALL = $(PERL) -e '$$\="\n\n";print "=head3 ", scalar(localtime), ": C<", shift, ">";' \
2869 -e 'print "=over 4";' \
2870 -e 'while (defined($$key = shift) and defined($$val = shift)){print "=item *";print "C<$$key: $$val>";}' \
2871 -e 'print "=back";'
2872
2873 UNINSTALL =   $(PERL) -MExtUtils::Install \
2874 -e 'uninstall($$ARGV[0],1);'
2875
2876 };
2877
2878     return join "", @m;
2879 }
2880
2881 =item tool_xsubpp (o)
2882
2883 Determines typemaps, xsubpp version, prototype behaviour.
2884
2885 =cut
2886
2887 sub tool_xsubpp {
2888     my($self) = shift;
2889     return "" unless $self->needs_linking;
2890     my($xsdir)  = $self->catdir($self->{PERL_LIB},"ExtUtils");
2891     my(@tmdeps) = $self->catdir('$(XSUBPPDIR)','typemap');
2892     if( $self->{TYPEMAPS} ){
2893         my $typemap;
2894         foreach $typemap (@{$self->{TYPEMAPS}}){
2895                 if( ! -f  $typemap ){
2896                         warn "Typemap $typemap not found.\n";
2897                 }
2898                 else{
2899                         push(@tmdeps,  $typemap);
2900                 }
2901         }
2902     }
2903     push(@tmdeps, "typemap") if -f "typemap";
2904     my(@tmargs) = map("-typemap $_", @tmdeps);
2905     if( exists $self->{XSOPT} ){
2906         unshift( @tmargs, $self->{XSOPT} );
2907     }
2908
2909
2910     my $xsubpp_version = $self->xsubpp_version($self->catfile($xsdir,"xsubpp"));
2911
2912     # What are the correct thresholds for version 1 && 2 Paul?
2913     if ( $xsubpp_version > 1.923 ){
2914         $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
2915     } else {
2916         if (defined $self->{XSPROTOARG} && $self->{XSPROTOARG} =~ /\-prototypes/) {
2917             print STDOUT qq{Warning: This extension wants to pass the switch "-prototypes" to xsubpp.
2918         Your version of xsubpp is $xsubpp_version and cannot handle this.
2919         Please upgrade to a more recent version of xsubpp.
2920 };
2921         } else {
2922             $self->{XSPROTOARG} = "";
2923         }
2924     }
2925
2926     return qq{
2927 XSUBPPDIR = $xsdir
2928 XSUBPP = \$(XSUBPPDIR)/xsubpp
2929 XSPROTOARG = $self->{XSPROTOARG}
2930 XSUBPPDEPS = @tmdeps
2931 XSUBPPARGS = @tmargs
2932 };
2933 };
2934
2935 sub xsubpp_version
2936 {
2937     my($self,$xsubpp) = @_;
2938     return $Xsubpp_Version if defined $Xsubpp_Version; # global variable
2939
2940     my ($version) ;
2941
2942     # try to figure out the version number of the xsubpp on the system
2943
2944     # first try the -v flag, introduced in 1.921 & 2.000a2
2945
2946     return "" unless $self->needs_linking;
2947
2948     my $command = "$self->{PERL} -I$self->{PERL_LIB} $xsubpp -v 2>&1";
2949     print "Running $command\n" if $Verbose >= 2;
2950     $version = `$command` ;
2951     warn "Running '$command' exits with status " . ($?>>8) if $?;
2952     chop $version ;
2953
2954     return $Xsubpp_Version = $1 if $version =~ /^xsubpp version (.*)/ ;
2955
2956     # nope, then try something else
2957
2958     my $counter = '000';
2959     my ($file) = 'temp' ;
2960     $counter++ while -e "$file$counter"; # don't overwrite anything
2961     $file .= $counter;
2962
2963     open(F, ">$file") or die "Cannot open file '$file': $!\n" ;
2964     print F <<EOM ;
2965 MODULE = fred PACKAGE = fred
2966
2967 int
2968 fred(a)
2969         int     a;
2970 EOM
2971
2972     close F ;
2973
2974     $command = "$self->{PERL} $xsubpp $file 2>&1";
2975     print "Running $command\n" if $Verbose >= 2;
2976     my $text = `$command` ;
2977     warn "Running '$command' exits with status " . ($?>>8) if $?;
2978     unlink $file ;
2979
2980     # gets 1.2 -> 1.92 and 2.000a1
2981     return $Xsubpp_Version = $1 if $text =~ /automatically by xsubpp version ([\S]+)\s*/  ;
2982
2983     # it is either 1.0 or 1.1
2984     return $Xsubpp_Version = 1.1 if $text =~ /^Warning: ignored semicolon/ ;
2985
2986     # none of the above, so 1.0
2987     return $Xsubpp_Version = "1.0" ;
2988 }
2989
2990 =item top_targets (o)
2991
2992 Defines the targets all, subdirs, config, and O_FILES
2993
2994 =cut
2995
2996 sub top_targets {
2997 # --- Target Sections ---
2998
2999     my($self) = shift;
3000     my(@m);
3001     push @m, '
3002 #all :: config $(INST_PM) subdirs linkext manifypods
3003
3004 all :: pure_all manifypods
3005         '.$self->{NOECHO}.'$(NOOP)
3006
3007 pure_all :: config pm_to_blib subdirs linkext
3008         '.$self->{NOECHO}.'$(NOOP)
3009
3010 subdirs :: $(MYEXTLIB)
3011         '.$self->{NOECHO}.'$(NOOP)
3012
3013 config :: '.$self->{MAKEFILE}.' $(INST_LIBDIR)/.exists
3014         '.$self->{NOECHO}.'$(NOOP)
3015
3016 config :: $(INST_ARCHAUTODIR)/.exists
3017         '.$self->{NOECHO}.'$(NOOP)
3018
3019 config :: $(INST_AUTODIR)/.exists
3020         '.$self->{NOECHO}.'$(NOOP)
3021 ';
3022
3023     push @m, qq{
3024 config :: Version_check
3025         $self->{NOECHO}\$(NOOP)
3026
3027 } unless $self->{PARENT} or ($self->{PERL_SRC} && $self->{INSTALLDIRS} eq "perl") or $self->{NO_VC};
3028
3029     push @m, $self->dir_target(qw[$(INST_AUTODIR) $(INST_LIBDIR) $(INST_ARCHAUTODIR)]);
3030
3031     if (%{$self->{MAN1PODS}}) {
3032         push @m, qq[
3033 config :: \$(INST_MAN1DIR)/.exists
3034         $self->{NOECHO}\$(NOOP)
3035
3036 ];
3037         push @m, $self->dir_target(qw[$(INST_MAN1DIR)]);
3038     }
3039     if (%{$self->{MAN3PODS}}) {
3040         push @m, qq[
3041 config :: \$(INST_MAN3DIR)/.exists
3042         $self->{NOECHO}\$(NOOP)
3043
3044 ];
3045         push @m, $self->dir_target(qw[$(INST_MAN3DIR)]);
3046     }
3047
3048     push @m, '
3049 $(O_FILES): $(H_FILES)
3050 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
3051
3052     push @m, q{
3053 help:
3054         perldoc ExtUtils::MakeMaker
3055 };
3056
3057     push @m, q{
3058 Version_check:
3059         }.$self->{NOECHO}.q{$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
3060                 -MExtUtils::MakeMaker=Version_check \
3061                 -e 'Version_check("$(MM_VERSION)")'
3062 };
3063
3064     join('',@m);
3065 }
3066
3067 =item writedoc
3068
3069 Obsolete, depecated method. Not used since Version 5.21.
3070
3071 =cut
3072
3073 sub writedoc {
3074 # --- perllocal.pod section ---
3075     my($self,$what,$name,@attribs)=@_;
3076     my $time = localtime;
3077     print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
3078     print join "\n\n=item *\n\n", map("C<$_>",@attribs);
3079     print "\n\n=back\n\n";
3080 }
3081
3082 =item xs_c (o)
3083
3084 Defines the suffix rules to compile XS files to C.
3085
3086 =cut
3087
3088 sub xs_c {
3089     my($self) = shift;
3090     return '' unless $self->needs_linking();
3091     '
3092 .xs.c:
3093         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >$*.tc && mv $*.tc $@
3094 ';
3095 }
3096
3097 =item xs_o (o)
3098
3099 Defines suffix rules to go from XS to object files directly. This is
3100 only intended for broken make implementations.
3101
3102 =cut
3103
3104 sub xs_o {      # many makes are too dumb to use xs_c then c_o
3105     my($self) = shift;
3106     return '' unless $self->needs_linking();
3107     '
3108 .xs$(OBJ_EXT):
3109         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $*.c
3110         $(CCCMD) $(MAB) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
3111 ';
3112 }
3113
3114 1;
3115
3116
3117 =head1 SEE ALSO
3118
3119 L<ExtUtils::MakeMaker>
3120
3121 =cut
3122
3123 __END__