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