xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1package ExtUtils::MM_Unix;
2
3require 5.006;
4
5use strict;
6use warnings;
7
8use Carp;
9use ExtUtils::MakeMaker::Config;
10use File::Basename qw(basename dirname);
11
12our %Config_Override;
13
14use ExtUtils::MakeMaker qw($Verbose neatvalue _sprintf562);
15
16# If $VERSION is in scope, parse_version() breaks
17{
18our $VERSION = '7.70';
19$VERSION =~ tr/_//d;
20}
21
22require ExtUtils::MM_Any;
23our @ISA = qw(ExtUtils::MM_Any);
24
25my %Is;
26BEGIN {
27    $Is{OS2}     = $^O eq 'os2';
28    $Is{Win32}   = $^O eq 'MSWin32' || $Config{osname} eq 'NetWare';
29    $Is{Dos}     = $^O eq 'dos';
30    $Is{VMS}     = $^O eq 'VMS';
31    $Is{OSF}     = $^O eq 'dec_osf';
32    $Is{IRIX}    = $^O eq 'irix';
33    $Is{NetBSD}  = $^O eq 'netbsd';
34    $Is{Interix} = $^O eq 'interix';
35    $Is{SunOS4}  = $^O eq 'sunos';
36    $Is{Solaris} = $^O eq 'solaris';
37    $Is{SunOS}   = $Is{SunOS4} || $Is{Solaris};
38    $Is{BSD}     = ($^O =~ /^(?:free|midnight|net|open)bsd$/ or
39                   grep( $^O eq $_, qw(bsdos interix dragonfly) )
40                  );
41    $Is{Android} = $^O =~ /android/;
42    if ( $^O eq 'darwin' ) {
43      my @osvers = split /\./, $Config{osvers};
44      if ( $^X eq '/usr/bin/perl' ) {
45        $Is{ApplCor} = ( $osvers[0] >= 18 );
46      }
47      $Is{AppleRPath} = ( $osvers[0] >= 9 );
48    }
49}
50
51BEGIN {
52    if( $Is{VMS} ) {
53        # For things like vmsify()
54        require VMS::Filespec;
55        VMS::Filespec->import;
56    }
57}
58
59
60=head1 NAME
61
62ExtUtils::MM_Unix - methods used by ExtUtils::MakeMaker
63
64=head1 SYNOPSIS
65
66  require ExtUtils::MM_Unix;
67
68=head1 DESCRIPTION
69
70The methods provided by this package are designed to be used in
71conjunction with L<ExtUtils::MakeMaker>. When MakeMaker writes a
72Makefile, it creates one or more objects that inherit their methods
73from a package L<MM|ExtUtils::MM>. MM itself doesn't provide any methods, but
74it ISA ExtUtils::MM_Unix class. The inheritance tree of MM lets operating
75specific packages take the responsibility for all the methods provided
76by MM_Unix. We are trying to reduce the number of the necessary
77overrides by defining rather primitive operations within
78ExtUtils::MM_Unix.
79
80If you are going to write a platform specific MM package, please try
81to limit the necessary overrides to primitive methods, and if it is not
82possible to do so, let's work out how to achieve that gain.
83
84If you are overriding any of these methods in your Makefile.PL (in the
85MY class), please report that to the makemaker mailing list. We are
86trying to minimize the necessary method overrides and switch to data
87driven Makefile.PLs wherever possible. In the long run less methods
88will be overridable via the MY class.
89
90=head1 METHODS
91
92The following description of methods is still under
93development. Please refer to the code for not suitably documented
94sections and complain loudly to the makemaker@perl.org mailing list.
95Better yet, provide a patch.
96
97Not all of the methods below are overridable in a
98Makefile.PL. Overridable methods are marked as (o). All methods are
99overridable by a platform specific MM_*.pm file.
100
101Cross-platform methods are being moved into L<MM_Any|ExtUtils::MM_Any>.
102If you can't find something that used to be in here, look in MM_Any.
103
104=cut
105
106# So we don't have to keep calling the methods over and over again,
107# we have these globals to cache the values.  Faster and shrtr.
108my $Curdir  = __PACKAGE__->curdir;
109my $Updir   = __PACKAGE__->updir;
110
111
112=head2 Methods
113
114=over 4
115
116=item os_flavor
117
118Simply says that we're Unix.
119
120=cut
121
122sub os_flavor {
123    return('Unix');
124}
125
126
127=item c_o (o)
128
129Defines the suffix rules to compile different flavors of C files to
130object files.
131
132=cut
133
134sub c_o {
135# --- Translation Sections ---
136
137    my($self) = shift;
138    return '' unless $self->needs_linking();
139    my(@m);
140
141    my $command = '$(CCCMD)';
142    my $flags   = '$(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE)';
143
144    if ( $Is{ApplCor} ) {
145        $flags =~ s/"-I(\$\(PERL_INC\))"/-iwithsysroot "$1"/;
146    }
147
148    if (my $cpp = $self->{CPPRUN}) {
149        my $cpp_cmd = $self->const_cccmd;
150        $cpp_cmd =~ s/^CCCMD\s*=\s*\$\(CC\)/\$(CPPRUN)/;
151        push @m, qq{
152.c.i:
153	$cpp_cmd $flags \$*.c > \$*.i
154};
155    }
156
157    my $m_o = $self->{XSMULTI} ? $self->xs_obj_opt('$*.s') : '';
158    push @m, sprintf <<'EOF', $command, $flags, $m_o;
159
160.c.s :
161	%s -S %s $*.c %s
162EOF
163
164    my @exts = qw(c cpp cxx cc);
165    push @exts, 'C' if !$Is{OS2} and !$Is{Win32} and !$Is{Dos}; #Case-specific
166    $m_o = $self->{XSMULTI} ? $self->xs_obj_opt('$*$(OBJ_EXT)') : '';
167    my $dbgout = $self->dbgoutflag;
168    for my $ext (@exts) {
169	push @m, "\n.$ext\$(OBJ_EXT) :\n\t$command $flags "
170            .($dbgout?"$dbgout ":'')
171            ."\$*.$ext" . ( $m_o ? " $m_o" : '' ) . "\n";
172    }
173    return join "", @m;
174}
175
176
177=item xs_obj_opt
178
179Takes the object file as an argument, and returns the portion of compile
180command-line that will output to the specified object file.
181
182=cut
183
184sub xs_obj_opt {
185    my ($self, $output_file) = @_;
186    "-o $output_file";
187}
188
189=item dbgoutflag
190
191Returns a CC flag that tells the CC to emit a separate debugging symbol file
192when compiling an object file.
193
194=cut
195
196sub dbgoutflag {
197    '';
198}
199
200=item cflags (o)
201
202Does very much the same as the cflags script in the perl
203distribution. It doesn't return the whole compiler command line, but
204initializes all of its parts. The const_cccmd method then actually
205returns the definition of the CCCMD macro which uses these parts.
206
207=cut
208
209#'
210
211sub cflags {
212    my($self,$libperl)=@_;
213    return $self->{CFLAGS} if $self->{CFLAGS};
214    return '' unless $self->needs_linking();
215
216    my($prog, $uc, $perltype, %cflags);
217    $libperl ||= $self->{LIBPERL_A} || "libperl$self->{LIB_EXT}" ;
218    $libperl =~ s/\.\$\(A\)$/$self->{LIB_EXT}/;
219
220    @cflags{qw(cc ccflags optimize shellflags)}
221	= @Config{qw(cc ccflags optimize shellflags)};
222
223    # Perl 5.21.4 adds the (gcc) warning (-Wall ...) and std (-std=c89)
224    # flags to the %Config, and the modules in the core should be built
225    # with the warning flags, but NOT the -std=c89 flags (the latter
226    # would break using any system header files that are strict C99).
227    my @ccextraflags = qw(ccwarnflags);
228    if ($ENV{PERL_CORE}) {
229      for my $x (@ccextraflags) {
230        if (exists $Config{$x}) {
231          $cflags{$x} = $Config{$x};
232        }
233      }
234    }
235
236    my($optdebug) = "";
237
238    $cflags{shellflags} ||= '';
239
240    my(%map) =  (
241		D =>   '-DDEBUGGING',
242		E =>   '-DEMBED',
243		DE =>  '-DDEBUGGING -DEMBED',
244		M =>   '-DEMBED -DMULTIPLICITY',
245		DM =>  '-DDEBUGGING -DEMBED -DMULTIPLICITY',
246		);
247
248    if ($libperl =~ /libperl(\w*)\Q$self->{LIB_EXT}/){
249	$uc = uc($1);
250    } else {
251	$uc = ""; # avoid warning
252    }
253    $perltype = $map{$uc} ? $map{$uc} : "";
254
255    if ($uc =~ /^D/) {
256	$optdebug = "-g";
257    }
258
259
260    my($name);
261    ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
262    if ($prog = $Config{$name}) {
263	# Expand hints for this extension via the shell
264	print "Processing $name hint:\n" if $Verbose;
265	my(@o)=`cc=\"$cflags{cc}\"
266	  ccflags=\"$cflags{ccflags}\"
267	  optimize=\"$cflags{optimize}\"
268	  perltype=\"$cflags{perltype}\"
269	  optdebug=\"$cflags{optdebug}\"
270	  eval '$prog'
271	  echo cc=\$cc
272	  echo ccflags=\$ccflags
273	  echo optimize=\$optimize
274	  echo perltype=\$perltype
275	  echo optdebug=\$optdebug
276	  `;
277	foreach my $line (@o){
278	    chomp $line;
279	    if ($line =~ /(.*?)=\s*(.*)\s*$/){
280		$cflags{$1} = $2;
281		print "	$1 = $2\n" if $Verbose;
282	    } else {
283		print "Unrecognised result from hint: '$line'\n";
284	    }
285	}
286    }
287
288    if ($optdebug) {
289	$cflags{optimize} = $optdebug;
290    }
291
292    for (qw(ccflags optimize perltype)) {
293        $cflags{$_} ||= '';
294	$cflags{$_} =~ s/^\s+//;
295	$cflags{$_} =~ s/\s+/ /g;
296	$cflags{$_} =~ s/\s+$//;
297	$self->{uc $_} ||= $cflags{$_};
298    }
299
300    if ($self->{POLLUTE}) {
301	$self->{CCFLAGS} .= ' -DPERL_POLLUTE ';
302    }
303
304    for my $x (@ccextraflags) {
305      next unless exists $cflags{$x};
306      $self->{CCFLAGS} .= $cflags{$x} =~ m!^\s! ? $cflags{$x} : ' ' . $cflags{$x};
307    }
308
309    my $pollute = '';
310    if ($Config{usemymalloc} and not $Config{bincompat5005}
311	and not $Config{ccflags} =~ /-DPERL_POLLUTE_MALLOC\b/
312	and $self->{PERL_MALLOC_OK}) {
313	$pollute = '$(PERL_MALLOC_DEF)';
314    }
315
316    return $self->{CFLAGS} = qq{
317CCFLAGS = $self->{CCFLAGS}
318OPTIMIZE = $self->{OPTIMIZE}
319PERLTYPE = $self->{PERLTYPE}
320MPOLLUTE = $pollute
321};
322
323}
324
325
326=item const_cccmd (o)
327
328Returns the full compiler call for C programs and stores the
329definition in CONST_CCCMD.
330
331=cut
332
333sub const_cccmd {
334    my($self,$libperl)=@_;
335    return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
336    return '' unless $self->needs_linking();
337    return $self->{CONST_CCCMD} =
338	q{CCCMD = $(CC) -c $(PASTHRU_INC) $(INC) \\
339	$(CCFLAGS) $(OPTIMIZE) \\
340	$(PERLTYPE) $(MPOLLUTE) $(DEFINE_VERSION) \\
341	$(XS_DEFINE_VERSION)};
342}
343
344=item const_config (o)
345
346Sets SHELL if needed, then defines a couple of constants in the Makefile
347that are imported from %Config.
348
349=cut
350
351sub const_config {
352# --- Constants Sections ---
353
354    my($self) = shift;
355    my @m = $self->specify_shell(); # Usually returns empty string
356    push @m, <<"END";
357
358# These definitions are from config.sh (via $INC{'Config.pm'}).
359# They may have been overridden via Makefile.PL or on the command line.
360END
361
362    my(%once_only);
363    foreach my $key (@{$self->{CONFIG}}){
364        # SITE*EXP macros are defined in &constants; avoid duplicates here
365        next if $once_only{$key};
366        push @m, uc($key) , ' = ' , $self->{uc $key}, "\n";
367        $once_only{$key} = 1;
368    }
369    join('', @m);
370}
371
372=item const_loadlibs (o)
373
374Defines EXTRALIBS, LDLOADLIBS, BSLOADLIBS, LD_RUN_PATH. See
375L<ExtUtils::Liblist> for details.
376
377=cut
378
379sub const_loadlibs {
380    my($self) = shift;
381    return "" unless $self->needs_linking;
382    my @m;
383    push @m, qq{
384# $self->{NAME} might depend on some other libraries:
385# See ExtUtils::Liblist for details
386#
387};
388    for my $tmp (qw/
389         EXTRALIBS LDLOADLIBS BSLOADLIBS
390         /) {
391        next unless defined $self->{$tmp};
392        push @m, "$tmp = $self->{$tmp}\n";
393    }
394    # don't set LD_RUN_PATH if empty
395    for my $tmp (qw/
396         LD_RUN_PATH
397         /) {
398        next unless $self->{$tmp};
399        push @m, "$tmp = $self->{$tmp}\n";
400    }
401    return join "", @m;
402}
403
404=item constants (o)
405
406  my $make_frag = $mm->constants;
407
408Prints out macros for lots of constants.
409
410=cut
411
412sub constants {
413    my($self) = @_;
414    my @m = ();
415
416    $self->{DFSEP} = '$(DIRFILESEP)';  # alias for internal use
417
418    for my $macro (qw(
419
420              AR_STATIC_ARGS DIRFILESEP DFSEP
421              NAME NAME_SYM
422              VERSION    VERSION_MACRO    VERSION_SYM DEFINE_VERSION
423              XS_VERSION XS_VERSION_MACRO             XS_DEFINE_VERSION
424              INST_ARCHLIB INST_SCRIPT INST_BIN INST_LIB
425              INST_MAN1DIR INST_MAN3DIR
426              MAN1EXT      MAN3EXT
427              MAN1SECTION  MAN3SECTION
428              INSTALLDIRS INSTALL_BASE DESTDIR PREFIX
429              PERLPREFIX      SITEPREFIX      VENDORPREFIX
430                   ),
431                   (map { ("INSTALL".$_,
432                          "DESTINSTALL".$_)
433                        } $self->installvars),
434                   qw(
435              PERL_LIB
436              PERL_ARCHLIB PERL_ARCHLIBDEP
437              LIBPERL_A MYEXTLIB
438              FIRST_MAKEFILE MAKEFILE_OLD MAKE_APERL_FILE
439              PERLMAINCC PERL_SRC PERL_INC PERL_INCDEP
440              PERL            FULLPERL          ABSPERL
441              PERLRUN         FULLPERLRUN       ABSPERLRUN
442              PERLRUNINST     FULLPERLRUNINST   ABSPERLRUNINST
443              PERL_CORE
444              PERM_DIR PERM_RW PERM_RWX
445
446	      ) )
447    {
448	next unless defined $self->{$macro};
449
450        # pathnames can have sharp signs in them; escape them so
451        # make doesn't think it is a comment-start character.
452        $self->{$macro} =~ s/#/\\#/g;
453	$self->{$macro} = $self->quote_dep($self->{$macro})
454	  if $ExtUtils::MakeMaker::macro_dep{$macro};
455	push @m, "$macro = $self->{$macro}\n";
456    }
457
458    push @m, qq{
459MAKEMAKER   = $self->{MAKEMAKER}
460MM_VERSION  = $self->{MM_VERSION}
461MM_REVISION = $self->{MM_REVISION}
462};
463
464    push @m, q{
465# FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
466# BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
467# PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
468# DLBASE  = Basename part of dynamic library. May be just equal BASEEXT.
469};
470
471    for my $macro (qw/
472              MAKE
473	      FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT
474	      LDFROM LINKTYPE BOOTDEP
475	      /	)
476    {
477	next unless defined $self->{$macro};
478	push @m, "$macro = $self->{$macro}\n";
479    }
480
481    push @m, "
482# Handy lists of source code files:
483XS_FILES = ".$self->wraplist(sort keys %{$self->{XS}})."
484C_FILES  = ".$self->wraplist(sort @{$self->{C}})."
485O_FILES  = ".$self->wraplist(sort @{$self->{O_FILES}})."
486H_FILES  = ".$self->wraplist(sort @{$self->{H}})."
487MAN1PODS = ".$self->wraplist(sort keys %{$self->{MAN1PODS}})."
488MAN3PODS = ".$self->wraplist(sort keys %{$self->{MAN3PODS}})."
489";
490
491    push @m, q{
492SDKROOT := $(shell xcrun --show-sdk-path)
493PERL_SYSROOT = $(SDKROOT)
494} if $Is{ApplCor} && $self->{'PERL_INC'} =~ m!^/System/Library/Perl/!;
495
496    push @m, q{
497# Where is the Config information that we are using/depend on
498CONFIGDEP = $(PERL_ARCHLIBDEP)$(DFSEP)Config.pm $(PERL_SYSROOT)$(PERL_INCDEP)$(DFSEP)config.h
499} if $Is{ApplCor};
500
501    push @m, q{
502# Where is the Config information that we are using/depend on
503CONFIGDEP = $(PERL_ARCHLIBDEP)$(DFSEP)Config.pm $(PERL_INCDEP)$(DFSEP)config.h
504} if -e $self->catfile( $self->{PERL_INC}, 'config.h' ) && !$Is{ApplCor};
505
506    push @m, qq{
507# Where to build things
508INST_LIBDIR      = $self->{INST_LIBDIR}
509INST_ARCHLIBDIR  = $self->{INST_ARCHLIBDIR}
510
511INST_AUTODIR     = $self->{INST_AUTODIR}
512INST_ARCHAUTODIR = $self->{INST_ARCHAUTODIR}
513
514INST_STATIC      = $self->{INST_STATIC}
515INST_DYNAMIC     = $self->{INST_DYNAMIC}
516INST_BOOT        = $self->{INST_BOOT}
517};
518
519    push @m, qq{
520# Extra linker info
521EXPORT_LIST        = $self->{EXPORT_LIST}
522PERL_ARCHIVE       = $self->{PERL_ARCHIVE}
523PERL_ARCHIVEDEP    = $self->{PERL_ARCHIVEDEP}
524PERL_ARCHIVE_AFTER = $self->{PERL_ARCHIVE_AFTER}
525};
526
527    push @m, "
528
529TO_INST_PM = ".$self->wraplist(map $self->quote_dep($_), sort keys %{$self->{PM}})."\n";
530
531    join('',@m);
532}
533
534
535=item depend (o)
536
537Same as macro for the depend attribute.
538
539=cut
540
541sub depend {
542    my($self,%attribs) = @_;
543    my(@m,$key,$val);
544    for my $key (sort keys %attribs){
545	my $val = $attribs{$key};
546	next unless defined $key and defined $val;
547	push @m, "$key : $val\n";
548    }
549    join "", @m;
550}
551
552
553=item init_DEST
554
555  $mm->init_DEST
556
557Defines the DESTDIR and DEST* variables paralleling the INSTALL*.
558
559=cut
560
561sub init_DEST {
562    my $self = shift;
563
564    # Initialize DESTDIR
565    $self->{DESTDIR} ||= '';
566
567    # Make DEST variables.
568    foreach my $var ($self->installvars) {
569        my $destvar = 'DESTINSTALL'.$var;
570        $self->{$destvar} ||= '$(DESTDIR)$(INSTALL'.$var.')';
571    }
572}
573
574
575=item init_dist
576
577  $mm->init_dist;
578
579Defines a lot of macros for distribution support.
580
581  macro         description                     default
582
583  TAR           tar command to use              tar
584  TARFLAGS      flags to pass to TAR            cvf
585
586  ZIP           zip command to use              zip
587  ZIPFLAGS      flags to pass to ZIP            -r
588
589  COMPRESS      compression command to          gzip --best
590                use for tarfiles
591  SUFFIX        suffix to put on                .gz
592                compressed files
593
594  SHAR          shar command to use             shar
595
596  PREOP         extra commands to run before
597                making the archive
598  POSTOP        extra commands to run after
599                making the archive
600
601  TO_UNIX       a command to convert linefeeds
602                to Unix style in your archive
603
604  CI            command to checkin your         ci -u
605                sources to version control
606  RCS_LABEL     command to label your sources   rcs -Nv$(VERSION_SYM): -q
607                just after CI is run
608
609  DIST_CP       $how argument to manicopy()     best
610                when the distdir is created
611
612  DIST_DEFAULT  default target to use to        tardist
613                create a distribution
614
615  DISTVNAME     name of the resulting archive   $(DISTNAME)-$(VERSION)
616                (minus suffixes)
617
618=cut
619
620sub init_dist {
621    my $self = shift;
622
623    $self->{TAR}      ||= 'tar';
624    $self->{TARFLAGS} ||= 'cvf';
625    $self->{ZIP}      ||= 'zip';
626    $self->{ZIPFLAGS} ||= '-r';
627    $self->{COMPRESS} ||= 'gzip --best';
628    $self->{SUFFIX}   ||= '.gz';
629    $self->{SHAR}     ||= 'shar';
630    $self->{PREOP}    ||= '$(NOECHO) $(NOOP)'; # eg update MANIFEST
631    $self->{POSTOP}   ||= '$(NOECHO) $(NOOP)'; # eg remove the distdir
632    $self->{TO_UNIX}  ||= '$(NOECHO) $(NOOP)';
633
634    $self->{CI}       ||= 'ci -u';
635    $self->{RCS_LABEL}||= 'rcs -Nv$(VERSION_SYM): -q';
636    $self->{DIST_CP}  ||= 'best';
637    $self->{DIST_DEFAULT} ||= 'tardist';
638
639    ($self->{DISTNAME} = $self->{NAME}) =~ s{::}{-}g unless $self->{DISTNAME};
640    $self->{DISTVNAME} ||= $self->{DISTNAME}.'-'.$self->{VERSION};
641}
642
643=item dist (o)
644
645  my $dist_macros = $mm->dist(%overrides);
646
647Generates a make fragment defining all the macros initialized in
648init_dist.
649
650%overrides can be used to override any of the above.
651
652=cut
653
654sub dist {
655    my($self, %attribs) = @_;
656
657    my $make = '';
658    if ( $attribs{SUFFIX} && $attribs{SUFFIX} !~ m!^\.! ) {
659      $attribs{SUFFIX} = '.' . $attribs{SUFFIX};
660    }
661    foreach my $key (qw(
662            TAR TARFLAGS ZIP ZIPFLAGS COMPRESS SUFFIX SHAR
663            PREOP POSTOP TO_UNIX
664            CI RCS_LABEL DIST_CP DIST_DEFAULT
665            DISTNAME DISTVNAME
666           ))
667    {
668        my $value = $attribs{$key} || $self->{$key};
669        $make .= "$key = $value\n";
670    }
671
672    return $make;
673}
674
675=item dist_basics (o)
676
677Defines the targets distclean, distcheck, skipcheck, manifest, veryclean.
678
679=cut
680
681sub dist_basics {
682    my($self) = shift;
683
684    return <<'MAKE_FRAG';
685distclean :: realclean distcheck
686	$(NOECHO) $(NOOP)
687
688distcheck :
689	$(PERLRUN) "-MExtUtils::Manifest=fullcheck" -e fullcheck
690
691skipcheck :
692	$(PERLRUN) "-MExtUtils::Manifest=skipcheck" -e skipcheck
693
694manifest :
695	$(PERLRUN) "-MExtUtils::Manifest=mkmanifest" -e mkmanifest
696
697veryclean : realclean
698	$(RM_F) *~ */*~ *.orig */*.orig *.bak */*.bak *.old */*.old
699
700MAKE_FRAG
701
702}
703
704=item dist_ci (o)
705
706Defines a check in target for RCS.
707
708=cut
709
710sub dist_ci {
711    my($self) = shift;
712    return sprintf "ci :\n\t%s\n", $self->oneliner(<<'EOF', [qw(-MExtUtils::Manifest=maniread)]);
713@all = sort keys %{ maniread() };
714print(qq{Executing $(CI) @all\n});
715system(qq{$(CI) @all}) == 0 or die $!;
716print(qq{Executing $(RCS_LABEL) ...\n});
717system(qq{$(RCS_LABEL) @all}) == 0 or die $!;
718EOF
719}
720
721=item dist_core (o)
722
723  my $dist_make_fragment = $MM->dist_core;
724
725Puts the targets necessary for 'make dist' together into one make
726fragment.
727
728=cut
729
730sub dist_core {
731    my($self) = shift;
732
733    my $make_frag = '';
734    foreach my $target (qw(dist tardist uutardist tarfile zipdist zipfile
735                           shdist))
736    {
737        my $method = $target.'_target';
738        $make_frag .= "\n";
739        $make_frag .= $self->$method();
740    }
741
742    return $make_frag;
743}
744
745
746=item B<dist_target>
747
748  my $make_frag = $MM->dist_target;
749
750Returns the 'dist' target to make an archive for distribution.  This
751target simply checks to make sure the Makefile is up-to-date and
752depends on $(DIST_DEFAULT).
753
754=cut
755
756sub dist_target {
757    my($self) = shift;
758
759    my $date_check = $self->oneliner(<<'CODE', ['-l']);
760print 'Warning: Makefile possibly out of date with $(VERSION_FROM)'
761    if -e '$(VERSION_FROM)' and -M '$(VERSION_FROM)' < -M '$(FIRST_MAKEFILE)';
762CODE
763
764    return sprintf <<'MAKE_FRAG', $date_check;
765dist : $(DIST_DEFAULT) $(FIRST_MAKEFILE)
766	$(NOECHO) %s
767MAKE_FRAG
768}
769
770=item B<tardist_target>
771
772  my $make_frag = $MM->tardist_target;
773
774Returns the 'tardist' target which is simply so 'make tardist' works.
775The real work is done by the dynamically named tardistfile_target()
776method, tardist should have that as a dependency.
777
778=cut
779
780sub tardist_target {
781    my($self) = shift;
782
783    return <<'MAKE_FRAG';
784tardist : $(DISTVNAME).tar$(SUFFIX)
785	$(NOECHO) $(NOOP)
786MAKE_FRAG
787}
788
789=item B<zipdist_target>
790
791  my $make_frag = $MM->zipdist_target;
792
793Returns the 'zipdist' target which is simply so 'make zipdist' works.
794The real work is done by the dynamically named zipdistfile_target()
795method, zipdist should have that as a dependency.
796
797=cut
798
799sub zipdist_target {
800    my($self) = shift;
801
802    return <<'MAKE_FRAG';
803zipdist : $(DISTVNAME).zip
804	$(NOECHO) $(NOOP)
805MAKE_FRAG
806}
807
808=item B<tarfile_target>
809
810  my $make_frag = $MM->tarfile_target;
811
812The name of this target is the name of the tarball generated by
813tardist.  This target does the actual work of turning the distdir into
814a tarball.
815
816=cut
817
818sub tarfile_target {
819    my($self) = shift;
820
821    return <<'MAKE_FRAG';
822$(DISTVNAME).tar$(SUFFIX) : distdir
823	$(PREOP)
824	$(TO_UNIX)
825	$(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
826	$(RM_RF) $(DISTVNAME)
827	$(COMPRESS) $(DISTVNAME).tar
828	$(NOECHO) $(ECHO) 'Created $(DISTVNAME).tar$(SUFFIX)'
829	$(POSTOP)
830MAKE_FRAG
831}
832
833=item zipfile_target
834
835  my $make_frag = $MM->zipfile_target;
836
837The name of this target is the name of the zip file generated by
838zipdist.  This target does the actual work of turning the distdir into
839a zip file.
840
841=cut
842
843sub zipfile_target {
844    my($self) = shift;
845
846    return <<'MAKE_FRAG';
847$(DISTVNAME).zip : distdir
848	$(PREOP)
849	$(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME)
850	$(RM_RF) $(DISTVNAME)
851	$(NOECHO) $(ECHO) 'Created $(DISTVNAME).zip'
852	$(POSTOP)
853MAKE_FRAG
854}
855
856=item uutardist_target
857
858  my $make_frag = $MM->uutardist_target;
859
860Converts the tarfile into a uuencoded file
861
862=cut
863
864sub uutardist_target {
865    my($self) = shift;
866
867    return <<'MAKE_FRAG';
868uutardist : $(DISTVNAME).tar$(SUFFIX)
869	uuencode $(DISTVNAME).tar$(SUFFIX) $(DISTVNAME).tar$(SUFFIX) > $(DISTVNAME).tar$(SUFFIX)_uu
870	$(NOECHO) $(ECHO) 'Created $(DISTVNAME).tar$(SUFFIX)_uu'
871MAKE_FRAG
872}
873
874
875=item shdist_target
876
877  my $make_frag = $MM->shdist_target;
878
879Converts the distdir into a shell archive.
880
881=cut
882
883sub shdist_target {
884    my($self) = shift;
885
886    return <<'MAKE_FRAG';
887shdist : distdir
888	$(PREOP)
889	$(SHAR) $(DISTVNAME) > $(DISTVNAME).shar
890	$(RM_RF) $(DISTVNAME)
891	$(NOECHO) $(ECHO) 'Created $(DISTVNAME).shar'
892	$(POSTOP)
893MAKE_FRAG
894}
895
896
897=item dlsyms (o)
898
899Used by some OS' to define DL_FUNCS and DL_VARS and write the *.exp files.
900
901Normally just returns an empty string.
902
903=cut
904
905sub dlsyms {
906    return '';
907}
908
909
910=item dynamic_bs (o)
911
912Defines targets for bootstrap files.
913
914=cut
915
916sub dynamic_bs {
917    my($self, %attribs) = @_;
918    return "\nBOOTSTRAP =\n" unless $self->has_link_code();
919    my @exts;
920    if ($self->{XSMULTI}) {
921	@exts = $self->_xs_list_basenames;
922    } else {
923	@exts = '$(BASEEXT)';
924    }
925    return join "\n",
926        "BOOTSTRAP = @{[map { qq{$_.bs} } @exts]}\n",
927        map { $self->_xs_make_bs($_) } @exts;
928}
929
930sub _xs_make_bs {
931    my ($self, $basename) = @_;
932    my ($v, $d, $f) = File::Spec->splitpath($basename);
933    my @d = File::Spec->splitdir($d);
934    shift @d if $self->{XSMULTI} and $d[0] eq 'lib';
935    my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
936    $instdir = '$(INST_ARCHAUTODIR)' if $basename eq '$(BASEEXT)';
937    my $instfile = $self->catfile($instdir, "$f.bs");
938    my $exists = "$instdir\$(DFSEP).exists"; # match blibdirs_target
939    #                                 1          2          3
940    return _sprintf562 <<'MAKE_FRAG', $basename, $instfile, $exists;
941# As Mkbootstrap might not write a file (if none is required)
942# we use touch to prevent make continually trying to remake it.
943# The DynaLoader only reads a non-empty file.
944%1$s.bs : $(FIRST_MAKEFILE) $(BOOTDEP)
945	$(NOECHO) $(ECHO) "Running Mkbootstrap for %1$s ($(BSLOADLIBS))"
946	$(NOECHO) $(PERLRUN) \
947		"-MExtUtils::Mkbootstrap" \
948		-e "Mkbootstrap('%1$s','$(BSLOADLIBS)');"
949	$(NOECHO) $(TOUCH) "%1$s.bs"
950	$(CHMOD) $(PERM_RW) "%1$s.bs"
951
952%2$s : %1$s.bs %3$s
953	$(NOECHO) $(RM_RF) %2$s
954	- $(CP_NONEMPTY) %1$s.bs %2$s $(PERM_RW)
955MAKE_FRAG
956}
957
958=item dynamic_lib (o)
959
960Defines how to produce the *.so (or equivalent) files.
961
962=cut
963
964sub dynamic_lib {
965    my($self, %attribs) = @_;
966    return '' unless $self->needs_linking(); #might be because of a subdir
967    return '' unless $self->has_link_code;
968    my @m = $self->xs_dynamic_lib_macros(\%attribs);
969    my @libs;
970    my $dlsyms_ext = eval { $self->xs_dlsyms_ext };
971    if ($self->{XSMULTI}) {
972        my @exts = $self->_xs_list_basenames;
973        for my $ext (@exts) {
974            my ($v, $d, $f) = File::Spec->splitpath($ext);
975            my @d = File::Spec->splitdir($d);
976            shift @d if $d[0] eq 'lib';
977            pop @d if $d[$#d] eq '';
978            my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
979
980            # Dynamic library names may need special handling.
981            eval { require DynaLoader };
982            if (defined &DynaLoader::mod2fname) {
983                $f = &DynaLoader::mod2fname([@d, $f]);
984            }
985
986            my $instfile = $self->catfile($instdir, "$f.\$(DLEXT)");
987            my $objfile = $self->_xsbuild_value('xs', $ext, 'OBJECT');
988            $objfile = "$ext\$(OBJ_EXT)" unless defined $objfile;
989            my $ldfrom = $self->_xsbuild_value('xs', $ext, 'LDFROM');
990            $ldfrom = $objfile unless defined $ldfrom;
991            my $exportlist = "$ext.def";
992            my @libchunk = ($objfile, $instfile, $instdir, $ldfrom, $exportlist);
993            push @libchunk, $dlsyms_ext ? $ext.$dlsyms_ext : undef;
994            push @libs, \@libchunk;
995        }
996    } else {
997        my @libchunk = qw($(OBJECT) $(INST_DYNAMIC) $(INST_ARCHAUTODIR) $(LDFROM) $(EXPORT_LIST));
998        push @libchunk, $dlsyms_ext ? '$(BASEEXT)'.$dlsyms_ext : undef;
999        @libs = (\@libchunk);
1000    }
1001    push @m, map { $self->xs_make_dynamic_lib(\%attribs, @$_); } @libs;
1002
1003    return join("\n",@m);
1004}
1005
1006=item xs_dynamic_lib_macros
1007
1008Defines the macros for the C<dynamic_lib> section.
1009
1010=cut
1011
1012sub xs_dynamic_lib_macros {
1013    my ($self, $attribs) = @_;
1014    my $otherldflags = $attribs->{OTHERLDFLAGS} || "";
1015    my $inst_dynamic_dep = $attribs->{INST_DYNAMIC_DEP} || "";
1016    my $armaybe = $self->_xs_armaybe($attribs);
1017    my $ld_opt = $Is{OS2} ? '$(OPTIMIZE) ' : ''; # Useful on other systems too?
1018    my $ld_fix = $Is{OS2} ? '|| ( $(RM_F) $@ && sh -c false )' : '';
1019    sprintf <<'EOF', $armaybe, $ld_opt.$otherldflags, $inst_dynamic_dep, $ld_fix;
1020# This section creates the dynamically loadable objects from relevant
1021# objects and possibly $(MYEXTLIB).
1022ARMAYBE = %s
1023OTHERLDFLAGS = %s
1024INST_DYNAMIC_DEP = %s
1025INST_DYNAMIC_FIX = %s
1026EOF
1027}
1028
1029sub _xs_armaybe {
1030    my ($self, $attribs) = @_;
1031    my $armaybe = $attribs->{ARMAYBE} || $self->{ARMAYBE} || ":";
1032    $armaybe = 'ar' if ($Is{OSF} and $armaybe eq ':');
1033    $armaybe;
1034}
1035
1036=item xs_make_dynamic_lib
1037
1038Defines the recipes for the C<dynamic_lib> section.
1039
1040=cut
1041
1042sub xs_make_dynamic_lib {
1043    my ($self, $attribs, $object, $to, $todir, $ldfrom, $exportlist, $dlsyms) = @_;
1044    $exportlist = '' if $exportlist ne '$(EXPORT_LIST)';
1045    my $armaybe = $self->_xs_armaybe($attribs);
1046    my @m = sprintf '%s : %s $(MYEXTLIB) %s$(DFSEP).exists %s $(PERL_ARCHIVEDEP) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP) %s'."\n", $to, $object, $todir, $exportlist, ($dlsyms || '');
1047    my $dlsyms_arg = $self->xs_dlsyms_arg($dlsyms);
1048    if ($armaybe ne ':'){
1049        $ldfrom = 'tmp$(LIB_EXT)';
1050        push(@m,"	\$(ARMAYBE) cr $ldfrom $object\n");
1051        push(@m,"	\$(RANLIB) $ldfrom\n");
1052    }
1053    $ldfrom = "-all $ldfrom -none" if $Is{OSF};
1054
1055    my $ldrun = '';
1056    # The IRIX linker doesn't use LD_RUN_PATH
1057    if ( $self->{LD_RUN_PATH} ) {
1058        if ( $Is{IRIX} ) {
1059            $ldrun = qq{-rpath "$self->{LD_RUN_PATH}"};
1060        }
1061        elsif ( $^O eq 'darwin' && $Is{AppleRPath} ) {
1062            # both clang and gcc support -Wl,-rpath, but only clang supports
1063            # -rpath so by using -Wl,-rpath we avoid having to check for the
1064            # type of compiler
1065            $ldrun = qq{-Wl,-rpath,"$self->{LD_RUN_PATH}"};
1066        }
1067    }
1068
1069    # For example in AIX the shared objects/libraries from previous builds
1070    # linger quite a while in the shared dynalinker cache even when nobody
1071    # is using them.  This is painful if one for instance tries to restart
1072    # a failed build because the link command will fail unnecessarily 'cos
1073    # the shared object/library is 'busy'.
1074    push(@m,"	\$(RM_F) \$\@\n");
1075
1076    my $libs = '$(LDLOADLIBS)';
1077    if (($Is{NetBSD} || $Is{Interix} || $Is{Android}) && $Config{'useshrplib'} eq 'true') {
1078        # Use nothing on static perl platforms, and to the flags needed
1079        # to link against the shared libperl library on shared perl
1080        # platforms.  We peek at lddlflags to see if we need -Wl,-R
1081        # or -R to add paths to the run-time library search path.
1082        if ($Config{'lddlflags'} =~ /-Wl,-R/) {
1083            $libs .= ' "-L$(PERL_INC)" "-Wl,-R$(INSTALLARCHLIB)/CORE" "-Wl,-R$(PERL_ARCHLIB)/CORE" -lperl';
1084        } elsif ($Config{'lddlflags'} =~ /-R/) {
1085            $libs .= ' "-L$(PERL_INC)" "-R$(INSTALLARCHLIB)/CORE" "-R$(PERL_ARCHLIB)/CORE" -lperl';
1086        } elsif ( $Is{Android} ) {
1087            # The Android linker will not recognize symbols from
1088            # libperl unless the module explicitly depends on it.
1089            $libs .= ' "-L$(PERL_INC)" -lperl';
1090        }
1091    }
1092
1093    my $ld_run_path_shell = "";
1094    if ($self->{LD_RUN_PATH} ne "") {
1095        $ld_run_path_shell = 'LD_RUN_PATH="$(LD_RUN_PATH)" ';
1096    }
1097
1098    push @m, sprintf <<'MAKE', $ld_run_path_shell, $ldrun, $dlsyms_arg, $ldfrom, $self->xs_obj_opt('$@'), $libs, $exportlist;
1099	%s$(LD) %s $(LDDLFLAGS) %s %s $(OTHERLDFLAGS) %s $(MYEXTLIB) \
1100	  $(PERL_ARCHIVE) %s $(PERL_ARCHIVE_AFTER) %s \
1101	  $(INST_DYNAMIC_FIX)
1102	$(CHMOD) $(PERM_RWX) $@
1103MAKE
1104    join '', @m;
1105}
1106
1107=item exescan
1108
1109Deprecated method. Use libscan instead.
1110
1111=cut
1112
1113sub exescan {
1114    my($self,$path) = @_;
1115    $path;
1116}
1117
1118=item extliblist
1119
1120Called by init_others, and calls ext ExtUtils::Liblist. See
1121L<ExtUtils::Liblist> for details.
1122
1123=cut
1124
1125sub extliblist {
1126    my($self,$libs) = @_;
1127    require ExtUtils::Liblist;
1128    $self->ext($libs, $Verbose);
1129}
1130
1131=item find_perl
1132
1133Finds the executables PERL and FULLPERL
1134
1135=cut
1136
1137sub find_perl {
1138    my($self, $ver, $names, $dirs, $trace) = @_;
1139    if ($trace >= 2){
1140        print "Looking for perl $ver by these names:
1141@$names
1142in these dirs:
1143@$dirs
1144";
1145    }
1146
1147    my $stderr_duped = 0;
1148    local *STDERR_COPY;
1149
1150    unless ($Is{BSD}) {
1151        # >& and lexical filehandles together give 5.6.2 indigestion
1152        if( open(STDERR_COPY, '>&STDERR') ) {  ## no critic
1153            $stderr_duped = 1;
1154        }
1155        else {
1156            warn <<WARNING;
1157find_perl() can't dup STDERR: $!
1158You might see some garbage while we search for Perl
1159WARNING
1160        }
1161    }
1162
1163    foreach my $name (@$names){
1164        my ($abs, $use_dir);
1165        if ($self->file_name_is_absolute($name)) {     # /foo/bar
1166            $abs = $name;
1167        } elsif ($self->canonpath($name) eq
1168                 $self->canonpath(basename($name))) {  # foo
1169            $use_dir = 1;
1170        } else {                                            # foo/bar
1171            $abs = $self->catfile($Curdir, $name);
1172        }
1173        foreach my $dir ($use_dir ? @$dirs : 1){
1174            next unless defined $dir; # $self->{PERL_SRC} may be undefined
1175
1176            $abs = $self->catfile($dir, $name)
1177                if $use_dir;
1178
1179            print "Checking $abs\n" if ($trace >= 2);
1180            next unless $self->maybe_command($abs);
1181            print "Executing $abs\n" if ($trace >= 2);
1182
1183            my $val;
1184            my $version_check = qq{"$abs" -le "require $ver; print qq{VER_OK}"};
1185
1186            # To avoid using the unportable 2>&1 to suppress STDERR,
1187            # we close it before running the command.
1188            # However, thanks to a thread library bug in many BSDs
1189            # ( http://www.freebsd.org/cgi/query-pr.cgi?pr=51535 )
1190            # we cannot use the fancier more portable way in here
1191            # but instead need to use the traditional 2>&1 construct.
1192            if ($Is{BSD}) {
1193                $val = `$version_check 2>&1`;
1194            } else {
1195                close STDERR if $stderr_duped;
1196                $val = `$version_check`;
1197
1198                # 5.6.2's 3-arg open doesn't work with >&
1199                open STDERR, ">&STDERR_COPY"  ## no critic
1200                        if $stderr_duped;
1201            }
1202
1203            if ($val =~ /^VER_OK/m) {
1204                print "Using PERL=$abs\n" if $trace;
1205                return $abs;
1206            } elsif ($trace >= 2) {
1207                print "Result: '$val' ".($? >> 8)."\n";
1208            }
1209        }
1210    }
1211    print "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
1212    0; # false and not empty
1213}
1214
1215
1216=item fixin
1217
1218  $mm->fixin(@files);
1219
1220Inserts the sharpbang or equivalent magic number to a set of @files.
1221
1222=cut
1223
1224sub fixin {    # stolen from the pink Camel book, more or less
1225    my ( $self, @files ) = @_;
1226
1227    for my $file (@files) {
1228        my $file_new = "$file.new";
1229        my $file_bak = "$file.bak";
1230
1231        open( my $fixin, '<', $file ) or croak "Can't process '$file': $!";
1232        local $/ = "\n";
1233        chomp( my $line = <$fixin> );
1234        next unless $line =~ s/^\s*\#!\s*//;    # Not a shebang file.
1235
1236        my $shb = $self->_fixin_replace_shebang( $file, $line );
1237        next unless defined $shb;
1238
1239        open( my $fixout, ">", "$file_new" ) or do {
1240            warn "Can't create new $file: $!\n";
1241            next;
1242        };
1243
1244        # Print out the new #! line (or equivalent).
1245        local $\;
1246        local $/;
1247        print $fixout $shb, <$fixin>;
1248        close $fixin;
1249        close $fixout;
1250
1251        chmod 0666, $file_bak;
1252        unlink $file_bak;
1253        unless ( _rename( $file, $file_bak ) ) {
1254            warn "Can't rename $file to $file_bak: $!";
1255            next;
1256        }
1257        unless ( _rename( $file_new, $file ) ) {
1258            warn "Can't rename $file_new to $file: $!";
1259            unless ( _rename( $file_bak, $file ) ) {
1260                warn "Can't rename $file_bak back to $file either: $!";
1261                warn "Leaving $file renamed as $file_bak\n";
1262            }
1263            next;
1264        }
1265        unlink $file_bak;
1266    }
1267    continue {
1268        system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
1269    }
1270}
1271
1272
1273sub _rename {
1274    my($old, $new) = @_;
1275
1276    foreach my $file ($old, $new) {
1277        if( $Is{VMS} and basename($file) !~ /\./ ) {
1278            # rename() in 5.8.0 on VMS will not rename a file if it
1279            # does not contain a dot yet it returns success.
1280            $file = "$file.";
1281        }
1282    }
1283
1284    return rename($old, $new);
1285}
1286
1287sub _fixin_replace_shebang {
1288    my ( $self, $file, $line ) = @_;
1289
1290    # Now figure out the interpreter name.
1291    my ( $origcmd, $arg ) = split ' ', $line, 2;
1292    (my $cmd = $origcmd) =~ s!^.*/!!;
1293
1294    # Now look (in reverse) for interpreter in absolute PATH (unless perl).
1295    my $interpreter;
1296    if ( defined $ENV{PERL_MM_SHEBANG} && $ENV{PERL_MM_SHEBANG} eq "relocatable" ) {
1297        $interpreter = "/usr/bin/env perl";
1298    }
1299    elsif ( $cmd =~ m{^perl(?:\z|[^a-z])} ) {
1300        if ( $Config{startperl} =~ m,^\#!.*/perl, ) {
1301            $interpreter = $Config{startperl};
1302            $interpreter =~ s,^\#!,,;
1303        }
1304        else {
1305            $interpreter = $Config{perlpath};
1306        }
1307    }
1308    else {
1309        my (@absdirs)
1310            = reverse grep { $self->file_name_is_absolute($_) } $self->path;
1311        $interpreter = '';
1312
1313        foreach my $dir (@absdirs) {
1314            my $maybefile = $self->catfile($dir,$cmd);
1315            if ( $self->maybe_command($maybefile) ) {
1316                warn "Ignoring $interpreter in $file\n"
1317                    if $Verbose && $interpreter;
1318                $interpreter = $maybefile;
1319            }
1320        }
1321
1322        # If the shebang is absolute and exists in PATH, but was not
1323        # the first one found, leave it alone if it's actually the
1324        # same file as first one.  This avoids packages built on
1325        # merged-/usr systems with /usr/bin before /bin in the path
1326        # breaking when installed on systems without merged /usr
1327        if ($origcmd ne $interpreter and $self->file_name_is_absolute($origcmd)) {
1328            my $origdir = dirname($origcmd);
1329            if ($self->maybe_command($origcmd) && grep { $_ eq $origdir } @absdirs) {
1330                my ($odev, $oino) = stat $origcmd;
1331                my ($idev, $iino) = stat $interpreter;
1332                if ($odev == $idev && $oino eq $iino) {
1333                    warn "$origcmd is the same as $interpreter, leaving alone"
1334                        if $Verbose;
1335                    $interpreter = $origcmd;
1336                }
1337            }
1338        }
1339    }
1340
1341    # Figure out how to invoke interpreter on this machine.
1342
1343    my ($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/;
1344    my ($shb) = "";
1345    if ($interpreter) {
1346        print "Changing sharpbang in $file to $interpreter"
1347            if $Verbose;
1348         # this is probably value-free on DOSISH platforms
1349        if ($does_shbang) {
1350            $shb .= "$Config{'sharpbang'}$interpreter";
1351            $shb .= ' ' . $arg if defined $arg;
1352            $shb .= "\n";
1353        }
1354    }
1355    else {
1356        warn "Can't find $cmd in PATH, $file unchanged"
1357            if $Verbose;
1358        return;
1359    }
1360    return $shb
1361}
1362
1363=item force (o)
1364
1365Writes an empty FORCE: target.
1366
1367=cut
1368
1369sub force {
1370    my($self) = shift;
1371    '# Phony target to force checking subdirectories.
1372FORCE :
1373	$(NOECHO) $(NOOP)
1374';
1375}
1376
1377=item guess_name
1378
1379Guess the name of this package by examining the working directory's
1380name. MakeMaker calls this only if the developer has not supplied a
1381NAME attribute.
1382
1383=cut
1384
1385# ';
1386
1387sub guess_name {
1388    my($self) = @_;
1389    use Cwd 'cwd';
1390    my $name = basename(cwd());
1391    $name =~ s|[\-_][\d\.\-]+\z||;  # this is new with MM 5.00, we
1392                                    # strip minus or underline
1393                                    # followed by a float or some such
1394    print "Warning: Guessing NAME [$name] from current directory name.\n";
1395    $name;
1396}
1397
1398=item has_link_code
1399
1400Returns true if C, XS, MYEXTLIB or similar objects exist within this
1401object that need a compiler. Does not descend into subdirectories as
1402needs_linking() does.
1403
1404=cut
1405
1406sub has_link_code {
1407    my($self) = shift;
1408    return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE};
1409    if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){
1410	$self->{HAS_LINK_CODE} = 1;
1411	return 1;
1412    }
1413    return $self->{HAS_LINK_CODE} = 0;
1414}
1415
1416
1417=item init_dirscan
1418
1419Scans the directory structure and initializes DIR, XS, XS_FILES,
1420C, C_FILES, O_FILES, H, H_FILES, PL_FILES, EXE_FILES.
1421
1422Called by init_main.
1423
1424=cut
1425
1426sub init_dirscan {	# --- File and Directory Lists (.xs .pm .pod etc)
1427    my($self) = @_;
1428    my(%dir, %xs, %c, %o, %h, %pl_files, %pm);
1429
1430    my %ignore = map {( $_ => 1 )} qw(Makefile.PL Build.PL test.pl t);
1431
1432    # ignore the distdir
1433    $Is{VMS} ? $ignore{"$self->{DISTVNAME}.dir"} = 1
1434            : $ignore{$self->{DISTVNAME}} = 1;
1435
1436    my $distprefix = $Is{VMS} ? qr/^\Q$self->{DISTNAME}\E-v?[\d\.]+\.dir$/i
1437                              : qr/^\Q$self->{DISTNAME}\E-v?[\d\.]+$/;
1438
1439    @ignore{map lc, keys %ignore} = values %ignore if $Is{VMS};
1440
1441    if ( defined $self->{XS} and !defined $self->{C} ) {
1442	my @c_files = grep { m/\.c(pp|xx)?\z/i } values %{$self->{XS}};
1443	my @o_files = grep { m/(?:.(?:o(?:bj)?)|\$\(OBJ_EXT\))\z/i } values %{$self->{XS}};
1444	%c = map { $_ => 1 } @c_files;
1445	%o = map { $_ => 1 } @o_files;
1446    }
1447
1448    foreach my $name ($self->lsdir($Curdir)){
1449	next if $name =~ /\#/;
1450	next if $name =~ $distprefix && -d $name;
1451	$name = lc($name) if $Is{VMS};
1452	next if $name eq $Curdir or $name eq $Updir or $ignore{$name};
1453	next unless $self->libscan($name);
1454	if (-d $name){
1455	    next if -l $name; # We do not support symlinks at all
1456            next if $self->{NORECURS};
1457	    $dir{$name} = $name if (-f $self->catfile($name,"Makefile.PL"));
1458	} elsif ($name =~ /\.xs\z/){
1459	    my($c); ($c = $name) =~ s/\.xs\z/.c/;
1460	    $xs{$name} = $c;
1461	    $c{$c} = 1;
1462	} elsif ($name =~ /\.c(pp|xx|c)?\z/i){  # .c .C .cpp .cxx .cc
1463	    $c{$name} = 1
1464		unless $name =~ m/perlmain\.c/; # See MAP_TARGET
1465	} elsif ($name =~ /\.h\z/i){
1466	    $h{$name} = 1;
1467	} elsif ($name =~ /\.PL\z/) {
1468	    ($pl_files{$name} = $name) =~ s/\.PL\z// ;
1469	} elsif (($Is{VMS} || $Is{Dos}) && $name =~ /[._]pl$/i) {
1470	    # case-insensitive filesystem, one dot per name, so foo.h.PL
1471	    # under Unix appears as foo.h_pl under VMS or fooh.pl on Dos
1472	    local($/); open(my $pl, '<', $name); my $txt = <$pl>; close $pl;
1473	    if ($txt =~ /Extracting \S+ \(with variable substitutions/) {
1474		($pl_files{$name} = $name) =~ s/[._]pl\z//i ;
1475	    }
1476	    else {
1477                $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name);
1478            }
1479	} elsif ($name =~ /\.(p[ml]|pod)\z/){
1480	    $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name);
1481	}
1482    }
1483
1484    $self->{PL_FILES}   ||= \%pl_files;
1485    $self->{DIR}        ||= [sort keys %dir];
1486    $self->{XS}         ||= \%xs;
1487    $self->{C}          ||= [sort keys %c];
1488    $self->{H}          ||= [sort keys %h];
1489    $self->{PM}         ||= \%pm;
1490
1491    my @o_files = @{$self->{C}};
1492    %o = (%o, map { $_ => 1 } grep s/\.c(pp|xx|c)?\z/$self->{OBJ_EXT}/i, @o_files);
1493    $self->{O_FILES} = [sort keys %o];
1494}
1495
1496
1497=item init_MANPODS
1498
1499Determines if man pages should be generated and initializes MAN1PODS
1500and MAN3PODS as appropriate.
1501
1502=cut
1503
1504sub init_MANPODS {
1505    my $self = shift;
1506
1507    # Set up names of manual pages to generate from pods
1508    foreach my $man (qw(MAN1 MAN3)) {
1509        if ( $self->{"${man}PODS"}
1510             or $self->{"INSTALL${man}DIR"} =~ /^(none|\s*)$/
1511        ) {
1512            $self->{"${man}PODS"} ||= {};
1513        }
1514        else {
1515            my $init_method = "init_${man}PODS";
1516            $self->$init_method();
1517        }
1518    }
1519
1520    # logic similar to picking man${num}ext in perl's Configure script
1521    foreach my $num (1,3) {
1522        my $installdirs = uc $self->{INSTALLDIRS};
1523        $installdirs = '' if $installdirs eq 'PERL';
1524        my @mandirs = File::Spec->splitdir( $self->_expand_macros(
1525            $self->{ "INSTALL${installdirs}MAN${num}DIR" } ) );
1526        my $mandir = pop @mandirs;
1527        my $section = $num;
1528
1529        foreach ($num, "${num}p", "${num}pm", qw< l n o C L >, "L$num") {
1530            if ( $mandir =~ /^(?:man|cat)$_$/ ) {
1531                $section = $_;
1532                last;
1533            }
1534        }
1535
1536        $self->{"MAN${num}SECTION"} = $section;
1537    }
1538}
1539
1540
1541sub _has_pod {
1542    my($self, $file) = @_;
1543
1544    my($ispod)=0;
1545    if (open( my $fh, '<', $file )) {
1546        while (<$fh>) {
1547            if (/^=(?:head\d+|item|pod)\b/) {
1548                $ispod=1;
1549                last;
1550            }
1551        }
1552        close $fh;
1553    } else {
1554        # If it doesn't exist yet, we assume, it has pods in it
1555        $ispod = 1;
1556    }
1557
1558    return $ispod;
1559}
1560
1561
1562=item init_MAN1PODS
1563
1564Initializes MAN1PODS from the list of EXE_FILES.
1565
1566=cut
1567
1568sub init_MAN1PODS {
1569    my($self) = @_;
1570
1571    if ( exists $self->{EXE_FILES} ) {
1572	foreach my $name (@{$self->{EXE_FILES}}) {
1573	    next unless $self->_has_pod($name);
1574
1575	    $self->{MAN1PODS}->{$name} =
1576		$self->catfile("\$(INST_MAN1DIR)",
1577			       basename($name).".\$(MAN1EXT)");
1578	}
1579    }
1580}
1581
1582
1583=item init_MAN3PODS
1584
1585Initializes MAN3PODS from the list of PM files.
1586
1587=cut
1588
1589sub init_MAN3PODS {
1590    my $self = shift;
1591
1592    my %manifypods = (); # we collect the keys first, i.e. the files
1593                         # we have to convert to pod
1594
1595    foreach my $name (keys %{$self->{PM}}) {
1596	if ($name =~ /\.pod\z/ ) {
1597	    $manifypods{$name} = $self->{PM}{$name};
1598	} elsif ($name =~ /\.p[ml]\z/ ) {
1599	    if( $self->_has_pod($name) ) {
1600		$manifypods{$name} = $self->{PM}{$name};
1601	    }
1602	}
1603    }
1604
1605    my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
1606
1607    # Remove "Configure.pm" and similar, if it's not the only pod listed
1608    # To force inclusion, just name it "Configure.pod", or override
1609    # MAN3PODS
1610    foreach my $name (keys %manifypods) {
1611	if (
1612            ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) or
1613            ( $name =~ m/^README\.pod$/i ) # don't manify top-level README.pod
1614        ) {
1615	    delete $manifypods{$name};
1616	    next;
1617	}
1618	my($manpagename) = $name;
1619	$manpagename =~ s/\.p(od|m|l)\z//;
1620	# everything below lib is ok
1621	unless($manpagename =~ s!^\W*($parentlibs_re)\W+!!s) {
1622	    $manpagename = $self->catfile(
1623	        split(/::/,$self->{PARENT_NAME}),$manpagename
1624	    );
1625	}
1626	$manpagename = $self->replace_manpage_separator($manpagename);
1627	$self->{MAN3PODS}->{$name} =
1628	    $self->catfile("\$(INST_MAN3DIR)", "$manpagename.\$(MAN3EXT)");
1629    }
1630}
1631
1632
1633=item init_PM
1634
1635Initializes PMLIBDIRS and PM from PMLIBDIRS.
1636
1637=cut
1638
1639sub init_PM {
1640    my $self = shift;
1641
1642    # Some larger extensions often wish to install a number of *.pm/pl
1643    # files into the library in various locations.
1644
1645    # The attribute PMLIBDIRS holds an array reference which lists
1646    # subdirectories which we should search for library files to
1647    # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ].  We
1648    # recursively search through the named directories (skipping any
1649    # which don't exist or contain Makefile.PL files).
1650
1651    # For each *.pm or *.pl file found $self->libscan() is called with
1652    # the default installation path in $_[1]. The return value of
1653    # libscan defines the actual installation location.  The default
1654    # libscan function simply returns the path.  The file is skipped
1655    # if libscan returns false.
1656
1657    # The default installation location passed to libscan in $_[1] is:
1658    #
1659    #  ./*.pm		=> $(INST_LIBDIR)/*.pm
1660    #  ./xyz/...	=> $(INST_LIBDIR)/xyz/...
1661    #  ./lib/...	=> $(INST_LIB)/...
1662    #
1663    # In this way the 'lib' directory is seen as the root of the actual
1664    # perl library whereas the others are relative to INST_LIBDIR
1665    # (which includes PARENT_NAME). This is a subtle distinction but one
1666    # that's important for nested modules.
1667
1668    unless( $self->{PMLIBDIRS} ) {
1669        if( $Is{VMS} ) {
1670            # Avoid logical name vs directory collisions
1671            $self->{PMLIBDIRS} = ['./lib', "./$self->{BASEEXT}"];
1672        }
1673        else {
1674            $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}];
1675        }
1676    }
1677
1678    #only existing directories that aren't in $dir are allowed
1679
1680    # Avoid $_ wherever possible:
1681    # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
1682    my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
1683    @{$self->{PMLIBDIRS}} = ();
1684    my %dir = map { ($_ => $_) } @{$self->{DIR}};
1685    foreach my $pmlibdir (@pmlibdirs) {
1686	-d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
1687    }
1688
1689    unless( $self->{PMLIBPARENTDIRS} ) {
1690	@{$self->{PMLIBPARENTDIRS}} = ('lib');
1691    }
1692
1693    return if $self->{PM} and $self->{ARGS}{PM};
1694
1695    if (@{$self->{PMLIBDIRS}}){
1696	print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
1697	    if ($Verbose >= 2);
1698	require File::Find;
1699        File::Find::find(sub {
1700            if (-d $_){
1701                unless ($self->libscan($_)){
1702                    $File::Find::prune = 1;
1703                }
1704                return;
1705            }
1706            return if /\#/;
1707            return if /~$/;             # emacs temp files
1708            return if /,v$/;            # RCS files
1709            return if m{\.swp$};        # vim swap files
1710
1711	    my $path   = $File::Find::name;
1712            my $prefix = $self->{INST_LIBDIR};
1713            my $striplibpath;
1714
1715	    my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
1716	    $prefix =  $self->{INST_LIB}
1717                if ($striplibpath = $path) =~ s{^(\W*)($parentlibs_re)\W}
1718	                                       {$1}i;
1719
1720	    my($inst) = $self->catfile($prefix,$striplibpath);
1721	    local($_) = $inst; # for backwards compatibility
1722	    $inst = $self->libscan($inst);
1723	    print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
1724	    return unless $inst;
1725	    if ($self->{XSMULTI} and $inst =~ /\.xs\z/) {
1726		my($base); ($base = $path) =~ s/\.xs\z//;
1727		$self->{XS}{$path} = "$base.c";
1728		push @{$self->{C}}, "$base.c";
1729		push @{$self->{O_FILES}}, "$base$self->{OBJ_EXT}";
1730	    } else {
1731		$self->{PM}{$path} = $inst;
1732	    }
1733	}, @{$self->{PMLIBDIRS}});
1734    }
1735}
1736
1737
1738=item init_DIRFILESEP
1739
1740Using / for Unix.  Called by init_main.
1741
1742=cut
1743
1744sub init_DIRFILESEP {
1745    my($self) = shift;
1746
1747    $self->{DIRFILESEP} = '/';
1748}
1749
1750
1751=item init_main
1752
1753Initializes AR, AR_STATIC_ARGS, BASEEXT, CONFIG, DISTNAME, DLBASE,
1754EXE_EXT, FULLEXT, FULLPERL, FULLPERLRUN, FULLPERLRUNINST, INST_*,
1755INSTALL*, INSTALLDIRS, LIB_EXT, LIBPERL_A, MAP_TARGET, NAME,
1756OBJ_EXT, PARENT_NAME, PERL, PERL_ARCHLIB, PERL_INC, PERL_LIB,
1757PERL_SRC, PERLRUN, PERLRUNINST, PREFIX, VERSION,
1758VERSION_SYM, XS_VERSION.
1759
1760=cut
1761
1762sub init_main {
1763    my($self) = @_;
1764
1765    # --- Initialize Module Name and Paths
1766
1767    # NAME    = Foo::Bar::Oracle
1768    # FULLEXT = Foo/Bar/Oracle
1769    # BASEEXT = Oracle
1770    # PARENT_NAME = Foo::Bar
1771### Only UNIX:
1772###    ($self->{FULLEXT} =
1773###     $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket
1774    $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME});
1775
1776
1777    # Copied from DynaLoader:
1778
1779    my(@modparts) = split(/::/,$self->{NAME});
1780    my($modfname) = $modparts[-1];
1781
1782    # Some systems have restrictions on files names for DLL's etc.
1783    # mod2fname returns appropriate file base name (typically truncated)
1784    # It may also edit @modparts if required.
1785    # We require DynaLoader to make sure that mod2fname is loaded
1786    eval { require DynaLoader };
1787    if (defined &DynaLoader::mod2fname) {
1788        $modfname = &DynaLoader::mod2fname(\@modparts);
1789    }
1790
1791    ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!(?:([\w:]+)::)?(\w+)\z! ;
1792    $self->{PARENT_NAME} ||= '';
1793
1794    if (defined &DynaLoader::mod2fname) {
1795	# As of 5.001m, dl_os2 appends '_'
1796	$self->{DLBASE} = $modfname;
1797    } else {
1798	$self->{DLBASE} = '$(BASEEXT)';
1799    }
1800
1801
1802    # --- Initialize PERL_LIB, PERL_SRC
1803
1804    # *Real* information: where did we get these two from? ...
1805    my $inc_config_dir = dirname($INC{'Config.pm'});
1806    my $inc_carp_dir   = dirname($INC{'Carp.pm'});
1807
1808    unless ($self->{PERL_SRC}){
1809        foreach my $dir_count (1..8) { # 8 is the VMS limit for nesting
1810            my $dir = $self->catdir(($Updir) x $dir_count);
1811
1812            if (-f $self->catfile($dir,"config_h.SH")   &&
1813                -f $self->catfile($dir,"perl.h")        &&
1814                -f $self->catfile($dir,"lib","strict.pm")
1815            ) {
1816                $self->{PERL_SRC}=$dir ;
1817                last;
1818            }
1819        }
1820    }
1821
1822    warn "PERL_CORE is set but I can't find your PERL_SRC!\n" if
1823      $self->{PERL_CORE} and !$self->{PERL_SRC};
1824
1825    if ($self->{PERL_SRC}){
1826	$self->{PERL_LIB}     ||= $self->catdir("$self->{PERL_SRC}","lib");
1827
1828        $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
1829        $self->{PERL_INC}     = ($Is{Win32}) ?
1830            $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
1831
1832	# catch a situation that has occurred a few times in the past:
1833	unless (
1834		-s $self->catfile($self->{PERL_SRC},'cflags')
1835		or
1836		$Is{VMS}
1837		&&
1838		-s $self->catfile($self->{PERL_SRC},'vmsish.h')
1839		or
1840		$Is{Win32}
1841	       ){
1842	    warn qq{
1843You cannot build extensions below the perl source tree after executing
1844a 'make clean' in the perl source tree.
1845
1846To rebuild extensions distributed with the perl source you should
1847simply Configure (to include those extensions) and then build perl as
1848normal. After installing perl the source tree can be deleted. It is
1849not needed for building extensions by running 'perl Makefile.PL'
1850usually without extra arguments.
1851
1852It is recommended that you unpack and build additional extensions away
1853from the perl source tree.
1854};
1855	}
1856    } else {
1857	# we should also consider $ENV{PERL5LIB} here
1858        my $old = $self->{PERL_LIB} || $self->{PERL_ARCHLIB} || $self->{PERL_INC};
1859	$self->{PERL_LIB}     ||= $Config{privlibexp};
1860	$self->{PERL_ARCHLIB} ||= $Config{archlibexp};
1861	$self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
1862	my $perl_h;
1863
1864	if (not -f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))
1865	    and not $old){
1866	    # Maybe somebody tries to build an extension with an
1867	    # uninstalled Perl outside of Perl build tree
1868	    my $lib;
1869	    for my $dir (@INC) {
1870	      $lib = $dir, last if -e $self->catfile($dir, "Config.pm");
1871	    }
1872	    if ($lib) {
1873              # Win32 puts its header files in /perl/src/lib/CORE.
1874              # Unix leaves them in /perl/src.
1875	      my $inc = $Is{Win32} ? $self->catdir($lib, "CORE" )
1876                                  : dirname $lib;
1877	      if (-e $self->catfile($inc, "perl.h")) {
1878		$self->{PERL_LIB}	   = $lib;
1879		$self->{PERL_ARCHLIB}	   = $lib;
1880		$self->{PERL_INC}	   = $inc;
1881		$self->{UNINSTALLED_PERL}  = 1;
1882		print <<EOP;
1883... Detected uninstalled Perl.  Trying to continue.
1884EOP
1885	      }
1886	    }
1887	}
1888    }
1889
1890    if ($Is{Android}) {
1891    	# Android fun times!
1892    	# ../../perl -I../../lib -MFile::Glob -e1 works
1893    	# ../../../perl -I../../../lib -MFile::Glob -e1 fails to find
1894    	# the .so for File::Glob.
1895    	# This always affects core perl, but may also affect an installed
1896    	# perl built with -Duserelocatableinc.
1897    	$self->{PERL_LIB} = File::Spec->rel2abs($self->{PERL_LIB});
1898    	$self->{PERL_ARCHLIB} = File::Spec->rel2abs($self->{PERL_ARCHLIB});
1899    }
1900    $self->{PERL_INCDEP} = $self->{PERL_INC};
1901    $self->{PERL_ARCHLIBDEP} = $self->{PERL_ARCHLIB};
1902
1903    # We get SITELIBEXP and SITEARCHEXP directly via
1904    # Get_from_Config. When we are running standard modules, these
1905    # won't matter, we will set INSTALLDIRS to "perl". Otherwise we
1906    # set it to "site". I prefer that INSTALLDIRS be set from outside
1907    # MakeMaker.
1908    $self->{INSTALLDIRS} ||= "site";
1909
1910    $self->{MAN1EXT} ||= $Config{man1ext};
1911    $self->{MAN3EXT} ||= $Config{man3ext};
1912
1913    # Get some stuff out of %Config if we haven't yet done so
1914    print "CONFIG must be an array ref\n"
1915        if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
1916    $self->{CONFIG} = [] unless (ref $self->{CONFIG});
1917    push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
1918    push(@{$self->{CONFIG}}, 'shellflags') if $Config{shellflags};
1919    my(%once_only);
1920    foreach my $m (@{$self->{CONFIG}}){
1921        next if $once_only{$m};
1922        print "CONFIG key '$m' does not exist in Config.pm\n"
1923                unless exists $Config{$m};
1924        $self->{uc $m} ||= $Config{$m};
1925        $once_only{$m} = 1;
1926    }
1927
1928# This is too dangerous:
1929#    if ($^O eq "next") {
1930#	$self->{AR} = "libtool";
1931#	$self->{AR_STATIC_ARGS} = "-o";
1932#    }
1933# But I leave it as a placeholder
1934
1935    $self->{AR_STATIC_ARGS} ||= "cr";
1936
1937    # These should never be needed
1938    $self->{OBJ_EXT} ||= '.o';
1939    $self->{LIB_EXT} ||= '.a';
1940
1941    $self->{MAP_TARGET} ||= "perl";
1942
1943    $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
1944
1945    # make a simple check if we find strict
1946    warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
1947        (strict.pm not found)"
1948        unless -f $self->catfile("$self->{PERL_LIB}","strict.pm") ||
1949               $self->{NAME} eq "ExtUtils::MakeMaker";
1950}
1951
1952=item init_tools
1953
1954Initializes tools to use their common (and faster) Unix commands.
1955
1956=cut
1957
1958sub init_tools {
1959    my $self = shift;
1960
1961    $self->{ECHO}       ||= 'echo';
1962    $self->{ECHO_N}     ||= 'echo -n';
1963    $self->{RM_F}       ||= "rm -f";
1964    $self->{RM_RF}      ||= "rm -rf";
1965    $self->{TOUCH}      ||= "touch";
1966    $self->{TEST_F}     ||= "test -f";
1967    $self->{TEST_S}     ||= "test -s";
1968    $self->{CP}         ||= "cp";
1969    $self->{MV}         ||= "mv";
1970    $self->{CHMOD}      ||= "chmod";
1971    $self->{FALSE}      ||= 'false';
1972    $self->{TRUE}       ||= 'true';
1973
1974    $self->{LD}         ||= 'ld';
1975
1976    return $self->SUPER::init_tools(@_);
1977
1978    # After SUPER::init_tools so $Config{shell} has a
1979    # chance to get set.
1980    $self->{SHELL}      ||= '/bin/sh';
1981
1982    return;
1983}
1984
1985
1986=item init_linker
1987
1988Unix has no need of special linker flags.
1989
1990=cut
1991
1992sub init_linker {
1993    my($self) = shift;
1994    $self->{PERL_ARCHIVE} ||= '';
1995    $self->{PERL_ARCHIVEDEP} ||= '';
1996    $self->{PERL_ARCHIVE_AFTER} ||= '';
1997    $self->{EXPORT_LIST}  ||= '';
1998}
1999
2000
2001=begin _protected
2002
2003=item init_lib2arch
2004
2005    $mm->init_lib2arch
2006
2007=end _protected
2008
2009=cut
2010
2011sub init_lib2arch {
2012    my($self) = shift;
2013
2014    # The user who requests an installation directory explicitly
2015    # should not have to tell us an architecture installation directory
2016    # as well. We look if a directory exists that is named after the
2017    # architecture. If not we take it as a sign that it should be the
2018    # same as the requested installation directory. Otherwise we take
2019    # the found one.
2020    for my $libpair ({l=>"privlib",   a=>"archlib"},
2021                     {l=>"sitelib",   a=>"sitearch"},
2022                     {l=>"vendorlib", a=>"vendorarch"},
2023                    )
2024    {
2025        my $lib = "install$libpair->{l}";
2026        my $Lib = uc $lib;
2027        my $Arch = uc "install$libpair->{a}";
2028        if( $self->{$Lib} && ! $self->{$Arch} ){
2029            my($ilib) = $Config{$lib};
2030
2031            $self->prefixify($Arch,$ilib,$self->{$Lib});
2032
2033            unless (-d $self->{$Arch}) {
2034                print "Directory $self->{$Arch} not found\n"
2035                  if $Verbose;
2036                $self->{$Arch} = $self->{$Lib};
2037            }
2038            print "Defaulting $Arch to $self->{$Arch}\n" if $Verbose;
2039        }
2040    }
2041}
2042
2043
2044=item init_PERL
2045
2046    $mm->init_PERL;
2047
2048Called by init_main.  Sets up ABSPERL, PERL, FULLPERL and all the
2049*PERLRUN* permutations.
2050
2051    PERL is allowed to be miniperl
2052    FULLPERL must be a complete perl
2053
2054    ABSPERL is PERL converted to an absolute path
2055
2056    *PERLRUN contains everything necessary to run perl, find it's
2057         libraries, etc...
2058
2059    *PERLRUNINST is *PERLRUN + everything necessary to find the
2060         modules being built.
2061
2062=cut
2063
2064sub init_PERL {
2065    my($self) = shift;
2066
2067    my @defpath = ();
2068    foreach my $component ($self->{PERL_SRC}, $self->path(),
2069                           $Config{binexp})
2070    {
2071	push @defpath, $component if defined $component;
2072    }
2073
2074    # Build up a set of file names (not command names).
2075    my $thisperl = $self->canonpath($^X);
2076    $thisperl .= $Config{exe_ext} unless
2077                # VMS might have a file version # at the end
2078      $Is{VMS} ? $thisperl =~ m/$Config{exe_ext}(;\d+)?$/i
2079              : $thisperl =~ m/$Config{exe_ext}$/i;
2080
2081    # We need a relative path to perl when in the core.
2082    $thisperl = $self->abs2rel($thisperl) if $self->{PERL_CORE};
2083
2084    my @perls = ($thisperl);
2085    push @perls, map { "$_$Config{exe_ext}" }
2086                     ("perl$Config{version}", 'perl5', 'perl');
2087
2088    # miniperl has priority over all but the canonical perl when in the
2089    # core.  Otherwise its a last resort.
2090    my $miniperl = "miniperl$Config{exe_ext}";
2091    if( $self->{PERL_CORE} ) {
2092        splice @perls, 1, 0, $miniperl;
2093    }
2094    else {
2095        push @perls, $miniperl;
2096    }
2097
2098    $self->{PERL} ||=
2099        $self->find_perl(5.0, \@perls, \@defpath, $Verbose );
2100
2101    my $perl = $self->{PERL};
2102    $perl =~ s/^"//;
2103    my $has_mcr = $perl =~ s/^MCR\s*//;
2104    my $perlflags = '';
2105    my $stripped_perl;
2106    while ($perl) {
2107	($stripped_perl = $perl) =~ s/"$//;
2108	last if -x $stripped_perl;
2109	last unless $perl =~ s/(\s+\S+)$//;
2110	$perlflags = $1.$perlflags;
2111    }
2112    $self->{PERL} = $stripped_perl;
2113    $self->{PERL} = 'MCR '.$self->{PERL} if $has_mcr || $Is{VMS};
2114
2115    # When built for debugging, VMS doesn't create perl.exe but ndbgperl.exe.
2116    my $perl_name = 'perl';
2117    $perl_name = 'ndbgperl' if $Is{VMS} &&
2118      defined $Config{usevmsdebug} && $Config{usevmsdebug} eq 'define';
2119
2120    # XXX This logic is flawed.  If "miniperl" is anywhere in the path
2121    # it will get confused.  It should be fixed to work only on the filename.
2122    # Define 'FULLPERL' to be a non-miniperl (used in test: target)
2123    unless ($self->{FULLPERL}) {
2124      ($self->{FULLPERL} = $self->{PERL}) =~ s/\Q$miniperl\E$/$perl_name$Config{exe_ext}/i;
2125      $self->{FULLPERL} = qq{"$self->{FULLPERL}"}.$perlflags;
2126    }
2127    # Can't have an image name with quotes, and findperl will have
2128    # already escaped spaces.
2129    $self->{FULLPERL} =~ tr/"//d if $Is{VMS};
2130
2131    # `dmake` can fail for image (aka, executable) names which start with double-quotes
2132    # * push quote inward by at least one character (or the drive prefix, if present)
2133    # * including any initial directory separator preserves the `file_name_is_absolute` property
2134    $self->{FULLPERL} =~ s/^"(\S(:\\|:)?)/$1"/ if $self->is_make_type('dmake');
2135
2136    # Little hack to get around VMS's find_perl putting "MCR" in front
2137    # sometimes.
2138    $self->{ABSPERL} = $self->{PERL};
2139    $has_mcr = $self->{ABSPERL} =~ s/^MCR\s*//;
2140    if( $self->file_name_is_absolute($self->{ABSPERL}) ) {
2141        $self->{ABSPERL} = '$(PERL)';
2142    }
2143    else {
2144        $self->{ABSPERL} = $self->rel2abs($self->{ABSPERL});
2145
2146        # Quote the perl command if it contains whitespace
2147        $self->{ABSPERL} = $self->quote_literal($self->{ABSPERL})
2148          if $self->{ABSPERL} =~ /\s/;
2149
2150        $self->{ABSPERL} = 'MCR '.$self->{ABSPERL} if $has_mcr;
2151    }
2152    $self->{PERL} = qq{"$self->{PERL}"}.$perlflags;
2153
2154    # Can't have an image name with quotes, and findperl will have
2155    # already escaped spaces.
2156    $self->{PERL} =~ tr/"//d if $Is{VMS};
2157
2158    # `dmake` can fail for image (aka, executable) names which start with double-quotes
2159    # * push quote inward by at least one character (or the drive prefix, if present)
2160    # * including any initial directory separator preserves the `file_name_is_absolute` property
2161    $self->{PERL} =~ s/^"(\S(:\\|:)?)/$1"/ if $self->is_make_type('dmake');
2162
2163    # Are we building the core?
2164    $self->{PERL_CORE} = $ENV{PERL_CORE} unless exists $self->{PERL_CORE};
2165    $self->{PERL_CORE} = 0               unless defined $self->{PERL_CORE};
2166
2167    # Make sure perl can find itself before it's installed.
2168    my $lib_paths = $self->{UNINSTALLED_PERL} || $self->{PERL_CORE}
2169        ? ( $self->{PERL_ARCHLIB} && $self->{PERL_LIB} && $self->{PERL_ARCHLIB} ne $self->{PERL_LIB} ) ?
2170            q{ "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)"} : q{ "-I$(PERL_LIB)"}
2171        : undef;
2172    my $inst_lib_paths = $self->{INST_ARCHLIB} ne $self->{INST_LIB}
2173        ? 'RUN)'.$perlflags.' "-I$(INST_ARCHLIB)" "-I$(INST_LIB)"'
2174        : 'RUN)'.$perlflags.' "-I$(INST_LIB)"';
2175    # How do we run perl?
2176    foreach my $perl (qw(PERL FULLPERL ABSPERL)) {
2177        my $run  = $perl.'RUN';
2178
2179        $self->{$run}  = qq{\$($perl)};
2180        $self->{$run} .= $lib_paths if $lib_paths;
2181
2182        $self->{$perl.'RUNINST'} = '$('.$perl.$inst_lib_paths;
2183    }
2184
2185    return 1;
2186}
2187
2188
2189=item init_platform
2190
2191=item platform_constants
2192
2193Add MM_Unix_VERSION.
2194
2195=cut
2196
2197sub init_platform {
2198    my($self) = shift;
2199
2200    $self->{MM_Unix_VERSION} = our $VERSION;
2201    $self->{PERL_MALLOC_DEF} = '-DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc '.
2202                               '-Dfree=Perl_mfree -Drealloc=Perl_realloc '.
2203                               '-Dcalloc=Perl_calloc';
2204
2205}
2206
2207sub platform_constants {
2208    my($self) = shift;
2209    my $make_frag = '';
2210
2211    foreach my $macro (qw(MM_Unix_VERSION PERL_MALLOC_DEF))
2212    {
2213        next unless defined $self->{$macro};
2214        $make_frag .= "$macro = $self->{$macro}\n";
2215    }
2216
2217    return $make_frag;
2218}
2219
2220
2221=item init_PERM
2222
2223  $mm->init_PERM
2224
2225Called by init_main.  Initializes PERL_*
2226
2227=cut
2228
2229sub init_PERM {
2230    my($self) = shift;
2231
2232    $self->{PERM_DIR} = 755  unless defined $self->{PERM_DIR};
2233    $self->{PERM_RW}  = 644  unless defined $self->{PERM_RW};
2234    $self->{PERM_RWX} = 755  unless defined $self->{PERM_RWX};
2235
2236    return 1;
2237}
2238
2239
2240=item init_xs
2241
2242    $mm->init_xs
2243
2244Sets up macros having to do with XS code.  Currently just INST_STATIC,
2245INST_DYNAMIC and INST_BOOT.
2246
2247=cut
2248
2249sub init_xs {
2250    my $self = shift;
2251
2252    if ($self->has_link_code()) {
2253        $self->{INST_STATIC}  =
2254          $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT)$(LIB_EXT)');
2255        $self->{INST_DYNAMIC} =
2256          $self->catfile('$(INST_ARCHAUTODIR)', '$(DLBASE).$(DLEXT)');
2257        $self->{INST_BOOT}    =
2258          $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT).bs');
2259	if ($self->{XSMULTI}) {
2260	    my @exts = $self->_xs_list_basenames;
2261	    my (@statics, @dynamics, @boots);
2262	    for my $ext (@exts) {
2263		my ($v, $d, $f) = File::Spec->splitpath($ext);
2264		my @d = File::Spec->splitdir($d);
2265		shift @d if defined $d[0] and $d[0] eq 'lib';
2266		pop @d if $d[$#d] eq '';
2267		my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
2268		my $instfile = $self->catfile($instdir, $f);
2269		push @statics, "$instfile\$(LIB_EXT)";
2270
2271                # Dynamic library names may need special handling.
2272                my $dynfile = $instfile;
2273                eval { require DynaLoader };
2274                if (defined &DynaLoader::mod2fname) {
2275                    $dynfile = $self->catfile($instdir, &DynaLoader::mod2fname([@d, $f]));
2276                }
2277
2278		push @dynamics, "$dynfile.\$(DLEXT)";
2279		push @boots, "$instfile.bs";
2280	    }
2281	    $self->{INST_STATIC} = join ' ', @statics;
2282	    $self->{INST_DYNAMIC} = join ' ', @dynamics;
2283	    $self->{INST_BOOT} = join ' ', @boots;
2284	}
2285    } else {
2286        $self->{INST_STATIC}  = '';
2287        $self->{INST_DYNAMIC} = '';
2288        $self->{INST_BOOT}    = '';
2289    }
2290}
2291
2292=item install (o)
2293
2294Defines the install target.
2295
2296=cut
2297
2298sub install {
2299    my($self, %attribs) = @_;
2300    my(@m);
2301
2302    push @m, q{
2303install :: pure_install doc_install
2304	$(NOECHO) $(NOOP)
2305
2306install_perl :: pure_perl_install doc_perl_install
2307	$(NOECHO) $(NOOP)
2308
2309install_site :: pure_site_install doc_site_install
2310	$(NOECHO) $(NOOP)
2311
2312install_vendor :: pure_vendor_install doc_vendor_install
2313	$(NOECHO) $(NOOP)
2314
2315pure_install :: pure_$(INSTALLDIRS)_install
2316	$(NOECHO) $(NOOP)
2317
2318doc_install :: doc_$(INSTALLDIRS)_install
2319	$(NOECHO) $(NOOP)
2320
2321pure__install : pure_site_install
2322	$(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2323
2324doc__install : doc_site_install
2325	$(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2326
2327pure_perl_install :: all
2328	$(NOECHO) $(MOD_INSTALL) \
2329};
2330
2331    push @m,
2332q{		read "}.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{" \
2333		write "}.$self->catfile('$(DESTINSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{" \
2334} unless $self->{NO_PACKLIST};
2335
2336    push @m,
2337q{		"$(INST_LIB)" "$(DESTINSTALLPRIVLIB)" \
2338		"$(INST_ARCHLIB)" "$(DESTINSTALLARCHLIB)" \
2339		"$(INST_BIN)" "$(DESTINSTALLBIN)" \
2340		"$(INST_SCRIPT)" "$(DESTINSTALLSCRIPT)" \
2341		"$(INST_MAN1DIR)" "$(DESTINSTALLMAN1DIR)" \
2342		"$(INST_MAN3DIR)" "$(DESTINSTALLMAN3DIR)"
2343	$(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2344		"}.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{"
2345
2346
2347pure_site_install :: all
2348	$(NOECHO) $(MOD_INSTALL) \
2349};
2350    push @m,
2351q{		read "}.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{" \
2352		write "}.$self->catfile('$(DESTINSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{" \
2353} unless $self->{NO_PACKLIST};
2354
2355    push @m,
2356q{		"$(INST_LIB)" "$(DESTINSTALLSITELIB)" \
2357		"$(INST_ARCHLIB)" "$(DESTINSTALLSITEARCH)" \
2358		"$(INST_BIN)" "$(DESTINSTALLSITEBIN)" \
2359		"$(INST_SCRIPT)" "$(DESTINSTALLSITESCRIPT)" \
2360		"$(INST_MAN1DIR)" "$(DESTINSTALLSITEMAN1DIR)" \
2361		"$(INST_MAN3DIR)" "$(DESTINSTALLSITEMAN3DIR)"
2362	$(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2363		"}.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{"
2364
2365pure_vendor_install :: all
2366	$(NOECHO) $(MOD_INSTALL) \
2367};
2368    push @m,
2369q{		read "}.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{" \
2370		write "}.$self->catfile('$(DESTINSTALLVENDORARCH)','auto','$(FULLEXT)','.packlist').q{" \
2371} unless $self->{NO_PACKLIST};
2372
2373    push @m,
2374q{		"$(INST_LIB)" "$(DESTINSTALLVENDORLIB)" \
2375		"$(INST_ARCHLIB)" "$(DESTINSTALLVENDORARCH)" \
2376		"$(INST_BIN)" "$(DESTINSTALLVENDORBIN)" \
2377		"$(INST_SCRIPT)" "$(DESTINSTALLVENDORSCRIPT)" \
2378		"$(INST_MAN1DIR)" "$(DESTINSTALLVENDORMAN1DIR)" \
2379		"$(INST_MAN3DIR)" "$(DESTINSTALLVENDORMAN3DIR)"
2380
2381};
2382
2383    push @m, q{
2384doc_perl_install :: all
2385	$(NOECHO) $(NOOP)
2386
2387doc_site_install :: all
2388	$(NOECHO) $(NOOP)
2389
2390doc_vendor_install :: all
2391	$(NOECHO) $(NOOP)
2392
2393} if $self->{NO_PERLLOCAL};
2394
2395    push @m, q{
2396doc_perl_install :: all
2397	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2398	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2399	-$(NOECHO) $(DOC_INSTALL) \
2400		"Module" "$(NAME)" \
2401		"installed into" "$(INSTALLPRIVLIB)" \
2402		LINKTYPE "$(LINKTYPE)" \
2403		VERSION "$(VERSION)" \
2404		EXE_FILES "$(EXE_FILES)" \
2405		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2406
2407doc_site_install :: all
2408	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2409	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2410	-$(NOECHO) $(DOC_INSTALL) \
2411		"Module" "$(NAME)" \
2412		"installed into" "$(INSTALLSITELIB)" \
2413		LINKTYPE "$(LINKTYPE)" \
2414		VERSION "$(VERSION)" \
2415		EXE_FILES "$(EXE_FILES)" \
2416		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2417
2418doc_vendor_install :: all
2419	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2420	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2421	-$(NOECHO) $(DOC_INSTALL) \
2422		"Module" "$(NAME)" \
2423		"installed into" "$(INSTALLVENDORLIB)" \
2424		LINKTYPE "$(LINKTYPE)" \
2425		VERSION "$(VERSION)" \
2426		EXE_FILES "$(EXE_FILES)" \
2427		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2428
2429} unless $self->{NO_PERLLOCAL};
2430
2431    push @m, q{
2432uninstall :: uninstall_from_$(INSTALLDIRS)dirs
2433	$(NOECHO) $(NOOP)
2434
2435uninstall_from_perldirs ::
2436	$(NOECHO) $(UNINSTALL) "}.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{"
2437
2438uninstall_from_sitedirs ::
2439	$(NOECHO) $(UNINSTALL) "}.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{"
2440
2441uninstall_from_vendordirs ::
2442	$(NOECHO) $(UNINSTALL) "}.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{"
2443};
2444
2445    join("",@m);
2446}
2447
2448=item installbin (o)
2449
2450Defines targets to make and to install EXE_FILES.
2451
2452=cut
2453
2454sub installbin {
2455    my($self) = shift;
2456
2457    return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
2458    my @exefiles = sort @{$self->{EXE_FILES}};
2459    return "" unless @exefiles;
2460
2461    @exefiles = map vmsify($_), @exefiles if $Is{VMS};
2462
2463    my %fromto;
2464    for my $from (@exefiles) {
2465	my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
2466
2467	local($_) = $path; # for backwards compatibility
2468	my $to = $self->libscan($path);
2469	print "libscan($from) => '$to'\n" if ($Verbose >=2);
2470
2471        $to = vmsify($to) if $Is{VMS};
2472	$fromto{$from} = $to;
2473    }
2474    my @to   = sort values %fromto;
2475
2476    my @m;
2477    push(@m, qq{
2478EXE_FILES = @exefiles
2479
2480pure_all :: @to
2481	\$(NOECHO) \$(NOOP)
2482
2483realclean ::
2484});
2485
2486    # realclean can get rather large.
2487    push @m, map "\t$_\n", $self->split_command('$(RM_F)', @to);
2488    push @m, "\n";
2489
2490    # A target for each exe file.
2491    my @froms = sort keys %fromto;
2492    for my $from (@froms) {
2493        #                              1      2
2494        push @m, _sprintf562 <<'MAKE', $from, $fromto{$from};
2495%2$s : %1$s $(FIRST_MAKEFILE) $(INST_SCRIPT)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists
2496	$(NOECHO) $(RM_F) %2$s
2497	$(CP) %1$s %2$s
2498	$(FIXIN) %2$s
2499	-$(NOECHO) $(CHMOD) $(PERM_RWX) %2$s
2500
2501MAKE
2502
2503    }
2504
2505    join "", @m;
2506}
2507
2508=item linkext (o)
2509
2510Defines the linkext target which in turn defines the LINKTYPE.
2511
2512=cut
2513
2514# LINKTYPE => static or dynamic or ''
2515sub linkext {
2516    my($self, %attribs) = @_;
2517    my $linktype = $attribs{LINKTYPE};
2518    $linktype = $self->{LINKTYPE} unless defined $linktype;
2519    if (defined $linktype and $linktype eq '') {
2520        warn "Warning: LINKTYPE set to '', no longer necessary\n";
2521    }
2522    $linktype = '$(LINKTYPE)' unless defined $linktype;
2523    "
2524linkext :: $linktype
2525	\$(NOECHO) \$(NOOP)
2526";
2527}
2528
2529=item lsdir
2530
2531Takes as arguments a directory name and a regular expression. Returns
2532all entries in the directory that match the regular expression.
2533
2534=cut
2535
2536sub lsdir {
2537    #  $self
2538    my(undef, $dir, $regex) = @_;
2539    opendir(my $dh, defined($dir) ? $dir : ".")
2540        or return;
2541    my @ls = readdir $dh;
2542    closedir $dh;
2543    @ls = grep(/$regex/, @ls) if defined $regex;
2544    @ls;
2545}
2546
2547=item macro (o)
2548
2549Simple subroutine to insert the macros defined by the macro attribute
2550into the Makefile.
2551
2552=cut
2553
2554sub macro {
2555    my($self,%attribs) = @_;
2556    my @m;
2557    foreach my $key (sort keys %attribs) {
2558	my $val = $attribs{$key};
2559	push @m, "$key = $val\n";
2560    }
2561    join "", @m;
2562}
2563
2564=item makeaperl (o)
2565
2566Called by staticmake. Defines how to write the Makefile to produce a
2567static new perl.
2568
2569By default the Makefile produced includes all the static extensions in
2570the perl library. (Purified versions of library files, e.g.,
2571DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
2572
2573=cut
2574
2575sub makeaperl {
2576    my($self, %attribs) = @_;
2577    my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
2578	@attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
2579    s/^(.*)/"-I$1"/ for @{$perlinc || []};
2580    my(@m);
2581    push @m, "
2582# --- MakeMaker makeaperl section ---
2583MAP_TARGET    = $target
2584FULLPERL      = $self->{FULLPERL}
2585MAP_PERLINC   = @{$perlinc || []}
2586";
2587    return join '', @m if $self->{PARENT};
2588
2589    my($dir) = join ":", @{$self->{DIR}};
2590
2591    unless ($self->{MAKEAPERL}) {
2592	push @m, q{
2593$(MAP_TARGET) :: $(MAKE_APERL_FILE)
2594	$(MAKE) $(USEMAKEFILE) $(MAKE_APERL_FILE) $@
2595
2596$(MAKE_APERL_FILE) : static $(FIRST_MAKEFILE) pm_to_blib
2597	$(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
2598	$(NOECHO) $(PERLRUNINST) \
2599		Makefile.PL DIR="}, $dir, q{" \
2600		MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
2601		MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
2602
2603	foreach (@ARGV){
2604		my $arg = $_; # avoid lvalue aliasing
2605		if ( $arg =~ /(^.*?=)(.*['\s].*)/ ) {
2606			$arg = $1 . $self->quote_literal($2);
2607		}
2608		push @m, " \\\n\t\t$arg";
2609	}
2610	push @m, "\n";
2611
2612	return join '', @m;
2613    }
2614
2615    my $cccmd = $self->const_cccmd($libperl);
2616    $cccmd =~ s/^CCCMD\s*=\s*//;
2617    $cccmd =~ s/\$\(INC\)/ "-I$self->{PERL_INC}" /;
2618    $cccmd .= " $Config{cccdlflags}"
2619	if ($Config{useshrplib} eq 'true');
2620    $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
2621
2622    # The front matter of the linkcommand...
2623    my $linkcmd = join ' ', "\$(CC)",
2624	    grep($_, @Config{qw(ldflags ccdlflags)});
2625    $linkcmd =~ s/\s+/ /g;
2626    $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
2627
2628    # Which *.a files could we make use of...
2629    my $staticlib21 = $self->_find_static_libs($searchdirs);
2630    # We trust that what has been handed in as argument, will be buildable
2631    $static = [] unless $static;
2632    @$staticlib21{@{$static}} = (1) x @{$static};
2633
2634    $extra = [] unless $extra && ref $extra eq 'ARRAY';
2635    for (sort keys %$staticlib21) {
2636	next unless /\Q$self->{LIB_EXT}\E\z/;
2637	$_ = dirname($_) . "/extralibs.ld";
2638	push @$extra, $_;
2639    }
2640
2641    s/^(.*)/"-I$1"/ for @{$perlinc || []};
2642
2643    $target ||= "perl";
2644    $tmp    ||= ".";
2645
2646# MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
2647# regenerate the Makefiles, MAP_STATIC and the dependencies for
2648# extralibs.all are computed correctly
2649    my @map_static = reverse sort keys %$staticlib21;
2650    push @m, "
2651MAP_LINKCMD   = $linkcmd
2652MAP_STATIC    = ", join(" \\\n\t", map { qq{"$_"} } @map_static), "
2653MAP_STATICDEP = ", join(' ', map { $self->quote_dep($_) } @map_static), "
2654
2655MAP_PRELIBS   = $Config{perllibs} $Config{cryptlib}
2656";
2657
2658    my $lperl;
2659    if (defined $libperl) {
2660	($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
2661    }
2662    unless ($libperl && -f $lperl) { # Ilya's code...
2663	my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
2664	$dir = "$self->{PERL_ARCHLIB}/.." if $self->{UNINSTALLED_PERL};
2665	$libperl ||= "libperl$self->{LIB_EXT}";
2666	$libperl   = "$dir/$libperl";
2667	$lperl   ||= "libperl$self->{LIB_EXT}";
2668	$lperl     = "$dir/$lperl";
2669
2670        if (! -f $libperl and ! -f $lperl) {
2671          # We did not find a static libperl. Maybe there is a shared one?
2672          if ($Is{SunOS}) {
2673            $lperl  = $libperl = "$dir/$Config{libperl}";
2674            # SUNOS ld does not take the full path to a shared library
2675            $libperl = '' if $Is{SunOS4};
2676          }
2677        }
2678
2679	print <<EOF unless -f $lperl || defined($self->{PERL_SRC});
2680Warning: $libperl not found
2681If you're going to build a static perl binary, make sure perl is installed
2682otherwise ignore this warning
2683EOF
2684    }
2685
2686    # SUNOS ld does not take the full path to a shared library
2687    my $llibperl = $libperl ? '$(MAP_LIBPERL)' : '-lperl';
2688    my $libperl_dep = $self->quote_dep($libperl);
2689
2690    push @m, "
2691MAP_LIBPERL = $libperl
2692MAP_LIBPERLDEP = $libperl_dep
2693LLIBPERL    = $llibperl
2694";
2695
2696    push @m, '
2697$(INST_ARCHAUTODIR)/extralibs.all : $(INST_ARCHAUTODIR)$(DFSEP).exists '.join(" \\\n\t", @$extra).'
2698	$(NOECHO) $(RM_F)  $@
2699	$(NOECHO) $(TOUCH) $@
2700';
2701
2702    foreach my $catfile (@$extra){
2703	push @m, "\tcat $catfile >> \$\@\n";
2704    }
2705
2706    my $ldfrom = $self->{XSMULTI} ? '' : '$(LDFROM)';
2707    #                             1     2                        3        4
2708    push @m, _sprintf562 <<'EOF', $tmp, $ldfrom, $self->xs_obj_opt('$@'), $makefilename;
2709$(MAP_TARGET) :: %1$s/perlmain$(OBJ_EXT) $(MAP_LIBPERLDEP) $(MAP_STATICDEP) $(INST_ARCHAUTODIR)/extralibs.all
2710	$(MAP_LINKCMD) %2$s $(OPTIMIZE) %1$s/perlmain$(OBJ_EXT) %3$s $(MAP_STATIC) "$(LLIBPERL)" `cat $(INST_ARCHAUTODIR)/extralibs.all` $(MAP_PRELIBS)
2711	$(NOECHO) $(ECHO) "To install the new '$(MAP_TARGET)' binary, call"
2712	$(NOECHO) $(ECHO) "    $(MAKE) $(USEMAKEFILE) %4$s inst_perl MAP_TARGET=$(MAP_TARGET)"
2713	$(NOECHO) $(ECHO) "    $(MAKE) $(USEMAKEFILE) %4$s map_clean"
2714
2715%1$s/perlmain\$(OBJ_EXT): %1$s/perlmain.c
2716EOF
2717    push @m, "\t".$self->cd($tmp, qq[$cccmd "-I\$(PERL_INC)" perlmain.c])."\n";
2718
2719    my $maybe_DynaLoader = $Config{usedl} ? 'q(DynaLoader)' : '';
2720    push @m, _sprintf562 <<'EOF', $tmp, $makefilename, $maybe_DynaLoader;
2721
2722%1$s/perlmain.c: %2$s
2723	$(NOECHO) $(ECHO) Writing $@
2724	$(NOECHO) $(PERL) $(MAP_PERLINC) "-MExtUtils::Miniperl" \
2725		-e "writemain(grep(s#.*/auto/##s, @ARGV), %3$s)" $(MAP_STATIC) > $@t
2726	$(MV) $@t $@
2727
2728EOF
2729    push @m, "\t", q{$(NOECHO) $(PERL) "$(INSTALLSCRIPT)/fixpmain"
2730} if (defined (&Dos::UseLFN) && Dos::UseLFN()==0);
2731
2732
2733    push @m, q{
2734doc_inst_perl :
2735	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2736	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2737	-$(NOECHO) $(DOC_INSTALL) \
2738		"Perl binary" "$(MAP_TARGET)" \
2739		MAP_STATIC "$(MAP_STATIC)" \
2740		MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
2741		MAP_LIBPERL "$(MAP_LIBPERL)" \
2742		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2743
2744};
2745
2746    push @m, q{
2747inst_perl : pure_inst_perl doc_inst_perl
2748
2749pure_inst_perl : $(MAP_TARGET)
2750	}.$self->{CP}.q{ $(MAP_TARGET) "}.$self->catfile('$(DESTINSTALLBIN)','$(MAP_TARGET)').q{"
2751
2752clean :: map_clean
2753
2754map_clean :
2755	}.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
2756};
2757
2758    join '', @m;
2759}
2760
2761# utility method
2762sub _find_static_libs {
2763    my ($self, $searchdirs) = @_;
2764    # don't use File::Spec here because on Win32 F::F still uses "/"
2765    my $installed_version = join('/',
2766	'auto', $self->{FULLEXT}, "$self->{BASEEXT}$self->{LIB_EXT}"
2767    );
2768    my %staticlib21;
2769    require File::Find;
2770    File::Find::find(sub {
2771	if ($File::Find::name =~ m{/auto/share\z}) {
2772	    # in a subdir of auto/share, prune because e.g.
2773	    # Alien::pkgconfig uses File::ShareDir to put .a files
2774	    # there. do not want
2775	    $File::Find::prune = 1;
2776	    return;
2777	}
2778
2779	return unless m/\Q$self->{LIB_EXT}\E$/;
2780
2781	return unless -f 'extralibs.ld'; # this checks is a "proper" XS installation
2782
2783        # Skip perl's libraries.
2784        return if m/^libperl/ or m/^perl\Q$self->{LIB_EXT}\E$/;
2785
2786	# Skip purified versions of libraries
2787        # (e.g., DynaLoader_pure_p1_c0_032.a)
2788	return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
2789
2790	if( exists $self->{INCLUDE_EXT} ){
2791		my $found = 0;
2792
2793		(my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
2794		$xx =~ s,/?$_,,;
2795		$xx =~ s,/,::,g;
2796
2797		# Throw away anything not explicitly marked for inclusion.
2798		# DynaLoader is implied.
2799		foreach my $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
2800			if( $xx eq $incl ){
2801				$found++;
2802				last;
2803			}
2804		}
2805		return unless $found;
2806	}
2807	elsif( exists $self->{EXCLUDE_EXT} ){
2808		(my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
2809		$xx =~ s,/?$_,,;
2810		$xx =~ s,/,::,g;
2811
2812		# Throw away anything explicitly marked for exclusion
2813		foreach my $excl (@{$self->{EXCLUDE_EXT}}){
2814			return if( $xx eq $excl );
2815		}
2816	}
2817
2818	# don't include the installed version of this extension. I
2819	# leave this line here, although it is not necessary anymore:
2820	# I patched minimod.PL instead, so that Miniperl.pm won't
2821	# include duplicates
2822
2823	# Once the patch to minimod.PL is in the distribution, I can
2824	# drop it
2825	return if $File::Find::name =~ m:\Q$installed_version\E\z:;
2826	return if !$self->xs_static_lib_is_xs($_);
2827	use Cwd 'cwd';
2828	$staticlib21{cwd() . "/" . $_}++;
2829    }, grep( -d $_, map { $self->catdir($_, 'auto') } @{$searchdirs || []}) );
2830    return \%staticlib21;
2831}
2832
2833=item xs_static_lib_is_xs (o)
2834
2835Called by a utility method of makeaperl. Checks whether a given file
2836is an XS library by seeing whether it defines any symbols starting
2837with C<boot_> (with an optional leading underscore - needed on MacOS).
2838
2839=cut
2840
2841sub xs_static_lib_is_xs {
2842    my ($self, $libfile) = @_;
2843    my $devnull = File::Spec->devnull;
2844    return `nm $libfile 2>$devnull` =~ /\b_?boot_/;
2845}
2846
2847=item makefile (o)
2848
2849Defines how to rewrite the Makefile.
2850
2851=cut
2852
2853sub makefile {
2854    my($self) = shift;
2855    my $m;
2856    # We do not know what target was originally specified so we
2857    # must force a manual rerun to be sure. But as it should only
2858    # happen very rarely it is not a significant problem.
2859    $m = '
2860$(OBJECT) : $(FIRST_MAKEFILE)
2861
2862' if $self->{OBJECT};
2863
2864    my $newer_than_target = $Is{VMS} ? '$(MMS$SOURCE_LIST)' : '$?';
2865    my $mpl_args = join " ", map qq["$_"], @ARGV;
2866    my $cross = '';
2867    if (defined $::Cross::platform) {
2868        # Inherited from win32/buildext.pl
2869        $cross = "-MCross=$::Cross::platform ";
2870    }
2871    $m .= sprintf <<'MAKE_FRAG', $newer_than_target, $cross, $mpl_args;
2872# We take a very conservative approach here, but it's worth it.
2873# We move Makefile to Makefile.old here to avoid gnu make looping.
2874$(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP)
2875	$(NOECHO) $(ECHO) "Makefile out-of-date with respect to %s"
2876	$(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..."
2877	-$(NOECHO) $(RM_F) $(MAKEFILE_OLD)
2878	-$(NOECHO) $(MV)   $(FIRST_MAKEFILE) $(MAKEFILE_OLD)
2879	- $(MAKE) $(USEMAKEFILE) $(MAKEFILE_OLD) clean $(DEV_NULL)
2880	$(PERLRUN) %sMakefile.PL %s
2881	$(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <=="
2882	$(NOECHO) $(ECHO) "==> Please rerun the $(MAKE) command.  <=="
2883	$(FALSE)
2884
2885MAKE_FRAG
2886
2887    return $m;
2888}
2889
2890
2891=item maybe_command
2892
2893Returns true, if the argument is likely to be a command.
2894
2895=cut
2896
2897sub maybe_command {
2898    my($self,$file) = @_;
2899    return $file if -x $file && ! -d $file;
2900    return;
2901}
2902
2903
2904=item needs_linking (o)
2905
2906Does this module need linking? Looks into subdirectory objects (see
2907also has_link_code())
2908
2909=cut
2910
2911sub needs_linking {
2912    my($self) = shift;
2913
2914    my $caller = (caller(0))[3];
2915    confess("needs_linking called too early") if
2916      $caller =~ /^ExtUtils::MakeMaker::/;
2917    return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
2918    if ($self->has_link_code or $self->{MAKEAPERL}){
2919	$self->{NEEDS_LINKING} = 1;
2920	return 1;
2921    }
2922    foreach my $child (keys %{$self->{CHILDREN}}) {
2923	if ($self->{CHILDREN}->{$child}->needs_linking) {
2924	    $self->{NEEDS_LINKING} = 1;
2925	    return 1;
2926	}
2927    }
2928    return $self->{NEEDS_LINKING} = 0;
2929}
2930
2931
2932=item parse_abstract
2933
2934parse a file and return what you think is the ABSTRACT
2935
2936=cut
2937
2938sub parse_abstract {
2939    my($self,$parsefile) = @_;
2940    my $result;
2941
2942    local $/ = "\n";
2943    open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
2944    binmode $fh;
2945    my $inpod = 0;
2946    my $pod_encoding;
2947    my $package = $self->{DISTNAME};
2948    $package =~ s/-/::/g;
2949    while (<$fh>) {
2950        $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2951        next if !$inpod;
2952        s#\r*\n\z##; # handle CRLF input
2953
2954        if ( /^=encoding\s*(.*)$/i ) {
2955            $pod_encoding = $1;
2956        }
2957
2958        if ( /^($package(?:\.pm)? \s+ -+ \s+)(.*)/x ) {
2959          $result = $2;
2960          next;
2961        }
2962        next unless $result;
2963
2964        if ( $result && ( /^\s*$/ || /^\=/ ) ) {
2965          last;
2966        }
2967        $result = join ' ', $result, $_;
2968    }
2969    close $fh;
2970
2971    if ( $pod_encoding and !( "$]" < 5.008 or !$Config{useperlio} ) ) {
2972        # Have to wrap in an eval{} for when running under PERL_CORE
2973        # Encode isn't available during build phase and parsing
2974        # ABSTRACT isn't important there
2975        eval {
2976          require Encode;
2977          $result = Encode::decode($pod_encoding, $result);
2978        }
2979    }
2980
2981    return $result;
2982}
2983
2984=item parse_version
2985
2986    my $version = MM->parse_version($file);
2987
2988Parse a $file and return what $VERSION is set to by the first assignment.
2989It will return the string "undef" if it can't figure out what $VERSION
2990is. $VERSION should be for all to see, so C<our $VERSION> or plain $VERSION
2991are okay, but C<my $VERSION> is not.
2992
2993C<package Foo VERSION> is also checked for.  The first version
2994declaration found is used, but this may change as it differs from how
2995Perl does it.
2996
2997parse_version() will try to C<use version> before checking for
2998C<$VERSION> so the following will work.
2999
3000    $VERSION = qv(1.2.3);
3001
3002=cut
3003
3004sub parse_version {
3005    my($self,$parsefile) = @_;
3006    my $result;
3007
3008    local $/ = "\n";
3009    local $_;
3010    open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
3011    my $inpod = 0;
3012    while (<$fh>) {
3013        $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
3014        next if $inpod || /^\s*#/;
3015        chop;
3016        next if /^\s*(if|unless|elsif)/;
3017        if ( m{^ \s* package \s+ \w[\w\:\']* \s+ (v?[0-9._]+) \s* (;|\{)  }x ) {
3018            no warnings;
3019            $result = $1;
3020        }
3021        elsif ( m{(?<!\\) ([\$*]) (([\w\:\']*) \bVERSION)\b .* (?<![<>=!])\=[^=]}x ) {
3022			$result = $self->get_version($parsefile, $1, $2);
3023        }
3024        else {
3025          next;
3026        }
3027        last if defined $result;
3028    }
3029    close $fh;
3030
3031    if ( defined $result && $result !~ /^v?[\d_\.]+$/ ) {
3032      require version;
3033      my $normal = eval { version->new( $result ) };
3034      $result = $normal if defined $normal;
3035    }
3036    if ( defined $result ) {
3037      $result = "undef" unless $result =~ m!^v?[\d_\.]+$!
3038                        or eval { version->parse( $result ) };
3039    }
3040    $result = "undef" unless defined $result;
3041    return $result;
3042}
3043
3044sub get_version {
3045    my ($self, $parsefile, $sigil, $name) = @_;
3046    my $line = $_; # from the while() loop in parse_version
3047    {
3048        package ExtUtils::MakeMaker::_version;
3049        undef *version; # in case of unexpected version() sub
3050        eval {
3051            require version;
3052            version::->import;
3053        };
3054        no strict;
3055        no warnings;
3056        local *{$name};
3057        $line = $1 if $line =~ m{^(.+)}s;
3058        eval($line); ## no critic
3059        return ${$name};
3060    }
3061}
3062
3063=item pasthru (o)
3064
3065Defines the string that is passed to recursive make calls in
3066subdirectories. The variables like C<PASTHRU_DEFINE> are used in each
3067level, and passed downwards on the command-line with e.g. the value of
3068that level's DEFINE. Example:
3069
3070    # Level 0 has DEFINE = -Dfunky
3071    # This code will define level 0's PASTHRU=PASTHRU_DEFINE="$(DEFINE)
3072    #     $(PASTHRU_DEFINE)"
3073    # Level 0's $(CCCMD) will include macros $(DEFINE) and $(PASTHRU_DEFINE)
3074    # So will level 1's, so when level 1 compiles, it will get right values
3075    # And so ad infinitum
3076
3077=cut
3078
3079sub pasthru {
3080    my($self) = shift;
3081    my(@m);
3082
3083    my(@pasthru);
3084    my($sep) = $Is{VMS} ? ',' : '';
3085    $sep .= "\\\n\t";
3086
3087    foreach my $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE
3088                     PREFIX INSTALL_BASE)
3089                 )
3090    {
3091        next unless defined $self->{$key};
3092	push @pasthru, "$key=\"\$($key)\"";
3093    }
3094
3095    foreach my $key (qw(DEFINE INC)) {
3096        # default to the make var
3097        my $val = qq{\$($key)};
3098        # expand within perl if given since need to use quote_literal
3099        # since INC might include space-protecting ""!
3100        chomp($val = $self->{$key}) if defined $self->{$key};
3101        $val .= " \$(PASTHRU_$key)";
3102        my $quoted = $self->quote_literal($val);
3103        push @pasthru, qq{PASTHRU_$key=$quoted};
3104    }
3105
3106    push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
3107    join "", @m;
3108}
3109
3110=item perl_script
3111
3112Takes one argument, a file name, and returns the file name, if the
3113argument is likely to be a perl script. On MM_Unix this is true for
3114any ordinary, readable file.
3115
3116=cut
3117
3118sub perl_script {
3119    my($self,$file) = @_;
3120    return $file if -r $file && -f _;
3121    return;
3122}
3123
3124=item perldepend (o)
3125
3126Defines the dependency from all *.h files that come with the perl
3127distribution.
3128
3129=cut
3130
3131sub perldepend {
3132    my($self) = shift;
3133    my(@m);
3134
3135    my $make_config = $self->cd('$(PERL_SRC)', '$(MAKE) lib/Config.pm');
3136
3137    push @m, sprintf <<'MAKE_FRAG', $make_config if $self->{PERL_SRC};
3138# Check for unpropogated config.sh changes. Should never happen.
3139# We do NOT just update config.h because that is not sufficient.
3140# An out of date config.h is not fatal but complains loudly!
3141$(PERL_INCDEP)/config.h: $(PERL_SRC)/config.sh
3142	-$(NOECHO) $(ECHO) "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; $(FALSE)
3143
3144$(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
3145	$(NOECHO) $(ECHO) "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
3146	%s
3147MAKE_FRAG
3148
3149    return join "", @m unless $self->needs_linking;
3150
3151    if ($self->{OBJECT}) {
3152        # Need to add an object file dependency on the perl headers.
3153        # this is very important for XS modules in perl.git development.
3154        push @m, $self->_perl_header_files_fragment("/"); # Directory separator between $(PERL_INC)/header.h
3155    }
3156
3157    push @m, join(" ", sort values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
3158
3159    return join "\n", @m;
3160}
3161
3162
3163=item pm_to_blib
3164
3165Defines target that copies all files in the hash PM to their
3166destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
3167
3168=cut
3169
3170sub pm_to_blib {
3171    my $self = shift;
3172    my($autodir) = $self->catdir('$(INST_LIB)','auto');
3173    my $r = q{
3174pm_to_blib : $(FIRST_MAKEFILE) $(TO_INST_PM)
3175};
3176
3177    # VMS will swallow '' and PM_FILTER is often empty.  So use q[]
3178    my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']);
3179pm_to_blib({\@ARGV}, '$autodir', q[\$(PM_FILTER)], '\$(PERM_DIR)')
3180CODE
3181
3182    my @cmds = $self->split_command($pm_to_blib,
3183                  map { ($self->quote_literal($_) => $self->quote_literal($self->{PM}->{$_})) } sort keys %{$self->{PM}});
3184
3185    $r .= join '', map { "\t\$(NOECHO) $_\n" } @cmds;
3186    $r .= qq{\t\$(NOECHO) \$(TOUCH) pm_to_blib\n};
3187
3188    return $r;
3189}
3190
3191# transform dot-separated version string into comma-separated quadruple
3192# examples:  '1.2.3.4.5' => '1,2,3,4'
3193#            '1.2.3'     => '1,2,3,0'
3194sub _ppd_version {
3195    my ($self, $string) = @_;
3196    return join ',', ((split /\./, $string), (0) x 4)[0..3];
3197}
3198
3199=item ppd
3200
3201Defines target that creates a PPD (Perl Package Description) file
3202for a binary distribution.
3203
3204=cut
3205
3206sub ppd {
3207    my($self) = @_;
3208
3209    my $abstract = $self->{ABSTRACT} || '';
3210    $abstract =~ s/\n/\\n/sg;
3211    $abstract =~ s/</&lt;/g;
3212    $abstract =~ s/>/&gt;/g;
3213
3214    my $author = join(', ',@{ ref $self->{AUTHOR} eq 'ARRAY' ? $self->{AUTHOR} : [ $self->{AUTHOR} || '']});
3215    $author =~ s/</&lt;/g;
3216    $author =~ s/>/&gt;/g;
3217
3218    my $ppd_file = "$self->{DISTNAME}.ppd";
3219
3220    my @ppd_chunks = qq(<SOFTPKG NAME="$self->{DISTNAME}" VERSION="$self->{VERSION}">\n);
3221
3222    push @ppd_chunks, sprintf <<'PPD_HTML', $abstract, $author;
3223    <ABSTRACT>%s</ABSTRACT>
3224    <AUTHOR>%s</AUTHOR>
3225PPD_HTML
3226
3227    push @ppd_chunks, "    <IMPLEMENTATION>\n";
3228    if ( $self->{MIN_PERL_VERSION} ) {
3229        my $min_perl_version = $self->_ppd_version($self->{MIN_PERL_VERSION});
3230        push @ppd_chunks, sprintf <<'PPD_PERLVERS', $min_perl_version;
3231        <PERLCORE VERSION="%s" />
3232PPD_PERLVERS
3233
3234    }
3235
3236    # Don't add "perl" to requires.  perl dependencies are
3237    # handles by ARCHITECTURE.
3238    my %prereqs = %{$self->{PREREQ_PM}};
3239    delete $prereqs{perl};
3240
3241    # Build up REQUIRE
3242    foreach my $prereq (sort keys %prereqs) {
3243        my $name = $prereq;
3244        $name .= '::' unless $name =~ /::/;
3245        my $version = $prereqs{$prereq};
3246
3247        my %attrs = ( NAME => $name );
3248        $attrs{VERSION} = $version if $version;
3249        my $attrs = join " ", map { qq[$_="$attrs{$_}"] } sort keys %attrs;
3250        push @ppd_chunks, qq(        <REQUIRE $attrs />\n);
3251    }
3252
3253    my $archname = $Config{archname};
3254
3255    # archname did not change from 5.6 to 5.8, but those versions may
3256    # not be not binary compatible so now we append the part of the
3257    # version that changes when binary compatibility may change
3258    if ("$]" >= 5.008) {
3259        $archname .= "-$Config{api_revision}.$Config{api_version}";
3260    }
3261    push @ppd_chunks, sprintf <<'PPD_OUT', $archname;
3262        <ARCHITECTURE NAME="%s" />
3263PPD_OUT
3264
3265    if ($self->{PPM_INSTALL_SCRIPT}) {
3266        if ($self->{PPM_INSTALL_EXEC}) {
3267            push @ppd_chunks, sprintf qq{        <INSTALL EXEC="%s">%s</INSTALL>\n},
3268                  $self->{PPM_INSTALL_EXEC}, $self->{PPM_INSTALL_SCRIPT};
3269        }
3270        else {
3271            push @ppd_chunks, sprintf qq{        <INSTALL>%s</INSTALL>\n},
3272                  $self->{PPM_INSTALL_SCRIPT};
3273        }
3274    }
3275
3276    if ($self->{PPM_UNINSTALL_SCRIPT}) {
3277        if ($self->{PPM_UNINSTALL_EXEC}) {
3278            push @ppd_chunks, sprintf qq{        <UNINSTALL EXEC="%s">%s</UNINSTALL>\n},
3279                  $self->{PPM_UNINSTALL_EXEC}, $self->{PPM_UNINSTALL_SCRIPT};
3280        }
3281        else {
3282            push @ppd_chunks, sprintf qq{        <UNINSTALL>%s</UNINSTALL>\n},
3283                  $self->{PPM_UNINSTALL_SCRIPT};
3284        }
3285    }
3286
3287    my ($bin_location) = $self->{BINARY_LOCATION} || '';
3288    $bin_location =~ s/\\/\\\\/g;
3289
3290    push @ppd_chunks, sprintf <<'PPD_XML', $bin_location;
3291        <CODEBASE HREF="%s" />
3292    </IMPLEMENTATION>
3293</SOFTPKG>
3294PPD_XML
3295
3296    my @ppd_cmds = $self->stashmeta(join('', @ppd_chunks), $ppd_file);
3297
3298    return sprintf <<'PPD_OUT', join "\n\t", @ppd_cmds;
3299# Creates a PPD (Perl Package Description) for a binary distribution.
3300ppd :
3301	%s
3302PPD_OUT
3303
3304}
3305
3306=item prefixify
3307
3308  $MM->prefixify($var, $prefix, $new_prefix, $default);
3309
3310Using either $MM->{uc $var} || $Config{lc $var}, it will attempt to
3311replace it's $prefix with a $new_prefix.
3312
3313Should the $prefix fail to match I<AND> a PREFIX was given as an
3314argument to WriteMakefile() it will set it to the $new_prefix +
3315$default.  This is for systems whose file layouts don't neatly fit into
3316our ideas of prefixes.
3317
3318This is for heuristics which attempt to create directory structures
3319that mirror those of the installed perl.
3320
3321For example:
3322
3323    $MM->prefixify('installman1dir', '/usr', '/home/foo', 'man/man1');
3324
3325this will attempt to remove '/usr' from the front of the
3326$MM->{INSTALLMAN1DIR} path (initializing it to $Config{installman1dir}
3327if necessary) and replace it with '/home/foo'.  If this fails it will
3328simply use '/home/foo/man/man1'.
3329
3330=cut
3331
3332sub prefixify {
3333    my($self,$var,$sprefix,$rprefix,$default) = @_;
3334
3335    my $path = $self->{uc $var} ||
3336               $Config_Override{lc $var} || $Config{lc $var} || '';
3337
3338    $rprefix .= '/' if $sprefix =~ m|/$|;
3339
3340    warn "  prefixify $var => $path\n" if $Verbose >= 2;
3341    warn "    from $sprefix to $rprefix\n" if $Verbose >= 2;
3342
3343    if( $self->{ARGS}{PREFIX} &&
3344        $path !~ s{^\Q$sprefix\E\b}{$rprefix}s )
3345    {
3346
3347        warn "    cannot prefix, using default.\n" if $Verbose >= 2;
3348        warn "    no default!\n" if !$default && $Verbose >= 2;
3349
3350        $path = $self->catdir($rprefix, $default) if $default;
3351    }
3352
3353    print "    now $path\n" if $Verbose >= 2;
3354    return $self->{uc $var} = $path;
3355}
3356
3357
3358=item processPL (o)
3359
3360Defines targets to run *.PL files.
3361
3362=cut
3363
3364sub processPL {
3365    my $self = shift;
3366    my $pl_files = $self->{PL_FILES};
3367
3368    return "" unless $pl_files;
3369
3370    my $m = '';
3371    foreach my $plfile (sort keys %$pl_files) {
3372        my $targets = $pl_files->{$plfile};
3373        my $list =
3374            ref($targets) eq 'HASH'  ? [ sort keys %$targets ] :
3375            ref($targets) eq 'ARRAY' ? $pl_files->{$plfile}   :
3376            [$pl_files->{$plfile}];
3377
3378        foreach my $target (@$list) {
3379            if( $Is{VMS} ) {
3380                $plfile = vmsify($self->eliminate_macros($plfile));
3381                $target = vmsify($self->eliminate_macros($target));
3382            }
3383
3384            # Normally a .PL file runs AFTER pm_to_blib so it can have
3385            # blib in its @INC and load the just built modules.  BUT if
3386            # the generated module is something in $(TO_INST_PM) which
3387            # pm_to_blib depends on then it can't depend on pm_to_blib
3388            # else we have a dependency loop.
3389            my $pm_dep;
3390            my $perlrun;
3391            if( defined $self->{PM}{$target} ) {
3392                $pm_dep  = '';
3393                $perlrun = 'PERLRUN';
3394            }
3395            else {
3396                $pm_dep  = 'pm_to_blib';
3397                $perlrun = 'PERLRUNINST';
3398            }
3399
3400            my $extra_inputs = '';
3401            if( ref($targets) eq 'HASH' ) {
3402                my $inputs = ref($targets->{$target})
3403                    ? $targets->{$target}
3404                    : [$targets->{$target}];
3405
3406                for my $input (@$inputs) {
3407                    if( $Is{VMS} ) {
3408                        $input = vmsify($self->eliminate_macros($input));
3409                    }
3410                    $extra_inputs .= ' '.$input;
3411                }
3412            }
3413
3414            $m .= <<MAKE_FRAG;
3415
3416pure_all :: $target
3417	\$(NOECHO) \$(NOOP)
3418
3419$target :: $plfile $pm_dep $extra_inputs
3420	\$($perlrun) $plfile $target $extra_inputs
3421MAKE_FRAG
3422
3423        }
3424    }
3425
3426    return $m;
3427}
3428
3429=item specify_shell
3430
3431Specify SHELL if needed - not done on Unix.
3432
3433=cut
3434
3435sub specify_shell {
3436  return '';
3437}
3438
3439=item quote_paren
3440
3441Backslashes parentheses C<()> in command line arguments.
3442Doesn't handle recursive Makefile C<$(...)> constructs,
3443but handles simple ones.
3444
3445=cut
3446
3447sub quote_paren {
3448    my $arg = shift;
3449    $arg =~ s{\$\((.+?)\)}{\$\\\\($1\\\\)}g;	# protect $(...)
3450    $arg =~ s{(?<!\\)([()])}{\\$1}g;		# quote unprotected
3451    $arg =~ s{\$\\\\\((.+?)\\\\\)}{\$($1)}g;	# unprotect $(...)
3452    return $arg;
3453}
3454
3455=item replace_manpage_separator
3456
3457  my $man_name = $MM->replace_manpage_separator($file_path);
3458
3459Takes the name of a package, which may be a nested package, in the
3460form 'Foo/Bar.pm' and replaces the slash with C<::> or something else
3461safe for a man page file name.  Returns the replacement.
3462
3463=cut
3464
3465sub replace_manpage_separator {
3466    my($self,$man) = @_;
3467
3468    $man =~ s,/+,::,g;
3469    return $man;
3470}
3471
3472
3473=item cd
3474
3475=cut
3476
3477sub cd {
3478    my($self, $dir, @cmds) = @_;
3479
3480    # No leading tab and no trailing newline makes for easier embedding
3481    my $make_frag = join "\n\t", map { "cd $dir && $_" } @cmds;
3482
3483    return $make_frag;
3484}
3485
3486=item oneliner
3487
3488=cut
3489
3490sub oneliner {
3491    my($self, $cmd, $switches) = @_;
3492    $switches = [] unless defined $switches;
3493
3494    # Strip leading and trailing newlines
3495    $cmd =~ s{^\n+}{};
3496    $cmd =~ s{\n+$}{};
3497
3498    my @cmds = split /\n/, $cmd;
3499    $cmd = join " \n\t  -e ", map $self->quote_literal($_), @cmds;
3500    $cmd = $self->escape_newlines($cmd);
3501
3502    $switches = join ' ', @$switches;
3503
3504    return qq{\$(ABSPERLRUN) $switches -e $cmd --};
3505}
3506
3507
3508=item quote_literal
3509
3510Quotes macro literal value suitable for being used on a command line so
3511that when expanded by make, will be received by command as given to
3512this method:
3513
3514  my $quoted = $mm->quote_literal(q{it isn't});
3515  # returns:
3516  #   'it isn'\''t'
3517  print MAKEFILE "target:\n\techo $quoted\n";
3518  # when run "make target", will output:
3519  #   it isn't
3520
3521=cut
3522
3523sub quote_literal {
3524    my($self, $text, $opts) = @_;
3525    $opts->{allow_variables} = 1 unless defined $opts->{allow_variables};
3526
3527    # Quote single quotes
3528    $text =~ s{'}{'\\''}g;
3529
3530    $text = $opts->{allow_variables}
3531      ? $self->escape_dollarsigns($text) : $self->escape_all_dollarsigns($text);
3532
3533    return "'$text'";
3534}
3535
3536
3537=item escape_newlines
3538
3539=cut
3540
3541sub escape_newlines {
3542    my($self, $text) = @_;
3543
3544    $text =~ s{\n}{\\\n}g;
3545
3546    return $text;
3547}
3548
3549
3550=item max_exec_len
3551
3552Using L<POSIX>::ARG_MAX.  Otherwise falling back to 4096.
3553
3554=cut
3555
3556sub max_exec_len {
3557    my $self = shift;
3558
3559    if (!defined $self->{_MAX_EXEC_LEN}) {
3560        if (my $arg_max = eval { require POSIX;  &POSIX::ARG_MAX }) {
3561            $self->{_MAX_EXEC_LEN} = $arg_max;
3562        }
3563        else {      # POSIX minimum exec size
3564            $self->{_MAX_EXEC_LEN} = 4096;
3565        }
3566    }
3567
3568    return $self->{_MAX_EXEC_LEN};
3569}
3570
3571
3572=item static (o)
3573
3574Defines the static target.
3575
3576=cut
3577
3578sub static {
3579# --- Static Loading Sections ---
3580
3581    my($self) = shift;
3582    '
3583## $(INST_PM) has been moved to the all: target.
3584## It remains here for awhile to allow for old usage: "make static"
3585static :: $(FIRST_MAKEFILE) $(INST_STATIC)
3586	$(NOECHO) $(NOOP)
3587';
3588}
3589
3590sub static_lib {
3591    my($self) = @_;
3592    return '' unless $self->has_link_code;
3593    my(@m);
3594    my @libs;
3595    if ($self->{XSMULTI}) {
3596	for my $ext ($self->_xs_list_basenames) {
3597	    my ($v, $d, $f) = File::Spec->splitpath($ext);
3598	    my @d = File::Spec->splitdir($d);
3599	    shift @d if $d[0] eq 'lib';
3600	    my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
3601	    my $instfile = $self->catfile($instdir, "$f\$(LIB_EXT)");
3602	    my $objfile = "$ext\$(OBJ_EXT)";
3603	    push @libs, [ $objfile, $instfile, $instdir ];
3604	}
3605    } else {
3606	@libs = ([ qw($(OBJECT) $(INST_STATIC) $(INST_ARCHAUTODIR)) ]);
3607    }
3608    push @m, map { $self->xs_make_static_lib(@$_); } @libs;
3609    join "\n", @m;
3610}
3611
3612=item xs_make_static_lib
3613
3614Defines the recipes for the C<static_lib> section.
3615
3616=cut
3617
3618sub xs_make_static_lib {
3619    my ($self, $from, $to, $todir) = @_;
3620    my @m = sprintf '%s: %s $(MYEXTLIB) %s$(DFSEP).exists'."\n", $to, $from, $todir;
3621    push @m, "\t\$(RM_F) \"\$\@\"\n";
3622    push @m, $self->static_lib_fixtures;
3623    push @m, $self->static_lib_pure_cmd($from);
3624    push @m, "\t\$(CHMOD) \$(PERM_RWX) \$\@\n";
3625    push @m, $self->static_lib_closures($todir);
3626    join '', @m;
3627}
3628
3629=item static_lib_closures
3630
3631Records C<$(EXTRALIBS)> in F<extralibs.ld> and F<$(PERL_SRC)/ext.libs>.
3632
3633=cut
3634
3635sub static_lib_closures {
3636    my ($self, $todir) = @_;
3637    my @m = sprintf <<'MAKE_FRAG', $todir;
3638	$(NOECHO) $(ECHO) "$(EXTRALIBS)" > %s$(DFSEP)extralibs.ld
3639MAKE_FRAG
3640    # Old mechanism - still available:
3641    push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
3642	$(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)$(DFSEP)ext.libs
3643MAKE_FRAG
3644    @m;
3645}
3646
3647=item static_lib_fixtures
3648
3649Handles copying C<$(MYEXTLIB)> as starter for final static library that
3650then gets added to.
3651
3652=cut
3653
3654sub static_lib_fixtures {
3655    my ($self) = @_;
3656    # If this extension has its own library (eg SDBM_File)
3657    # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
3658    return unless $self->{MYEXTLIB};
3659    "\t\$(CP) \$(MYEXTLIB) \"\$\@\"\n";
3660}
3661
3662=item static_lib_pure_cmd
3663
3664Defines how to run the archive utility.
3665
3666=cut
3667
3668sub static_lib_pure_cmd {
3669    my ($self, $from) = @_;
3670    my $ar;
3671    if (exists $self->{FULL_AR} && -x $self->{FULL_AR}) {
3672        # Prefer the absolute pathed ar if available so that PATH
3673        # doesn't confuse us.  Perl itself is built with the full_ar.
3674        $ar = 'FULL_AR';
3675    } else {
3676        $ar = 'AR';
3677    }
3678    sprintf <<'MAKE_FRAG', $ar, $from;
3679	$(%s) $(AR_STATIC_ARGS) "$@" %s
3680	$(RANLIB) "$@"
3681MAKE_FRAG
3682}
3683
3684=item staticmake (o)
3685
3686Calls makeaperl.
3687
3688=cut
3689
3690sub staticmake {
3691    my($self, %attribs) = @_;
3692    my(@static);
3693
3694    my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
3695
3696    # And as it's not yet built, we add the current extension
3697    # but only if it has some C code (or XS code, which implies C code)
3698    if (@{$self->{C}}) {
3699	@static = $self->catfile($self->{INST_ARCHLIB},
3700				 "auto",
3701				 $self->{FULLEXT},
3702				 "$self->{BASEEXT}$self->{LIB_EXT}"
3703				);
3704    }
3705
3706    # Either we determine now, which libraries we will produce in the
3707    # subdirectories or we do it at runtime of the make.
3708
3709    # We could ask all subdir objects, but I cannot imagine, why it
3710    # would be necessary.
3711
3712    # Instead we determine all libraries for the new perl at
3713    # runtime.
3714    my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
3715
3716    $self->makeaperl(MAKE	=> $self->{MAKEFILE},
3717		     DIRS	=> \@searchdirs,
3718		     STAT	=> \@static,
3719		     INCL	=> \@perlinc,
3720		     TARGET	=> $self->{MAP_TARGET},
3721		     TMP	=> "",
3722		     LIBPERL	=> $self->{LIBPERL_A}
3723		    );
3724}
3725
3726=item subdir_x (o)
3727
3728Helper subroutine for subdirs
3729
3730=cut
3731
3732sub subdir_x {
3733    my($self, $subdir) = @_;
3734
3735    my $subdir_cmd = $self->cd($subdir,
3736      '$(MAKE) $(USEMAKEFILE) $(FIRST_MAKEFILE) all $(PASTHRU)'
3737    );
3738    return sprintf <<'EOT', $subdir_cmd;
3739
3740subdirs ::
3741	$(NOECHO) %s
3742EOT
3743
3744}
3745
3746=item subdirs (o)
3747
3748Defines targets to process subdirectories.
3749
3750=cut
3751
3752sub subdirs {
3753# --- Sub-directory Sections ---
3754    my($self) = shift;
3755    my(@m);
3756    # This method provides a mechanism to automatically deal with
3757    # subdirectories containing further Makefile.PL scripts.
3758    # It calls the subdir_x() method for each subdirectory.
3759    foreach my $dir (@{$self->{DIR}}){
3760	push @m, $self->subdir_x($dir);
3761####	print "Including $dir subdirectory\n";
3762    }
3763    if (@m){
3764	unshift @m, <<'EOF';
3765
3766# The default clean, realclean and test targets in this Makefile
3767# have automatically been given entries for each subdir.
3768
3769EOF
3770    } else {
3771	push(@m, "\n# none")
3772    }
3773    join('',@m);
3774}
3775
3776=item test (o)
3777
3778Defines the test targets.
3779
3780=cut
3781
3782sub test {
3783    my($self, %attribs) = @_;
3784    my $tests = $attribs{TESTS} || '';
3785    if (!$tests && -d 't' && defined $attribs{RECURSIVE_TEST_FILES}) {
3786        $tests = $self->find_tests_recursive;
3787    }
3788    elsif (!$tests && -d 't') {
3789        $tests = $self->find_tests;
3790    }
3791    # have to do this because nmake is broken
3792    $tests =~ s!/!\\!g if $self->is_make_type('nmake');
3793    # note: 'test.pl' name is also hardcoded in init_dirscan()
3794    my @m;
3795    my $default_testtype = $Config{usedl} ? 'dynamic' : 'static';
3796    push @m, <<EOF;
3797TEST_VERBOSE=0
3798TEST_TYPE=test_\$(LINKTYPE)
3799TEST_FILE = test.pl
3800TEST_FILES = $tests
3801TESTDB_SW = -d
3802
3803testdb :: testdb_\$(LINKTYPE)
3804	\$(NOECHO) \$(NOOP)
3805
3806test :: \$(TEST_TYPE)
3807	\$(NOECHO) \$(NOOP)
3808
3809# Occasionally we may face this degenerate target:
3810test_ : test_$default_testtype
3811	\$(NOECHO) \$(NOOP)
3812
3813EOF
3814
3815    for my $linktype (qw(dynamic static)) {
3816        my $directdeps = join ' ', grep !$self->{SKIPHASH}{$_}, $linktype, "pure_all"; # no depend on a linktype if SKIPped
3817        push @m, "subdirs-test_$linktype :: $directdeps\n";
3818        foreach my $dir (@{ $self->{DIR} }) {
3819            my $test = $self->cd($dir, "\$(MAKE) test_$linktype \$(PASTHRU)");
3820            push @m, "\t\$(NOECHO) $test\n";
3821        }
3822        push @m, "\n";
3823        if ($tests or -f "test.pl") {
3824            for my $testspec ([ '', '' ], [ 'db', ' $(TESTDB_SW)' ]) {
3825                my ($db, $switch) = @$testspec;
3826                my ($command, $deps);
3827                # if testdb, build all but don't test all
3828                $deps = $db eq 'db' ? $directdeps : "subdirs-test_$linktype";
3829                if ($linktype eq 'static' and $self->needs_linking) {
3830                    my $target = File::Spec->rel2abs('$(MAP_TARGET)');
3831                    $command = qq{"$target" \$(MAP_PERLINC)};
3832                    $deps .= ' $(MAP_TARGET)';
3833                } else {
3834                    $command = '$(FULLPERLRUN)' . $switch;
3835                }
3836                push @m, "test${db}_$linktype :: $deps\n";
3837                if ($db eq 'db') {
3838                    push @m, $self->test_via_script($command, '$(TEST_FILE)')
3839                } else {
3840                    push @m, $self->test_via_script($command, '$(TEST_FILE)')
3841                        if -f "test.pl";
3842                    push @m, $self->test_via_harness($command, '$(TEST_FILES)')
3843                        if $tests;
3844                }
3845                push @m, "\n";
3846            }
3847        } else {
3848            push @m, _sprintf562 <<'EOF', $linktype;
3849testdb_%1$s test_%1$s :: subdirs-test_%1$s
3850	$(NOECHO) $(ECHO) 'No tests defined for $(NAME) extension.'
3851
3852EOF
3853        }
3854    }
3855
3856    join "", @m;
3857}
3858
3859=item test_via_harness (override)
3860
3861For some reason which I forget, Unix machines like to have
3862PERL_DL_NONLAZY set for tests.
3863
3864=cut
3865
3866sub test_via_harness {
3867    my($self, $perl, $tests) = @_;
3868    return $self->SUPER::test_via_harness("PERL_DL_NONLAZY=1 $perl", $tests);
3869}
3870
3871=item test_via_script (override)
3872
3873Again, the PERL_DL_NONLAZY thing.
3874
3875=cut
3876
3877sub test_via_script {
3878    my($self, $perl, $script) = @_;
3879    return $self->SUPER::test_via_script("PERL_DL_NONLAZY=1 $perl", $script);
3880}
3881
3882
3883=item tool_xsubpp (o)
3884
3885Determines typemaps, xsubpp version, prototype behaviour.
3886
3887=cut
3888
3889sub tool_xsubpp {
3890    my($self) = shift;
3891    return "" unless $self->needs_linking;
3892
3893    my $xsdir;
3894    my @xsubpp_dirs = @INC;
3895
3896    # Make sure we pick up the new xsubpp if we're building perl.
3897    unshift @xsubpp_dirs, $self->{PERL_LIB} if $self->{PERL_CORE};
3898
3899    my $foundxsubpp = 0;
3900    foreach my $dir (@xsubpp_dirs) {
3901        $xsdir = $self->catdir($dir, 'ExtUtils');
3902        if( -r $self->catfile($xsdir, "xsubpp") ) {
3903            $foundxsubpp = 1;
3904            last;
3905        }
3906    }
3907    die "ExtUtils::MM_Unix::tool_xsubpp : Can't find xsubpp" if !$foundxsubpp;
3908
3909    my $tmdir   = $self->catdir($self->{PERL_LIB},"ExtUtils");
3910    my(@tmdeps) = $self->catfile($tmdir,'typemap');
3911    if( $self->{TYPEMAPS} ){
3912        foreach my $typemap (@{$self->{TYPEMAPS}}){
3913            if( ! -f  $typemap ) {
3914                warn "Typemap $typemap not found.\n";
3915            }
3916            else {
3917                $typemap = vmsify($typemap) if $Is{VMS};
3918                push(@tmdeps, $typemap);
3919            }
3920        }
3921    }
3922    push(@tmdeps, "typemap") if -f "typemap";
3923    # absolutised because with deep-located typemaps, eg "lib/XS/typemap",
3924    # if xsubpp is called from top level with
3925    #     $(XSUBPP) ... -typemap "lib/XS/typemap" "lib/XS/Test.xs"
3926    # it says:
3927    #     Can't find lib/XS/type map in (fulldir)/lib/XS
3928    # because ExtUtils::ParseXS::process_file chdir's to .xs file's
3929    # location. This is the only way to get all specified typemaps used,
3930    # wherever located.
3931    my @tmargs = map { '-typemap '.$self->quote_literal(File::Spec->rel2abs($_)) } @tmdeps;
3932    $_ = $self->quote_dep($_) for @tmdeps;
3933    if( exists $self->{XSOPT} ){
3934        unshift( @tmargs, $self->{XSOPT} );
3935    }
3936
3937    if ($Is{VMS}                          &&
3938        $Config{'ldflags'}               &&
3939        $Config{'ldflags'} =~ m!/Debug!i &&
3940        (!exists($self->{XSOPT}) || $self->{XSOPT} !~ /linenumbers/)
3941       )
3942    {
3943        unshift(@tmargs,'-nolinenumbers');
3944    }
3945
3946
3947    $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
3948    my $xsdirdep = $self->quote_dep($xsdir);
3949    # -dep for use when dependency not command
3950
3951    return qq{
3952XSUBPPDIR = $xsdir
3953XSUBPP = "\$(XSUBPPDIR)\$(DFSEP)xsubpp"
3954XSUBPPRUN = \$(PERLRUN) \$(XSUBPP)
3955XSPROTOARG = $self->{XSPROTOARG}
3956XSUBPPDEPS = @tmdeps $xsdirdep\$(DFSEP)xsubpp
3957XSUBPPARGS = @tmargs
3958XSUBPP_EXTRA_ARGS =
3959};
3960}
3961
3962
3963=item all_target
3964
3965Build man pages, too
3966
3967=cut
3968
3969sub all_target {
3970    my $self = shift;
3971
3972    return <<'MAKE_EXT';
3973all :: pure_all manifypods
3974	$(NOECHO) $(NOOP)
3975MAKE_EXT
3976}
3977
3978=item top_targets (o)
3979
3980Defines the targets all, subdirs, config, and O_FILES
3981
3982=cut
3983
3984sub top_targets {
3985# --- Target Sections ---
3986
3987    my($self) = shift;
3988    my(@m);
3989
3990    push @m, $self->all_target, "\n" unless $self->{SKIPHASH}{'all'};
3991
3992    push @m, sprintf <<'EOF';
3993pure_all :: config pm_to_blib subdirs linkext
3994	$(NOECHO) $(NOOP)
3995
3996subdirs :: $(MYEXTLIB)
3997	$(NOECHO) $(NOOP)
3998
3999config :: $(FIRST_MAKEFILE) blibdirs
4000	$(NOECHO) $(NOOP)
4001EOF
4002
4003    push @m, '
4004$(O_FILES) : $(H_FILES)
4005' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
4006
4007    push @m, q{
4008help :
4009	perldoc ExtUtils::MakeMaker
4010};
4011
4012    join('',@m);
4013}
4014
4015=item writedoc
4016
4017Obsolete, deprecated method. Not used since Version 5.21.
4018
4019=cut
4020
4021sub writedoc {
4022# --- perllocal.pod section ---
4023    my($self,$what,$name,@attribs)=@_;
4024    my $time = gmtime($ENV{SOURCE_DATE_EPOCH} || time);
4025    print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
4026    print join "\n\n=item *\n\n", map("C<$_>",@attribs);
4027    print "\n\n=back\n\n";
4028}
4029
4030=item xs_c (o)
4031
4032Defines the suffix rules to compile XS files to C.
4033
4034=cut
4035
4036sub xs_c {
4037    my($self) = shift;
4038    return '' unless $self->needs_linking();
4039    '
4040.xs.c:
4041	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc
4042	$(MV) $*.xsc $*.c
4043';
4044}
4045
4046=item xs_cpp (o)
4047
4048Defines the suffix rules to compile XS files to C++.
4049
4050=cut
4051
4052sub xs_cpp {
4053    my($self) = shift;
4054    return '' unless $self->needs_linking();
4055    '
4056.xs.cpp:
4057	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
4058	$(MV) $*.xsc $*.cpp
4059';
4060}
4061
4062=item xs_o (o)
4063
4064Defines suffix rules to go from XS to object files directly. This was
4065originally only intended for broken make implementations, but is now
4066necessary for per-XS file under C<XSMULTI>, since each XS file might
4067have an individual C<$(VERSION)>.
4068
4069=cut
4070
4071sub xs_o {
4072    my ($self) = @_;
4073    return '' unless $self->needs_linking();
4074    my $m_o = $self->{XSMULTI} ? $self->xs_obj_opt('$*$(OBJ_EXT)') : '';
4075    my $dbgout = $self->dbgoutflag;
4076    $dbgout = $dbgout ? "$dbgout " : '';
4077    my $frag = '';
4078    # dmake makes noise about ambiguous rule
4079    $frag .= sprintf <<'EOF', $dbgout, $m_o unless $self->is_make_type('dmake');
4080.xs$(OBJ_EXT) :
4081	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
4082	$(MV) $*.xsc $*.c
4083	$(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) %s$*.c %s
4084EOF
4085    if ($self->{XSMULTI}) {
4086	for my $ext ($self->_xs_list_basenames) {
4087	    my $pmfile = "$ext.pm";
4088	    croak "$ext.xs has no matching $pmfile: $!" unless -f $pmfile;
4089	    my $version = $self->parse_version($pmfile);
4090	    my $cccmd = $self->{CONST_CCCMD};
4091	    $cccmd =~ s/^\s*CCCMD\s*=\s*//;
4092	    $cccmd =~ s/\$\(DEFINE_VERSION\)/-DVERSION=\\"$version\\"/;
4093	    $cccmd =~ s/\$\(XS_DEFINE_VERSION\)/-DXS_VERSION=\\"$version\\"/;
4094            $self->_xsbuild_replace_macro($cccmd, 'xs', $ext, 'INC');
4095            my $define = '$(DEFINE)';
4096            $self->_xsbuild_replace_macro($define, 'xs', $ext, 'DEFINE');
4097            #                             1     2       3     4        5
4098            $frag .= _sprintf562 <<'EOF', $ext, $cccmd, $m_o, $define, $dbgout;
4099
4100%1$s$(OBJ_EXT): %1$s.xs
4101	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
4102	$(MV) $*.xsc $*.c
4103	%2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) %4$s %5$s$*.c %3$s
4104EOF
4105	}
4106    }
4107    $frag =~ s/"-I(\$\(PERL_INC\))"/-iwithsysroot "$1"/sg if $Is{ApplCor};
4108    $frag;
4109}
4110
4111# param gets modified
4112sub _xsbuild_replace_macro {
4113    my ($self, undef, $xstype, $ext, $varname) = @_;
4114    my $value = $self->_xsbuild_value($xstype, $ext, $varname);
4115    return unless defined $value;
4116    $_[1] =~ s/\$\($varname\)/$value/;
4117}
4118
4119sub _xsbuild_value {
4120    my ($self, $xstype, $ext, $varname) = @_;
4121    return $self->{XSBUILD}{$xstype}{$ext}{$varname}
4122        if $self->{XSBUILD}{$xstype}{$ext}{$varname};
4123    return $self->{XSBUILD}{$xstype}{all}{$varname}
4124        if $self->{XSBUILD}{$xstype}{all}{$varname};
4125    ();
4126}
4127
41281;
4129
4130=back
4131
4132=head1 SEE ALSO
4133
4134L<ExtUtils::MakeMaker>
4135
4136=cut
4137
4138__END__
4139