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