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