File Coverage

lib/ExtUtils/MM_Unix.pm
Criterion Covered Total %
statement 935 1456 64.2
branch 336 772 43.5
condition 184 436 42.2
subroutine 105 126 83.3
pod 96 99 96.9
total 1656 2889 57.3


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