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    my $perm_dir = $self->{PERL_CORE} ? 770 : 755;
2233    $self->{PERM_DIR} = $perm_dir  unless defined $self->{PERM_DIR};
2234    $self->{PERM_RW}  = 644  unless defined $self->{PERM_RW};
2235    $self->{PERM_RWX} = 755  unless defined $self->{PERM_RWX};
2236
2237    return 1;
2238}
2239
2240
2241=item init_xs
2242
2243    $mm->init_xs
2244
2245Sets up macros having to do with XS code.  Currently just INST_STATIC,
2246INST_DYNAMIC and INST_BOOT.
2247
2248=cut
2249
2250sub init_xs {
2251    my $self = shift;
2252
2253    if ($self->has_link_code()) {
2254        $self->{INST_STATIC}  =
2255          $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT)$(LIB_EXT)');
2256        $self->{INST_DYNAMIC} =
2257          $self->catfile('$(INST_ARCHAUTODIR)', '$(DLBASE).$(DLEXT)');
2258        $self->{INST_BOOT}    =
2259          $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT).bs');
2260	if ($self->{XSMULTI}) {
2261	    my @exts = $self->_xs_list_basenames;
2262	    my (@statics, @dynamics, @boots);
2263	    for my $ext (@exts) {
2264		my ($v, $d, $f) = File::Spec->splitpath($ext);
2265		my @d = File::Spec->splitdir($d);
2266		shift @d if defined $d[0] and $d[0] eq 'lib';
2267		pop @d if $d[$#d] eq '';
2268		my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
2269		my $instfile = $self->catfile($instdir, $f);
2270		push @statics, "$instfile\$(LIB_EXT)";
2271
2272                # Dynamic library names may need special handling.
2273                my $dynfile = $instfile;
2274                eval { require DynaLoader };
2275                if (defined &DynaLoader::mod2fname) {
2276                    $dynfile = $self->catfile($instdir, &DynaLoader::mod2fname([@d, $f]));
2277                }
2278
2279		push @dynamics, "$dynfile.\$(DLEXT)";
2280		push @boots, "$instfile.bs";
2281	    }
2282	    $self->{INST_STATIC} = join ' ', @statics;
2283	    $self->{INST_DYNAMIC} = join ' ', @dynamics;
2284	    $self->{INST_BOOT} = join ' ', @boots;
2285	}
2286    } else {
2287        $self->{INST_STATIC}  = '';
2288        $self->{INST_DYNAMIC} = '';
2289        $self->{INST_BOOT}    = '';
2290    }
2291}
2292
2293=item install (o)
2294
2295Defines the install target.
2296
2297=cut
2298
2299sub install {
2300    my($self, %attribs) = @_;
2301    my(@m);
2302
2303    push @m, q{
2304install :: pure_install doc_install
2305	$(NOECHO) $(NOOP)
2306
2307install_perl :: pure_perl_install doc_perl_install
2308	$(NOECHO) $(NOOP)
2309
2310install_site :: pure_site_install doc_site_install
2311	$(NOECHO) $(NOOP)
2312
2313install_vendor :: pure_vendor_install doc_vendor_install
2314	$(NOECHO) $(NOOP)
2315
2316pure_install :: pure_$(INSTALLDIRS)_install
2317	$(NOECHO) $(NOOP)
2318
2319doc_install :: doc_$(INSTALLDIRS)_install
2320	$(NOECHO) $(NOOP)
2321
2322pure__install : pure_site_install
2323	$(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2324
2325doc__install : doc_site_install
2326	$(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2327
2328pure_perl_install :: all
2329	$(NOECHO) $(MOD_INSTALL) \
2330};
2331
2332    push @m,
2333q{		read "}.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{" \
2334		write "}.$self->catfile('$(DESTINSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{" \
2335} unless $self->{NO_PACKLIST};
2336
2337    push @m,
2338q{		"$(INST_LIB)" "$(DESTINSTALLPRIVLIB)" \
2339		"$(INST_ARCHLIB)" "$(DESTINSTALLARCHLIB)" \
2340		"$(INST_BIN)" "$(DESTINSTALLBIN)" \
2341		"$(INST_SCRIPT)" "$(DESTINSTALLSCRIPT)" \
2342		"$(INST_MAN1DIR)" "$(DESTINSTALLMAN1DIR)" \
2343		"$(INST_MAN3DIR)" "$(DESTINSTALLMAN3DIR)"
2344	$(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2345		"}.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{"
2346
2347
2348pure_site_install :: all
2349	$(NOECHO) $(MOD_INSTALL) \
2350};
2351    push @m,
2352q{		read "}.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{" \
2353		write "}.$self->catfile('$(DESTINSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{" \
2354} unless $self->{NO_PACKLIST};
2355
2356    push @m,
2357q{		"$(INST_LIB)" "$(DESTINSTALLSITELIB)" \
2358		"$(INST_ARCHLIB)" "$(DESTINSTALLSITEARCH)" \
2359		"$(INST_BIN)" "$(DESTINSTALLSITEBIN)" \
2360		"$(INST_SCRIPT)" "$(DESTINSTALLSITESCRIPT)" \
2361		"$(INST_MAN1DIR)" "$(DESTINSTALLSITEMAN1DIR)" \
2362		"$(INST_MAN3DIR)" "$(DESTINSTALLSITEMAN3DIR)"
2363	$(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2364		"}.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{"
2365
2366pure_vendor_install :: all
2367	$(NOECHO) $(MOD_INSTALL) \
2368};
2369    push @m,
2370q{		read "}.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{" \
2371		write "}.$self->catfile('$(DESTINSTALLVENDORARCH)','auto','$(FULLEXT)','.packlist').q{" \
2372} unless $self->{NO_PACKLIST};
2373
2374    push @m,
2375q{		"$(INST_LIB)" "$(DESTINSTALLVENDORLIB)" \
2376		"$(INST_ARCHLIB)" "$(DESTINSTALLVENDORARCH)" \
2377		"$(INST_BIN)" "$(DESTINSTALLVENDORBIN)" \
2378		"$(INST_SCRIPT)" "$(DESTINSTALLVENDORSCRIPT)" \
2379		"$(INST_MAN1DIR)" "$(DESTINSTALLVENDORMAN1DIR)" \
2380		"$(INST_MAN3DIR)" "$(DESTINSTALLVENDORMAN3DIR)"
2381
2382};
2383
2384    push @m, q{
2385doc_perl_install :: all
2386	$(NOECHO) $(NOOP)
2387
2388doc_site_install :: all
2389	$(NOECHO) $(NOOP)
2390
2391doc_vendor_install :: all
2392	$(NOECHO) $(NOOP)
2393
2394} if $self->{NO_PERLLOCAL};
2395
2396    push @m, q{
2397doc_perl_install :: all
2398	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2399	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2400	-$(NOECHO) $(DOC_INSTALL) \
2401		"Module" "$(NAME)" \
2402		"installed into" "$(INSTALLPRIVLIB)" \
2403		LINKTYPE "$(LINKTYPE)" \
2404		VERSION "$(VERSION)" \
2405		EXE_FILES "$(EXE_FILES)" \
2406		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2407
2408doc_site_install :: all
2409	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2410	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2411	-$(NOECHO) $(DOC_INSTALL) \
2412		"Module" "$(NAME)" \
2413		"installed into" "$(INSTALLSITELIB)" \
2414		LINKTYPE "$(LINKTYPE)" \
2415		VERSION "$(VERSION)" \
2416		EXE_FILES "$(EXE_FILES)" \
2417		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2418
2419doc_vendor_install :: all
2420	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2421	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2422	-$(NOECHO) $(DOC_INSTALL) \
2423		"Module" "$(NAME)" \
2424		"installed into" "$(INSTALLVENDORLIB)" \
2425		LINKTYPE "$(LINKTYPE)" \
2426		VERSION "$(VERSION)" \
2427		EXE_FILES "$(EXE_FILES)" \
2428		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2429
2430} unless $self->{NO_PERLLOCAL};
2431
2432    push @m, q{
2433uninstall :: uninstall_from_$(INSTALLDIRS)dirs
2434	$(NOECHO) $(NOOP)
2435
2436uninstall_from_perldirs ::
2437	$(NOECHO) $(UNINSTALL) "}.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{"
2438
2439uninstall_from_sitedirs ::
2440	$(NOECHO) $(UNINSTALL) "}.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{"
2441
2442uninstall_from_vendordirs ::
2443	$(NOECHO) $(UNINSTALL) "}.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{"
2444};
2445
2446    join("",@m);
2447}
2448
2449=item installbin (o)
2450
2451Defines targets to make and to install EXE_FILES.
2452
2453=cut
2454
2455sub installbin {
2456    my($self) = shift;
2457
2458    return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
2459    my @exefiles = sort @{$self->{EXE_FILES}};
2460    return "" unless @exefiles;
2461
2462    @exefiles = map vmsify($_), @exefiles if $Is{VMS};
2463
2464    my %fromto;
2465    for my $from (@exefiles) {
2466	my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
2467
2468	local($_) = $path; # for backwards compatibility
2469	my $to = $self->libscan($path);
2470	print "libscan($from) => '$to'\n" if ($Verbose >=2);
2471
2472        $to = vmsify($to) if $Is{VMS};
2473	$fromto{$from} = $to;
2474    }
2475    my @to   = sort values %fromto;
2476
2477    my @m;
2478    push(@m, qq{
2479EXE_FILES = @exefiles
2480
2481pure_all :: @to
2482	\$(NOECHO) \$(NOOP)
2483
2484realclean ::
2485});
2486
2487    # realclean can get rather large.
2488    push @m, map "\t$_\n", $self->split_command('$(RM_F)', @to);
2489    push @m, "\n";
2490
2491    # A target for each exe file.
2492    my @froms = sort keys %fromto;
2493    for my $from (@froms) {
2494        #                              1      2
2495        push @m, _sprintf562 <<'MAKE', $from, $fromto{$from};
2496%2$s : %1$s $(FIRST_MAKEFILE) $(INST_SCRIPT)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists
2497	$(NOECHO) $(RM_F) %2$s
2498	$(CP) %1$s %2$s
2499	$(FIXIN) %2$s
2500	-$(NOECHO) $(CHMOD) $(PERM_RWX) %2$s
2501
2502MAKE
2503
2504    }
2505
2506    join "", @m;
2507}
2508
2509=item linkext (o)
2510
2511Defines the linkext target which in turn defines the LINKTYPE.
2512
2513=cut
2514
2515# LINKTYPE => static or dynamic or ''
2516sub linkext {
2517    my($self, %attribs) = @_;
2518    my $linktype = $attribs{LINKTYPE};
2519    $linktype = $self->{LINKTYPE} unless defined $linktype;
2520    if (defined $linktype and $linktype eq '') {
2521        warn "Warning: LINKTYPE set to '', no longer necessary\n";
2522    }
2523    $linktype = '$(LINKTYPE)' unless defined $linktype;
2524    "
2525linkext :: $linktype
2526	\$(NOECHO) \$(NOOP)
2527";
2528}
2529
2530=item lsdir
2531
2532Takes as arguments a directory name and a regular expression. Returns
2533all entries in the directory that match the regular expression.
2534
2535=cut
2536
2537sub lsdir {
2538    #  $self
2539    my(undef, $dir, $regex) = @_;
2540    opendir(my $dh, defined($dir) ? $dir : ".")
2541        or return;
2542    my @ls = readdir $dh;
2543    closedir $dh;
2544    @ls = grep(/$regex/, @ls) if defined $regex;
2545    @ls;
2546}
2547
2548=item macro (o)
2549
2550Simple subroutine to insert the macros defined by the macro attribute
2551into the Makefile.
2552
2553=cut
2554
2555sub macro {
2556    my($self,%attribs) = @_;
2557    my @m;
2558    foreach my $key (sort keys %attribs) {
2559	my $val = $attribs{$key};
2560	push @m, "$key = $val\n";
2561    }
2562    join "", @m;
2563}
2564
2565=item makeaperl (o)
2566
2567Called by staticmake. Defines how to write the Makefile to produce a
2568static new perl.
2569
2570By default the Makefile produced includes all the static extensions in
2571the perl library. (Purified versions of library files, e.g.,
2572DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
2573
2574=cut
2575
2576sub makeaperl {
2577    my($self, %attribs) = @_;
2578    my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
2579	@attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
2580    s/^(.*)/"-I$1"/ for @{$perlinc || []};
2581    my(@m);
2582    push @m, "
2583# --- MakeMaker makeaperl section ---
2584MAP_TARGET    = $target
2585FULLPERL      = $self->{FULLPERL}
2586MAP_PERLINC   = @{$perlinc || []}
2587";
2588    return join '', @m if $self->{PARENT};
2589
2590    my($dir) = join ":", @{$self->{DIR}};
2591
2592    unless ($self->{MAKEAPERL}) {
2593	push @m, q{
2594$(MAP_TARGET) :: $(MAKE_APERL_FILE)
2595	$(MAKE) $(USEMAKEFILE) $(MAKE_APERL_FILE) $@
2596
2597$(MAKE_APERL_FILE) : static $(FIRST_MAKEFILE) pm_to_blib
2598	$(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
2599	$(NOECHO) $(PERLRUNINST) \
2600		Makefile.PL DIR="}, $dir, q{" \
2601		MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
2602		MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
2603
2604	foreach (@ARGV){
2605		my $arg = $_; # avoid lvalue aliasing
2606		if ( $arg =~ /(^.*?=)(.*['\s].*)/ ) {
2607			$arg = $1 . $self->quote_literal($2);
2608		}
2609		push @m, " \\\n\t\t$arg";
2610	}
2611	push @m, "\n";
2612
2613	return join '', @m;
2614    }
2615
2616    my $cccmd = $self->const_cccmd($libperl);
2617    $cccmd =~ s/^CCCMD\s*=\s*//;
2618    $cccmd =~ s/\$\(INC\)/ "-I$self->{PERL_INC}" /;
2619    $cccmd .= " $Config{cccdlflags}"
2620	if ($Config{useshrplib} eq 'true');
2621    $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
2622
2623    # The front matter of the linkcommand...
2624    my $linkcmd = join ' ', "\$(CC)",
2625	    grep($_, @Config{qw(ldflags ccdlflags)});
2626    $linkcmd =~ s/\s+/ /g;
2627    $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
2628
2629    # Which *.a files could we make use of...
2630    my $staticlib21 = $self->_find_static_libs($searchdirs);
2631    # We trust that what has been handed in as argument, will be buildable
2632    $static = [] unless $static;
2633    @$staticlib21{@{$static}} = (1) x @{$static};
2634
2635    $extra = [] unless $extra && ref $extra eq 'ARRAY';
2636    for (sort keys %$staticlib21) {
2637	next unless /\Q$self->{LIB_EXT}\E\z/;
2638	$_ = dirname($_) . "/extralibs.ld";
2639	push @$extra, $_;
2640    }
2641
2642    s/^(.*)/"-I$1"/ for @{$perlinc || []};
2643
2644    $target ||= "perl";
2645    $tmp    ||= ".";
2646
2647# MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
2648# regenerate the Makefiles, MAP_STATIC and the dependencies for
2649# extralibs.all are computed correctly
2650    my @map_static = reverse sort keys %$staticlib21;
2651    push @m, "
2652MAP_LINKCMD   = $linkcmd
2653MAP_STATIC    = ", join(" \\\n\t", map { qq{"$_"} } @map_static), "
2654MAP_STATICDEP = ", join(' ', map { $self->quote_dep($_) } @map_static), "
2655
2656MAP_PRELIBS   = $Config{perllibs} $Config{cryptlib}
2657";
2658
2659    my $lperl;
2660    if (defined $libperl) {
2661	($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
2662    }
2663    unless ($libperl && -f $lperl) { # Ilya's code...
2664	my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
2665	$dir = "$self->{PERL_ARCHLIB}/.." if $self->{UNINSTALLED_PERL};
2666	$libperl ||= "libperl$self->{LIB_EXT}";
2667	$libperl   = "$dir/$libperl";
2668	$lperl   ||= "libperl$self->{LIB_EXT}";
2669	$lperl     = "$dir/$lperl";
2670
2671        if (! -f $libperl and ! -f $lperl) {
2672          # We did not find a static libperl. Maybe there is a shared one?
2673          if ($Is{SunOS}) {
2674            $lperl  = $libperl = "$dir/$Config{libperl}";
2675            # SUNOS ld does not take the full path to a shared library
2676            $libperl = '' if $Is{SunOS4};
2677          }
2678        }
2679
2680	print <<EOF unless -f $lperl || defined($self->{PERL_SRC});
2681Warning: $libperl not found
2682If you're going to build a static perl binary, make sure perl is installed
2683otherwise ignore this warning
2684EOF
2685    }
2686
2687    # SUNOS ld does not take the full path to a shared library
2688    my $llibperl = $libperl ? '$(MAP_LIBPERL)' : '-lperl';
2689    my $libperl_dep = $self->quote_dep($libperl);
2690
2691    push @m, "
2692MAP_LIBPERL = $libperl
2693MAP_LIBPERLDEP = $libperl_dep
2694LLIBPERL    = $llibperl
2695";
2696
2697    push @m, '
2698$(INST_ARCHAUTODIR)/extralibs.all : $(INST_ARCHAUTODIR)$(DFSEP).exists '.join(" \\\n\t", @$extra).'
2699	$(NOECHO) $(RM_F)  $@
2700	$(NOECHO) $(TOUCH) $@
2701';
2702
2703    foreach my $catfile (@$extra){
2704	push @m, "\tcat $catfile >> \$\@\n";
2705    }
2706
2707    my $ldfrom = $self->{XSMULTI} ? '' : '$(LDFROM)';
2708    #                             1     2                        3        4
2709    push @m, _sprintf562 <<'EOF', $tmp, $ldfrom, $self->xs_obj_opt('$@'), $makefilename;
2710$(MAP_TARGET) :: %1$s/perlmain$(OBJ_EXT) $(MAP_LIBPERLDEP) $(MAP_STATICDEP) $(INST_ARCHAUTODIR)/extralibs.all
2711	$(MAP_LINKCMD) %2$s $(OPTIMIZE) %1$s/perlmain$(OBJ_EXT) %3$s $(MAP_STATIC) "$(LLIBPERL)" `cat $(INST_ARCHAUTODIR)/extralibs.all` $(MAP_PRELIBS)
2712	$(NOECHO) $(ECHO) "To install the new '$(MAP_TARGET)' binary, call"
2713	$(NOECHO) $(ECHO) "    $(MAKE) $(USEMAKEFILE) %4$s inst_perl MAP_TARGET=$(MAP_TARGET)"
2714	$(NOECHO) $(ECHO) "    $(MAKE) $(USEMAKEFILE) %4$s map_clean"
2715
2716%1$s/perlmain\$(OBJ_EXT): %1$s/perlmain.c
2717EOF
2718    push @m, "\t".$self->cd($tmp, qq[$cccmd "-I\$(PERL_INC)" perlmain.c])."\n";
2719
2720    my $maybe_DynaLoader = $Config{usedl} ? 'q(DynaLoader)' : '';
2721    push @m, _sprintf562 <<'EOF', $tmp, $makefilename, $maybe_DynaLoader;
2722
2723%1$s/perlmain.c: %2$s
2724	$(NOECHO) $(ECHO) Writing $@
2725	$(NOECHO) $(PERL) $(MAP_PERLINC) "-MExtUtils::Miniperl" \
2726		-e "writemain(grep(s#.*/auto/##s, @ARGV), %3$s)" $(MAP_STATIC) > $@t
2727	$(MV) $@t $@
2728
2729EOF
2730    push @m, "\t", q{$(NOECHO) $(PERL) "$(INSTALLSCRIPT)/fixpmain"
2731} if (defined (&Dos::UseLFN) && Dos::UseLFN()==0);
2732
2733
2734    push @m, q{
2735doc_inst_perl :
2736	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2737	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2738	-$(NOECHO) $(DOC_INSTALL) \
2739		"Perl binary" "$(MAP_TARGET)" \
2740		MAP_STATIC "$(MAP_STATIC)" \
2741		MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
2742		MAP_LIBPERL "$(MAP_LIBPERL)" \
2743		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2744
2745};
2746
2747    push @m, q{
2748inst_perl : pure_inst_perl doc_inst_perl
2749
2750pure_inst_perl : $(MAP_TARGET)
2751	}.$self->{CP}.q{ $(MAP_TARGET) "}.$self->catfile('$(DESTINSTALLBIN)','$(MAP_TARGET)').q{"
2752
2753clean :: map_clean
2754
2755map_clean :
2756	}.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
2757};
2758
2759    join '', @m;
2760}
2761
2762# utility method
2763sub _find_static_libs {
2764    my ($self, $searchdirs) = @_;
2765    # don't use File::Spec here because on Win32 F::F still uses "/"
2766    my $installed_version = join('/',
2767	'auto', $self->{FULLEXT}, "$self->{BASEEXT}$self->{LIB_EXT}"
2768    );
2769    my %staticlib21;
2770    require File::Find;
2771    File::Find::find(sub {
2772	if ($File::Find::name =~ m{/auto/share\z}) {
2773	    # in a subdir of auto/share, prune because e.g.
2774	    # Alien::pkgconfig uses File::ShareDir to put .a files
2775	    # there. do not want
2776	    $File::Find::prune = 1;
2777	    return;
2778	}
2779
2780	return unless m/\Q$self->{LIB_EXT}\E$/;
2781
2782	return unless -f 'extralibs.ld'; # this checks is a "proper" XS installation
2783
2784        # Skip perl's libraries.
2785        return if m/^libperl/ or m/^perl\Q$self->{LIB_EXT}\E$/;
2786
2787	# Skip purified versions of libraries
2788        # (e.g., DynaLoader_pure_p1_c0_032.a)
2789	return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
2790
2791	if( exists $self->{INCLUDE_EXT} ){
2792		my $found = 0;
2793
2794		(my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
2795		$xx =~ s,/?$_,,;
2796		$xx =~ s,/,::,g;
2797
2798		# Throw away anything not explicitly marked for inclusion.
2799		# DynaLoader is implied.
2800		foreach my $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
2801			if( $xx eq $incl ){
2802				$found++;
2803				last;
2804			}
2805		}
2806		return unless $found;
2807	}
2808	elsif( exists $self->{EXCLUDE_EXT} ){
2809		(my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
2810		$xx =~ s,/?$_,,;
2811		$xx =~ s,/,::,g;
2812
2813		# Throw away anything explicitly marked for exclusion
2814		foreach my $excl (@{$self->{EXCLUDE_EXT}}){
2815			return if( $xx eq $excl );
2816		}
2817	}
2818
2819	# don't include the installed version of this extension. I
2820	# leave this line here, although it is not necessary anymore:
2821	# I patched minimod.PL instead, so that Miniperl.pm won't
2822	# include duplicates
2823
2824	# Once the patch to minimod.PL is in the distribution, I can
2825	# drop it
2826	return if $File::Find::name =~ m:\Q$installed_version\E\z:;
2827	return if !$self->xs_static_lib_is_xs($_);
2828	use Cwd 'cwd';
2829	$staticlib21{cwd() . "/" . $_}++;
2830    }, grep( -d $_, map { $self->catdir($_, 'auto') } @{$searchdirs || []}) );
2831    return \%staticlib21;
2832}
2833
2834=item xs_static_lib_is_xs (o)
2835
2836Called by a utility method of makeaperl. Checks whether a given file
2837is an XS library by seeing whether it defines any symbols starting
2838with C<boot_> (with an optional leading underscore - needed on MacOS).
2839
2840=cut
2841
2842sub xs_static_lib_is_xs {
2843    my ($self, $libfile) = @_;
2844    my $devnull = File::Spec->devnull;
2845    return `nm $libfile 2>$devnull` =~ /\b_?boot_/;
2846}
2847
2848=item makefile (o)
2849
2850Defines how to rewrite the Makefile.
2851
2852=cut
2853
2854sub makefile {
2855    my($self) = shift;
2856    my $m;
2857    # We do not know what target was originally specified so we
2858    # must force a manual rerun to be sure. But as it should only
2859    # happen very rarely it is not a significant problem.
2860    $m = '
2861$(OBJECT) : $(FIRST_MAKEFILE)
2862
2863' if $self->{OBJECT};
2864
2865    my $newer_than_target = $Is{VMS} ? '$(MMS$SOURCE_LIST)' : '$?';
2866    my $mpl_args = join " ", map qq["$_"], @ARGV;
2867    my $cross = '';
2868    if (defined $::Cross::platform) {
2869        # Inherited from win32/buildext.pl
2870        $cross = "-MCross=$::Cross::platform ";
2871    }
2872    $m .= sprintf <<'MAKE_FRAG', $newer_than_target, $cross, $mpl_args;
2873# We take a very conservative approach here, but it's worth it.
2874# We move Makefile to Makefile.old here to avoid gnu make looping.
2875$(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP)
2876	$(NOECHO) $(ECHO) "Makefile out-of-date with respect to %s"
2877	$(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..."
2878	-$(NOECHO) $(RM_F) $(MAKEFILE_OLD)
2879	-$(NOECHO) $(MV)   $(FIRST_MAKEFILE) $(MAKEFILE_OLD)
2880	- $(MAKE) $(USEMAKEFILE) $(MAKEFILE_OLD) clean $(DEV_NULL)
2881	$(PERLRUN) %sMakefile.PL %s
2882	$(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <=="
2883	$(NOECHO) $(ECHO) "==> Please rerun the $(MAKE) command.  <=="
2884	$(FALSE)
2885
2886MAKE_FRAG
2887
2888    return $m;
2889}
2890
2891
2892=item maybe_command
2893
2894Returns true, if the argument is likely to be a command.
2895
2896=cut
2897
2898sub maybe_command {
2899    my($self,$file) = @_;
2900    return $file if -x $file && ! -d $file;
2901    return;
2902}
2903
2904
2905=item needs_linking (o)
2906
2907Does this module need linking? Looks into subdirectory objects (see
2908also has_link_code())
2909
2910=cut
2911
2912sub needs_linking {
2913    my($self) = shift;
2914
2915    my $caller = (caller(0))[3];
2916    confess("needs_linking called too early") if
2917      $caller =~ /^ExtUtils::MakeMaker::/;
2918    return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
2919    if ($self->has_link_code or $self->{MAKEAPERL}){
2920	$self->{NEEDS_LINKING} = 1;
2921	return 1;
2922    }
2923    foreach my $child (keys %{$self->{CHILDREN}}) {
2924	if ($self->{CHILDREN}->{$child}->needs_linking) {
2925	    $self->{NEEDS_LINKING} = 1;
2926	    return 1;
2927	}
2928    }
2929    return $self->{NEEDS_LINKING} = 0;
2930}
2931
2932
2933=item parse_abstract
2934
2935parse a file and return what you think is the ABSTRACT
2936
2937=cut
2938
2939sub parse_abstract {
2940    my($self,$parsefile) = @_;
2941    my $result;
2942
2943    local $/ = "\n";
2944    open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
2945    binmode $fh;
2946    my $inpod = 0;
2947    my $pod_encoding;
2948    my $package = $self->{DISTNAME};
2949    $package =~ s/-/::/g;
2950    while (<$fh>) {
2951        $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2952        next if !$inpod;
2953        s#\r*\n\z##; # handle CRLF input
2954
2955        if ( /^=encoding\s*(.*)$/i ) {
2956            $pod_encoding = $1;
2957        }
2958
2959        if ( /^($package(?:\.pm)? \s+ -+ \s+)(.*)/x ) {
2960          $result = $2;
2961          next;
2962        }
2963        next unless $result;
2964
2965        if ( $result && ( /^\s*$/ || /^\=/ ) ) {
2966          last;
2967        }
2968        $result = join ' ', $result, $_;
2969    }
2970    close $fh;
2971
2972    if ( $pod_encoding and !( "$]" < 5.008 or !$Config{useperlio} ) ) {
2973        # Have to wrap in an eval{} for when running under PERL_CORE
2974        # Encode isn't available during build phase and parsing
2975        # ABSTRACT isn't important there
2976        eval {
2977          require Encode;
2978          $result = Encode::decode($pod_encoding, $result);
2979        }
2980    }
2981
2982    return $result;
2983}
2984
2985=item parse_version
2986
2987    my $version = MM->parse_version($file);
2988
2989Parse a $file and return what $VERSION is set to by the first assignment.
2990It will return the string "undef" if it can't figure out what $VERSION
2991is. $VERSION should be for all to see, so C<our $VERSION> or plain $VERSION
2992are okay, but C<my $VERSION> is not.
2993
2994C<package Foo VERSION> is also checked for.  The first version
2995declaration found is used, but this may change as it differs from how
2996Perl does it.
2997
2998parse_version() will try to C<use version> before checking for
2999C<$VERSION> so the following will work.
3000
3001    $VERSION = qv(1.2.3);
3002
3003=cut
3004
3005sub parse_version {
3006    my($self,$parsefile) = @_;
3007    my $result;
3008
3009    local $/ = "\n";
3010    local $_;
3011    open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
3012    my $inpod = 0;
3013    while (<$fh>) {
3014        $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
3015        next if $inpod || /^\s*#/;
3016        chop;
3017        next if /^\s*(if|unless|elsif)/;
3018        if ( m{^ \s* package \s+ \w[\w\:\']* \s+ (v?[0-9._]+) \s* (;|\{)  }x ) {
3019            no warnings;
3020            $result = $1;
3021        }
3022        elsif ( m{(?<!\\) ([\$*]) (([\w\:\']*) \bVERSION)\b .* (?<![<>=!])\=[^=]}x ) {
3023			$result = $self->get_version($parsefile, $1, $2);
3024        }
3025        else {
3026          next;
3027        }
3028        last if defined $result;
3029    }
3030    close $fh;
3031
3032    if ( defined $result && $result !~ /^v?[\d_\.]+$/ ) {
3033      require version;
3034      my $normal = eval { version->new( $result ) };
3035      $result = $normal if defined $normal;
3036    }
3037    if ( defined $result ) {
3038      $result = "undef" unless $result =~ m!^v?[\d_\.]+$!
3039                        or eval { version->parse( $result ) };
3040    }
3041    $result = "undef" unless defined $result;
3042    return $result;
3043}
3044
3045sub get_version {
3046    my ($self, $parsefile, $sigil, $name) = @_;
3047    my $line = $_; # from the while() loop in parse_version
3048    {
3049        package ExtUtils::MakeMaker::_version;
3050        undef *version; # in case of unexpected version() sub
3051        eval {
3052            require version;
3053            version::->import;
3054        };
3055        no strict;
3056        no warnings;
3057        local *{$name};
3058        $line = $1 if $line =~ m{^(.+)}s;
3059        eval($line); ## no critic
3060        return ${$name};
3061    }
3062}
3063
3064=item pasthru (o)
3065
3066Defines the string that is passed to recursive make calls in
3067subdirectories. The variables like C<PASTHRU_DEFINE> are used in each
3068level, and passed downwards on the command-line with e.g. the value of
3069that level's DEFINE. Example:
3070
3071    # Level 0 has DEFINE = -Dfunky
3072    # This code will define level 0's PASTHRU=PASTHRU_DEFINE="$(DEFINE)
3073    #     $(PASTHRU_DEFINE)"
3074    # Level 0's $(CCCMD) will include macros $(DEFINE) and $(PASTHRU_DEFINE)
3075    # So will level 1's, so when level 1 compiles, it will get right values
3076    # And so ad infinitum
3077
3078=cut
3079
3080sub pasthru {
3081    my($self) = shift;
3082    my(@m);
3083
3084    my(@pasthru);
3085    my($sep) = $Is{VMS} ? ',' : '';
3086    $sep .= "\\\n\t";
3087
3088    foreach my $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE
3089                     PREFIX INSTALL_BASE)
3090                 )
3091    {
3092        next unless defined $self->{$key};
3093	push @pasthru, "$key=\"\$($key)\"";
3094    }
3095
3096    foreach my $key (qw(DEFINE INC)) {
3097        # default to the make var
3098        my $val = qq{\$($key)};
3099        # expand within perl if given since need to use quote_literal
3100        # since INC might include space-protecting ""!
3101        chomp($val = $self->{$key}) if defined $self->{$key};
3102        $val .= " \$(PASTHRU_$key)";
3103        my $quoted = $self->quote_literal($val);
3104        push @pasthru, qq{PASTHRU_$key=$quoted};
3105    }
3106
3107    push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
3108    join "", @m;
3109}
3110
3111=item perl_script
3112
3113Takes one argument, a file name, and returns the file name, if the
3114argument is likely to be a perl script. On MM_Unix this is true for
3115any ordinary, readable file.
3116
3117=cut
3118
3119sub perl_script {
3120    my($self,$file) = @_;
3121    return $file if -r $file && -f _;
3122    return;
3123}
3124
3125=item perldepend (o)
3126
3127Defines the dependency from all *.h files that come with the perl
3128distribution.
3129
3130=cut
3131
3132sub perldepend {
3133    my($self) = shift;
3134    my(@m);
3135
3136    my $make_config = $self->cd('$(PERL_SRC)', '$(MAKE) lib/Config.pm');
3137
3138    push @m, sprintf <<'MAKE_FRAG', $make_config if $self->{PERL_SRC};
3139# Check for unpropogated config.sh changes. Should never happen.
3140# We do NOT just update config.h because that is not sufficient.
3141# An out of date config.h is not fatal but complains loudly!
3142$(PERL_INCDEP)/config.h: $(PERL_SRC)/config.sh
3143	-$(NOECHO) $(ECHO) "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; $(FALSE)
3144
3145$(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
3146	$(NOECHO) $(ECHO) "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
3147	%s
3148MAKE_FRAG
3149
3150    return join "", @m unless $self->needs_linking;
3151
3152    if ($self->{OBJECT}) {
3153        # Need to add an object file dependency on the perl headers.
3154        # this is very important for XS modules in perl.git development.
3155        push @m, $self->_perl_header_files_fragment("/"); # Directory separator between $(PERL_INC)/header.h
3156    }
3157
3158    push @m, join(" ", sort values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
3159
3160    return join "\n", @m;
3161}
3162
3163
3164=item pm_to_blib
3165
3166Defines target that copies all files in the hash PM to their
3167destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
3168
3169=cut
3170
3171sub pm_to_blib {
3172    my $self = shift;
3173    my($autodir) = $self->catdir('$(INST_LIB)','auto');
3174    my $r = q{
3175pm_to_blib : $(FIRST_MAKEFILE) $(TO_INST_PM)
3176};
3177
3178    # VMS will swallow '' and PM_FILTER is often empty.  So use q[]
3179    my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']);
3180pm_to_blib({\@ARGV}, '$autodir', q[\$(PM_FILTER)], '\$(PERM_DIR)')
3181CODE
3182
3183    my @cmds = $self->split_command($pm_to_blib,
3184                  map { ($self->quote_literal($_) => $self->quote_literal($self->{PM}->{$_})) } sort keys %{$self->{PM}});
3185
3186    $r .= join '', map { "\t\$(NOECHO) $_\n" } @cmds;
3187    $r .= qq{\t\$(NOECHO) \$(TOUCH) pm_to_blib\n};
3188
3189    return $r;
3190}
3191
3192# transform dot-separated version string into comma-separated quadruple
3193# examples:  '1.2.3.4.5' => '1,2,3,4'
3194#            '1.2.3'     => '1,2,3,0'
3195sub _ppd_version {
3196    my ($self, $string) = @_;
3197    return join ',', ((split /\./, $string), (0) x 4)[0..3];
3198}
3199
3200=item ppd
3201
3202Defines target that creates a PPD (Perl Package Description) file
3203for a binary distribution.
3204
3205=cut
3206
3207sub ppd {
3208    my($self) = @_;
3209
3210    my $abstract = $self->{ABSTRACT} || '';
3211    $abstract =~ s/\n/\\n/sg;
3212    $abstract =~ s/</&lt;/g;
3213    $abstract =~ s/>/&gt;/g;
3214
3215    my $author = join(', ',@{ ref $self->{AUTHOR} eq 'ARRAY' ? $self->{AUTHOR} : [ $self->{AUTHOR} || '']});
3216    $author =~ s/</&lt;/g;
3217    $author =~ s/>/&gt;/g;
3218
3219    my $ppd_file = "$self->{DISTNAME}.ppd";
3220
3221    my @ppd_chunks = qq(<SOFTPKG NAME="$self->{DISTNAME}" VERSION="$self->{VERSION}">\n);
3222
3223    push @ppd_chunks, sprintf <<'PPD_HTML', $abstract, $author;
3224    <ABSTRACT>%s</ABSTRACT>
3225    <AUTHOR>%s</AUTHOR>
3226PPD_HTML
3227
3228    push @ppd_chunks, "    <IMPLEMENTATION>\n";
3229    if ( $self->{MIN_PERL_VERSION} ) {
3230        my $min_perl_version = $self->_ppd_version($self->{MIN_PERL_VERSION});
3231        push @ppd_chunks, sprintf <<'PPD_PERLVERS', $min_perl_version;
3232        <PERLCORE VERSION="%s" />
3233PPD_PERLVERS
3234
3235    }
3236
3237    # Don't add "perl" to requires.  perl dependencies are
3238    # handles by ARCHITECTURE.
3239    my %prereqs = %{$self->{PREREQ_PM}};
3240    delete $prereqs{perl};
3241
3242    # Build up REQUIRE
3243    foreach my $prereq (sort keys %prereqs) {
3244        my $name = $prereq;
3245        $name .= '::' unless $name =~ /::/;
3246        my $version = $prereqs{$prereq};
3247
3248        my %attrs = ( NAME => $name );
3249        $attrs{VERSION} = $version if $version;
3250        my $attrs = join " ", map { qq[$_="$attrs{$_}"] } sort keys %attrs;
3251        push @ppd_chunks, qq(        <REQUIRE $attrs />\n);
3252    }
3253
3254    my $archname = $Config{archname};
3255
3256    # archname did not change from 5.6 to 5.8, but those versions may
3257    # not be not binary compatible so now we append the part of the
3258    # version that changes when binary compatibility may change
3259    if ("$]" >= 5.008) {
3260        $archname .= "-$Config{api_revision}.$Config{api_version}";
3261    }
3262    push @ppd_chunks, sprintf <<'PPD_OUT', $archname;
3263        <ARCHITECTURE NAME="%s" />
3264PPD_OUT
3265
3266    if ($self->{PPM_INSTALL_SCRIPT}) {
3267        if ($self->{PPM_INSTALL_EXEC}) {
3268            push @ppd_chunks, sprintf qq{        <INSTALL EXEC="%s">%s</INSTALL>\n},
3269                  $self->{PPM_INSTALL_EXEC}, $self->{PPM_INSTALL_SCRIPT};
3270        }
3271        else {
3272            push @ppd_chunks, sprintf qq{        <INSTALL>%s</INSTALL>\n},
3273                  $self->{PPM_INSTALL_SCRIPT};
3274        }
3275    }
3276
3277    if ($self->{PPM_UNINSTALL_SCRIPT}) {
3278        if ($self->{PPM_UNINSTALL_EXEC}) {
3279            push @ppd_chunks, sprintf qq{        <UNINSTALL EXEC="%s">%s</UNINSTALL>\n},
3280                  $self->{PPM_UNINSTALL_EXEC}, $self->{PPM_UNINSTALL_SCRIPT};
3281        }
3282        else {
3283            push @ppd_chunks, sprintf qq{        <UNINSTALL>%s</UNINSTALL>\n},
3284                  $self->{PPM_UNINSTALL_SCRIPT};
3285        }
3286    }
3287
3288    my ($bin_location) = $self->{BINARY_LOCATION} || '';
3289    $bin_location =~ s/\\/\\\\/g;
3290
3291    push @ppd_chunks, sprintf <<'PPD_XML', $bin_location;
3292        <CODEBASE HREF="%s" />
3293    </IMPLEMENTATION>
3294</SOFTPKG>
3295PPD_XML
3296
3297    my @ppd_cmds = $self->stashmeta(join('', @ppd_chunks), $ppd_file);
3298
3299    return sprintf <<'PPD_OUT', join "\n\t", @ppd_cmds;
3300# Creates a PPD (Perl Package Description) for a binary distribution.
3301ppd :
3302	%s
3303PPD_OUT
3304
3305}
3306
3307=item prefixify
3308
3309  $MM->prefixify($var, $prefix, $new_prefix, $default);
3310
3311Using either $MM->{uc $var} || $Config{lc $var}, it will attempt to
3312replace it's $prefix with a $new_prefix.
3313
3314Should the $prefix fail to match I<AND> a PREFIX was given as an
3315argument to WriteMakefile() it will set it to the $new_prefix +
3316$default.  This is for systems whose file layouts don't neatly fit into
3317our ideas of prefixes.
3318
3319This is for heuristics which attempt to create directory structures
3320that mirror those of the installed perl.
3321
3322For example:
3323
3324    $MM->prefixify('installman1dir', '/usr', '/home/foo', 'man/man1');
3325
3326this will attempt to remove '/usr' from the front of the
3327$MM->{INSTALLMAN1DIR} path (initializing it to $Config{installman1dir}
3328if necessary) and replace it with '/home/foo'.  If this fails it will
3329simply use '/home/foo/man/man1'.
3330
3331=cut
3332
3333sub prefixify {
3334    my($self,$var,$sprefix,$rprefix,$default) = @_;
3335
3336    my $path = $self->{uc $var} ||
3337               $Config_Override{lc $var} || $Config{lc $var} || '';
3338
3339    $rprefix .= '/' if $sprefix =~ m|/$|;
3340
3341    warn "  prefixify $var => $path\n" if $Verbose >= 2;
3342    warn "    from $sprefix to $rprefix\n" if $Verbose >= 2;
3343
3344    if( $self->{ARGS}{PREFIX} &&
3345        $path !~ s{^\Q$sprefix\E\b}{$rprefix}s )
3346    {
3347
3348        warn "    cannot prefix, using default.\n" if $Verbose >= 2;
3349        warn "    no default!\n" if !$default && $Verbose >= 2;
3350
3351        $path = $self->catdir($rprefix, $default) if $default;
3352    }
3353
3354    print "    now $path\n" if $Verbose >= 2;
3355    return $self->{uc $var} = $path;
3356}
3357
3358
3359=item processPL (o)
3360
3361Defines targets to run *.PL files.
3362
3363=cut
3364
3365sub processPL {
3366    my $self = shift;
3367    my $pl_files = $self->{PL_FILES};
3368
3369    return "" unless $pl_files;
3370
3371    my $m = '';
3372    foreach my $plfile (sort keys %$pl_files) {
3373        my $targets = $pl_files->{$plfile};
3374        my $list =
3375            ref($targets) eq 'HASH'  ? [ sort keys %$targets ] :
3376            ref($targets) eq 'ARRAY' ? $pl_files->{$plfile}   :
3377            [$pl_files->{$plfile}];
3378
3379        foreach my $target (@$list) {
3380            if( $Is{VMS} ) {
3381                $plfile = vmsify($self->eliminate_macros($plfile));
3382                $target = vmsify($self->eliminate_macros($target));
3383            }
3384
3385            # Normally a .PL file runs AFTER pm_to_blib so it can have
3386            # blib in its @INC and load the just built modules.  BUT if
3387            # the generated module is something in $(TO_INST_PM) which
3388            # pm_to_blib depends on then it can't depend on pm_to_blib
3389            # else we have a dependency loop.
3390            my $pm_dep;
3391            my $perlrun;
3392            if( defined $self->{PM}{$target} ) {
3393                $pm_dep  = '';
3394                $perlrun = 'PERLRUN';
3395            }
3396            else {
3397                $pm_dep  = 'pm_to_blib';
3398                $perlrun = 'PERLRUNINST';
3399            }
3400
3401            my $extra_inputs = '';
3402            if( ref($targets) eq 'HASH' ) {
3403                my $inputs = ref($targets->{$target})
3404                    ? $targets->{$target}
3405                    : [$targets->{$target}];
3406
3407                for my $input (@$inputs) {
3408                    if( $Is{VMS} ) {
3409                        $input = vmsify($self->eliminate_macros($input));
3410                    }
3411                    $extra_inputs .= ' '.$input;
3412                }
3413            }
3414
3415            $m .= <<MAKE_FRAG;
3416
3417pure_all :: $target
3418	\$(NOECHO) \$(NOOP)
3419
3420$target :: $plfile $pm_dep $extra_inputs
3421	\$($perlrun) $plfile $target $extra_inputs
3422MAKE_FRAG
3423
3424        }
3425    }
3426
3427    return $m;
3428}
3429
3430=item specify_shell
3431
3432Specify SHELL if needed - not done on Unix.
3433
3434=cut
3435
3436sub specify_shell {
3437  return '';
3438}
3439
3440=item quote_paren
3441
3442Backslashes parentheses C<()> in command line arguments.
3443Doesn't handle recursive Makefile C<$(...)> constructs,
3444but handles simple ones.
3445
3446=cut
3447
3448sub quote_paren {
3449    my $arg = shift;
3450    $arg =~ s{\$\((.+?)\)}{\$\\\\($1\\\\)}g;	# protect $(...)
3451    $arg =~ s{(?<!\\)([()])}{\\$1}g;		# quote unprotected
3452    $arg =~ s{\$\\\\\((.+?)\\\\\)}{\$($1)}g;	# unprotect $(...)
3453    return $arg;
3454}
3455
3456=item replace_manpage_separator
3457
3458  my $man_name = $MM->replace_manpage_separator($file_path);
3459
3460Takes the name of a package, which may be a nested package, in the
3461form 'Foo/Bar.pm' and replaces the slash with C<::> or something else
3462safe for a man page file name.  Returns the replacement.
3463
3464=cut
3465
3466sub replace_manpage_separator {
3467    my($self,$man) = @_;
3468
3469    $man =~ s,/+,::,g;
3470    return $man;
3471}
3472
3473
3474=item cd
3475
3476=cut
3477
3478sub cd {
3479    my($self, $dir, @cmds) = @_;
3480
3481    # No leading tab and no trailing newline makes for easier embedding
3482    my $make_frag = join "\n\t", map { "cd $dir && $_" } @cmds;
3483
3484    return $make_frag;
3485}
3486
3487=item oneliner
3488
3489=cut
3490
3491sub oneliner {
3492    my($self, $cmd, $switches) = @_;
3493    $switches = [] unless defined $switches;
3494
3495    # Strip leading and trailing newlines
3496    $cmd =~ s{^\n+}{};
3497    $cmd =~ s{\n+$}{};
3498
3499    my @cmds = split /\n/, $cmd;
3500    $cmd = join " \n\t  -e ", map $self->quote_literal($_), @cmds;
3501    $cmd = $self->escape_newlines($cmd);
3502
3503    $switches = join ' ', @$switches;
3504
3505    return qq{\$(ABSPERLRUN) $switches -e $cmd --};
3506}
3507
3508
3509=item quote_literal
3510
3511Quotes macro literal value suitable for being used on a command line so
3512that when expanded by make, will be received by command as given to
3513this method:
3514
3515  my $quoted = $mm->quote_literal(q{it isn't});
3516  # returns:
3517  #   'it isn'\''t'
3518  print MAKEFILE "target:\n\techo $quoted\n";
3519  # when run "make target", will output:
3520  #   it isn't
3521
3522=cut
3523
3524sub quote_literal {
3525    my($self, $text, $opts) = @_;
3526    $opts->{allow_variables} = 1 unless defined $opts->{allow_variables};
3527
3528    # Quote single quotes
3529    $text =~ s{'}{'\\''}g;
3530
3531    $text = $opts->{allow_variables}
3532      ? $self->escape_dollarsigns($text) : $self->escape_all_dollarsigns($text);
3533
3534    return "'$text'";
3535}
3536
3537
3538=item escape_newlines
3539
3540=cut
3541
3542sub escape_newlines {
3543    my($self, $text) = @_;
3544
3545    $text =~ s{\n}{\\\n}g;
3546
3547    return $text;
3548}
3549
3550
3551=item max_exec_len
3552
3553Using L<POSIX>::ARG_MAX.  Otherwise falling back to 4096.
3554
3555=cut
3556
3557sub max_exec_len {
3558    my $self = shift;
3559
3560    if (!defined $self->{_MAX_EXEC_LEN}) {
3561        if (my $arg_max = eval { require POSIX;  &POSIX::ARG_MAX }) {
3562            $self->{_MAX_EXEC_LEN} = $arg_max;
3563        }
3564        else {      # POSIX minimum exec size
3565            $self->{_MAX_EXEC_LEN} = 4096;
3566        }
3567    }
3568
3569    return $self->{_MAX_EXEC_LEN};
3570}
3571
3572
3573=item static (o)
3574
3575Defines the static target.
3576
3577=cut
3578
3579sub static {
3580# --- Static Loading Sections ---
3581
3582    my($self) = shift;
3583    '
3584## $(INST_PM) has been moved to the all: target.
3585## It remains here for awhile to allow for old usage: "make static"
3586static :: $(FIRST_MAKEFILE) $(INST_STATIC)
3587	$(NOECHO) $(NOOP)
3588';
3589}
3590
3591sub static_lib {
3592    my($self) = @_;
3593    return '' unless $self->has_link_code;
3594    my(@m);
3595    my @libs;
3596    if ($self->{XSMULTI}) {
3597	for my $ext ($self->_xs_list_basenames) {
3598	    my ($v, $d, $f) = File::Spec->splitpath($ext);
3599	    my @d = File::Spec->splitdir($d);
3600	    shift @d if $d[0] eq 'lib';
3601	    my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
3602	    my $instfile = $self->catfile($instdir, "$f\$(LIB_EXT)");
3603	    my $objfile = "$ext\$(OBJ_EXT)";
3604	    push @libs, [ $objfile, $instfile, $instdir ];
3605	}
3606    } else {
3607	@libs = ([ qw($(OBJECT) $(INST_STATIC) $(INST_ARCHAUTODIR)) ]);
3608    }
3609    push @m, map { $self->xs_make_static_lib(@$_); } @libs;
3610    join "\n", @m;
3611}
3612
3613=item xs_make_static_lib
3614
3615Defines the recipes for the C<static_lib> section.
3616
3617=cut
3618
3619sub xs_make_static_lib {
3620    my ($self, $from, $to, $todir) = @_;
3621    my @m = sprintf '%s: %s $(MYEXTLIB) %s$(DFSEP).exists'."\n", $to, $from, $todir;
3622    push @m, "\t\$(RM_F) \"\$\@\"\n";
3623    push @m, $self->static_lib_fixtures;
3624    push @m, $self->static_lib_pure_cmd($from);
3625    push @m, "\t\$(CHMOD) \$(PERM_RWX) \$\@\n";
3626    push @m, $self->static_lib_closures($todir);
3627    join '', @m;
3628}
3629
3630=item static_lib_closures
3631
3632Records C<$(EXTRALIBS)> in F<extralibs.ld> and F<$(PERL_SRC)/ext.libs>.
3633
3634=cut
3635
3636sub static_lib_closures {
3637    my ($self, $todir) = @_;
3638    my @m = sprintf <<'MAKE_FRAG', $todir;
3639	$(NOECHO) $(ECHO) "$(EXTRALIBS)" > %s$(DFSEP)extralibs.ld
3640MAKE_FRAG
3641    # Old mechanism - still available:
3642    push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
3643	$(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)$(DFSEP)ext.libs
3644MAKE_FRAG
3645    @m;
3646}
3647
3648=item static_lib_fixtures
3649
3650Handles copying C<$(MYEXTLIB)> as starter for final static library that
3651then gets added to.
3652
3653=cut
3654
3655sub static_lib_fixtures {
3656    my ($self) = @_;
3657    # If this extension has its own library (eg SDBM_File)
3658    # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
3659    return unless $self->{MYEXTLIB};
3660    "\t\$(CP) \$(MYEXTLIB) \"\$\@\"\n";
3661}
3662
3663=item static_lib_pure_cmd
3664
3665Defines how to run the archive utility.
3666
3667=cut
3668
3669sub static_lib_pure_cmd {
3670    my ($self, $from) = @_;
3671    my $ar;
3672    if (exists $self->{FULL_AR} && -x $self->{FULL_AR}) {
3673        # Prefer the absolute pathed ar if available so that PATH
3674        # doesn't confuse us.  Perl itself is built with the full_ar.
3675        $ar = 'FULL_AR';
3676    } else {
3677        $ar = 'AR';
3678    }
3679    sprintf <<'MAKE_FRAG', $ar, $from;
3680	$(%s) $(AR_STATIC_ARGS) "$@" %s
3681	$(RANLIB) "$@"
3682MAKE_FRAG
3683}
3684
3685=item staticmake (o)
3686
3687Calls makeaperl.
3688
3689=cut
3690
3691sub staticmake {
3692    my($self, %attribs) = @_;
3693    my(@static);
3694
3695    my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
3696
3697    # And as it's not yet built, we add the current extension
3698    # but only if it has some C code (or XS code, which implies C code)
3699    if (@{$self->{C}}) {
3700	@static = $self->catfile($self->{INST_ARCHLIB},
3701				 "auto",
3702				 $self->{FULLEXT},
3703				 "$self->{BASEEXT}$self->{LIB_EXT}"
3704				);
3705    }
3706
3707    # Either we determine now, which libraries we will produce in the
3708    # subdirectories or we do it at runtime of the make.
3709
3710    # We could ask all subdir objects, but I cannot imagine, why it
3711    # would be necessary.
3712
3713    # Instead we determine all libraries for the new perl at
3714    # runtime.
3715    my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
3716
3717    $self->makeaperl(MAKE	=> $self->{MAKEFILE},
3718		     DIRS	=> \@searchdirs,
3719		     STAT	=> \@static,
3720		     INCL	=> \@perlinc,
3721		     TARGET	=> $self->{MAP_TARGET},
3722		     TMP	=> "",
3723		     LIBPERL	=> $self->{LIBPERL_A}
3724		    );
3725}
3726
3727=item subdir_x (o)
3728
3729Helper subroutine for subdirs
3730
3731=cut
3732
3733sub subdir_x {
3734    my($self, $subdir) = @_;
3735
3736    my $subdir_cmd = $self->cd($subdir,
3737      '$(MAKE) $(USEMAKEFILE) $(FIRST_MAKEFILE) all $(PASTHRU)'
3738    );
3739    return sprintf <<'EOT', $subdir_cmd;
3740
3741subdirs ::
3742	$(NOECHO) %s
3743EOT
3744
3745}
3746
3747=item subdirs (o)
3748
3749Defines targets to process subdirectories.
3750
3751=cut
3752
3753sub subdirs {
3754# --- Sub-directory Sections ---
3755    my($self) = shift;
3756    my(@m);
3757    # This method provides a mechanism to automatically deal with
3758    # subdirectories containing further Makefile.PL scripts.
3759    # It calls the subdir_x() method for each subdirectory.
3760    foreach my $dir (@{$self->{DIR}}){
3761	push @m, $self->subdir_x($dir);
3762####	print "Including $dir subdirectory\n";
3763    }
3764    if (@m){
3765	unshift @m, <<'EOF';
3766
3767# The default clean, realclean and test targets in this Makefile
3768# have automatically been given entries for each subdir.
3769
3770EOF
3771    } else {
3772	push(@m, "\n# none")
3773    }
3774    join('',@m);
3775}
3776
3777=item test (o)
3778
3779Defines the test targets.
3780
3781=cut
3782
3783sub test {
3784    my($self, %attribs) = @_;
3785    my $tests = $attribs{TESTS} || '';
3786    if (!$tests && -d 't' && defined $attribs{RECURSIVE_TEST_FILES}) {
3787        $tests = $self->find_tests_recursive;
3788    }
3789    elsif (!$tests && -d 't') {
3790        $tests = $self->find_tests;
3791    }
3792    # have to do this because nmake is broken
3793    $tests =~ s!/!\\!g if $self->is_make_type('nmake');
3794    # note: 'test.pl' name is also hardcoded in init_dirscan()
3795    my @m;
3796    my $default_testtype = $Config{usedl} ? 'dynamic' : 'static';
3797    push @m, <<EOF;
3798TEST_VERBOSE=0
3799TEST_TYPE=test_\$(LINKTYPE)
3800TEST_FILE = test.pl
3801TEST_FILES = $tests
3802TESTDB_SW = -d
3803
3804testdb :: testdb_\$(LINKTYPE)
3805	\$(NOECHO) \$(NOOP)
3806
3807test :: \$(TEST_TYPE)
3808	\$(NOECHO) \$(NOOP)
3809
3810# Occasionally we may face this degenerate target:
3811test_ : test_$default_testtype
3812	\$(NOECHO) \$(NOOP)
3813
3814EOF
3815
3816    for my $linktype (qw(dynamic static)) {
3817        my $directdeps = join ' ', grep !$self->{SKIPHASH}{$_}, $linktype, "pure_all"; # no depend on a linktype if SKIPped
3818        push @m, "subdirs-test_$linktype :: $directdeps\n";
3819        foreach my $dir (@{ $self->{DIR} }) {
3820            my $test = $self->cd($dir, "\$(MAKE) test_$linktype \$(PASTHRU)");
3821            push @m, "\t\$(NOECHO) $test\n";
3822        }
3823        push @m, "\n";
3824        if ($tests or -f "test.pl") {
3825            for my $testspec ([ '', '' ], [ 'db', ' $(TESTDB_SW)' ]) {
3826                my ($db, $switch) = @$testspec;
3827                my ($command, $deps);
3828                # if testdb, build all but don't test all
3829                $deps = $db eq 'db' ? $directdeps : "subdirs-test_$linktype";
3830                if ($linktype eq 'static' and $self->needs_linking) {
3831                    my $target = File::Spec->rel2abs('$(MAP_TARGET)');
3832                    $command = qq{"$target" \$(MAP_PERLINC)};
3833                    $deps .= ' $(MAP_TARGET)';
3834                } else {
3835                    $command = '$(FULLPERLRUN)' . $switch;
3836                }
3837                push @m, "test${db}_$linktype :: $deps\n";
3838                if ($db eq 'db') {
3839                    push @m, $self->test_via_script($command, '$(TEST_FILE)')
3840                } else {
3841                    push @m, $self->test_via_script($command, '$(TEST_FILE)')
3842                        if -f "test.pl";
3843                    push @m, $self->test_via_harness($command, '$(TEST_FILES)')
3844                        if $tests;
3845                }
3846                push @m, "\n";
3847            }
3848        } else {
3849            push @m, _sprintf562 <<'EOF', $linktype;
3850testdb_%1$s test_%1$s :: subdirs-test_%1$s
3851	$(NOECHO) $(ECHO) 'No tests defined for $(NAME) extension.'
3852
3853EOF
3854        }
3855    }
3856
3857    join "", @m;
3858}
3859
3860=item test_via_harness (override)
3861
3862For some reason which I forget, Unix machines like to have
3863PERL_DL_NONLAZY set for tests.
3864
3865=cut
3866
3867sub test_via_harness {
3868    my($self, $perl, $tests) = @_;
3869    return $self->SUPER::test_via_harness("PERL_DL_NONLAZY=1 $perl", $tests);
3870}
3871
3872=item test_via_script (override)
3873
3874Again, the PERL_DL_NONLAZY thing.
3875
3876=cut
3877
3878sub test_via_script {
3879    my($self, $perl, $script) = @_;
3880    return $self->SUPER::test_via_script("PERL_DL_NONLAZY=1 $perl", $script);
3881}
3882
3883
3884=item tool_xsubpp (o)
3885
3886Determines typemaps, xsubpp version, prototype behaviour.
3887
3888=cut
3889
3890sub tool_xsubpp {
3891    my($self) = shift;
3892    return "" unless $self->needs_linking;
3893
3894    my $xsdir;
3895    my @xsubpp_dirs = @INC;
3896
3897    # Make sure we pick up the new xsubpp if we're building perl.
3898    unshift @xsubpp_dirs, $self->{PERL_LIB} if $self->{PERL_CORE};
3899
3900    my $foundxsubpp = 0;
3901    foreach my $dir (@xsubpp_dirs) {
3902        $xsdir = $self->catdir($dir, 'ExtUtils');
3903        if( -r $self->catfile($xsdir, "xsubpp") ) {
3904            $foundxsubpp = 1;
3905            last;
3906        }
3907    }
3908    die "ExtUtils::MM_Unix::tool_xsubpp : Can't find xsubpp" if !$foundxsubpp;
3909
3910    my $tmdir   = $self->catdir($self->{PERL_LIB},"ExtUtils");
3911    my(@tmdeps) = $self->catfile($tmdir,'typemap');
3912    if( $self->{TYPEMAPS} ){
3913        foreach my $typemap (@{$self->{TYPEMAPS}}){
3914            if( ! -f  $typemap ) {
3915                warn "Typemap $typemap not found.\n";
3916            }
3917            else {
3918                $typemap = vmsify($typemap) if $Is{VMS};
3919                push(@tmdeps, $typemap);
3920            }
3921        }
3922    }
3923    push(@tmdeps, "typemap") if -f "typemap";
3924    # absolutised because with deep-located typemaps, eg "lib/XS/typemap",
3925    # if xsubpp is called from top level with
3926    #     $(XSUBPP) ... -typemap "lib/XS/typemap" "lib/XS/Test.xs"
3927    # it says:
3928    #     Can't find lib/XS/type map in (fulldir)/lib/XS
3929    # because ExtUtils::ParseXS::process_file chdir's to .xs file's
3930    # location. This is the only way to get all specified typemaps used,
3931    # wherever located.
3932    my @tmargs = map { '-typemap '.$self->quote_literal(File::Spec->rel2abs($_)) } @tmdeps;
3933    $_ = $self->quote_dep($_) for @tmdeps;
3934    if( exists $self->{XSOPT} ){
3935        unshift( @tmargs, $self->{XSOPT} );
3936    }
3937
3938    if ($Is{VMS}                          &&
3939        $Config{'ldflags'}               &&
3940        $Config{'ldflags'} =~ m!/Debug!i &&
3941        (!exists($self->{XSOPT}) || $self->{XSOPT} !~ /linenumbers/)
3942       )
3943    {
3944        unshift(@tmargs,'-nolinenumbers');
3945    }
3946
3947
3948    $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
3949    my $xsdirdep = $self->quote_dep($xsdir);
3950    # -dep for use when dependency not command
3951
3952    return qq{
3953XSUBPPDIR = $xsdir
3954XSUBPP = "\$(XSUBPPDIR)\$(DFSEP)xsubpp"
3955XSUBPPRUN = \$(PERLRUN) \$(XSUBPP)
3956XSPROTOARG = $self->{XSPROTOARG}
3957XSUBPPDEPS = @tmdeps $xsdirdep\$(DFSEP)xsubpp
3958XSUBPPARGS = @tmargs
3959XSUBPP_EXTRA_ARGS =
3960};
3961}
3962
3963
3964=item all_target
3965
3966Build man pages, too
3967
3968=cut
3969
3970sub all_target {
3971    my $self = shift;
3972
3973    return <<'MAKE_EXT';
3974all :: pure_all manifypods
3975	$(NOECHO) $(NOOP)
3976MAKE_EXT
3977}
3978
3979=item top_targets (o)
3980
3981Defines the targets all, subdirs, config, and O_FILES
3982
3983=cut
3984
3985sub top_targets {
3986# --- Target Sections ---
3987
3988    my($self) = shift;
3989    my(@m);
3990
3991    push @m, $self->all_target, "\n" unless $self->{SKIPHASH}{'all'};
3992
3993    push @m, sprintf <<'EOF';
3994pure_all :: config pm_to_blib subdirs linkext
3995	$(NOECHO) $(NOOP)
3996
3997subdirs :: $(MYEXTLIB)
3998	$(NOECHO) $(NOOP)
3999
4000config :: $(FIRST_MAKEFILE) blibdirs
4001	$(NOECHO) $(NOOP)
4002EOF
4003
4004    push @m, '
4005$(O_FILES) : $(H_FILES)
4006' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
4007
4008    push @m, q{
4009help :
4010	perldoc ExtUtils::MakeMaker
4011};
4012
4013    join('',@m);
4014}
4015
4016=item writedoc
4017
4018Obsolete, deprecated method. Not used since Version 5.21.
4019
4020=cut
4021
4022sub writedoc {
4023# --- perllocal.pod section ---
4024    my($self,$what,$name,@attribs)=@_;
4025    my $time = gmtime($ENV{SOURCE_DATE_EPOCH} || time);
4026    print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
4027    print join "\n\n=item *\n\n", map("C<$_>",@attribs);
4028    print "\n\n=back\n\n";
4029}
4030
4031=item xs_c (o)
4032
4033Defines the suffix rules to compile XS files to C.
4034
4035=cut
4036
4037sub xs_c {
4038    my($self) = shift;
4039    return '' unless $self->needs_linking();
4040    '
4041.xs.c:
4042	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc
4043	$(MV) $*.xsc $*.c
4044';
4045}
4046
4047=item xs_cpp (o)
4048
4049Defines the suffix rules to compile XS files to C++.
4050
4051=cut
4052
4053sub xs_cpp {
4054    my($self) = shift;
4055    return '' unless $self->needs_linking();
4056    '
4057.xs.cpp:
4058	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
4059	$(MV) $*.xsc $*.cpp
4060';
4061}
4062
4063=item xs_o (o)
4064
4065Defines suffix rules to go from XS to object files directly. This was
4066originally only intended for broken make implementations, but is now
4067necessary for per-XS file under C<XSMULTI>, since each XS file might
4068have an individual C<$(VERSION)>.
4069
4070=cut
4071
4072sub xs_o {
4073    my ($self) = @_;
4074    return '' unless $self->needs_linking();
4075    my $m_o = $self->{XSMULTI} ? $self->xs_obj_opt('$*$(OBJ_EXT)') : '';
4076    my $dbgout = $self->dbgoutflag;
4077    $dbgout = $dbgout ? "$dbgout " : '';
4078    my $frag = '';
4079    # dmake makes noise about ambiguous rule
4080    $frag .= sprintf <<'EOF', $dbgout, $m_o unless $self->is_make_type('dmake');
4081.xs$(OBJ_EXT) :
4082	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
4083	$(MV) $*.xsc $*.c
4084	$(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) %s$*.c %s
4085EOF
4086    if ($self->{XSMULTI}) {
4087	for my $ext ($self->_xs_list_basenames) {
4088	    my $pmfile = "$ext.pm";
4089	    croak "$ext.xs has no matching $pmfile: $!" unless -f $pmfile;
4090	    my $version = $self->parse_version($pmfile);
4091	    my $cccmd = $self->{CONST_CCCMD};
4092	    $cccmd =~ s/^\s*CCCMD\s*=\s*//;
4093	    $cccmd =~ s/\$\(DEFINE_VERSION\)/-DVERSION=\\"$version\\"/;
4094	    $cccmd =~ s/\$\(XS_DEFINE_VERSION\)/-DXS_VERSION=\\"$version\\"/;
4095            $self->_xsbuild_replace_macro($cccmd, 'xs', $ext, 'INC');
4096            my $define = '$(DEFINE)';
4097            $self->_xsbuild_replace_macro($define, 'xs', $ext, 'DEFINE');
4098            #                             1     2       3     4        5
4099            $frag .= _sprintf562 <<'EOF', $ext, $cccmd, $m_o, $define, $dbgout;
4100
4101%1$s$(OBJ_EXT): %1$s.xs
4102	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
4103	$(MV) $*.xsc $*.c
4104	%2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) %4$s %5$s$*.c %3$s
4105EOF
4106	}
4107    }
4108    $frag =~ s/"-I(\$\(PERL_INC\))"/-iwithsysroot "$1"/sg if $Is{ApplCor};
4109    $frag;
4110}
4111
4112# param gets modified
4113sub _xsbuild_replace_macro {
4114    my ($self, undef, $xstype, $ext, $varname) = @_;
4115    my $value = $self->_xsbuild_value($xstype, $ext, $varname);
4116    return unless defined $value;
4117    $_[1] =~ s/\$\($varname\)/$value/;
4118}
4119
4120sub _xsbuild_value {
4121    my ($self, $xstype, $ext, $varname) = @_;
4122    return $self->{XSBUILD}{$xstype}{$ext}{$varname}
4123        if $self->{XSBUILD}{$xstype}{$ext}{$varname};
4124    return $self->{XSBUILD}{$xstype}{all}{$varname}
4125        if $self->{XSBUILD}{$xstype}{all}{$varname};
4126    ();
4127}
4128
41291;
4130
4131=back
4132
4133=head1 SEE ALSO
4134
4135L<ExtUtils::MakeMaker>
4136
4137=cut
4138
4139__END__
4140