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