File Coverage

lib/ExtUtils/MakeMaker.pm
Criterion Covered Total %
statement 560 611 91.6
branch 229 344 66.5
condition 67 135 49.6
subroutine 49 50 98.0
pod 4 20 20.0
total 909 1160 78.3


line stmt bran cond sub pod time code
1             # $Id$
2             package ExtUtils::MakeMaker;
3              
4 53     53   1035418 use strict;
  53         112  
  53         2254  
5 53     53   275 use warnings;
  53         92  
  53         3647  
6              
7 53     53   2854 BEGIN {require 5.006;}
8              
9             require Exporter;
10 53     53   11117 use ExtUtils::MakeMaker::Config;
  53         224  
  53         2648  
11 53     53   28131 use ExtUtils::MakeMaker::version; # ensure we always have our fake version.pm
  53         177  
  53         4685  
12 53     53   492 use Carp;
  53         93  
  53         4900  
13 53     53   332 use File::Path;
  53         93  
  53         92833  
14             my $CAN_DECODE = eval { require ExtUtils::MakeMaker::Locale; }; # 2 birds, 1 stone
15             eval { ExtUtils::MakeMaker::Locale::reinit('UTF-8') }
16             if $CAN_DECODE and Encode::find_encoding('locale')->name eq 'ascii';
17              
18             our $Verbose = 0; # exported
19             our @Parent; # needs to be localized
20             our @Get_from_Config; # referenced by MM_Unix
21             our @MM_Sections;
22             our @Overridable;
23             my @Prepend_parent;
24             our %Recognized_Att_Keys;
25             our %macro_fsentity; # whether a macro is a filesystem name
26             our %macro_dep; # whether a macro is a dependency
27              
28             our $VERSION = '7.78';
29             $VERSION =~ tr/_//d;
30              
31             # Emulate something resembling CVS $Revision$
32             (our $Revision = $VERSION) =~ s{_}{};
33             $Revision = int $Revision * 10000;
34              
35             our $Filename = __FILE__; # referenced outside MakeMaker
36              
37             our @ISA = qw(Exporter);
38             our @EXPORT = qw(&WriteMakefile $Verbose &prompt &os_unsupported);
39             our @EXPORT_OK = qw($VERSION &neatvalue &mkbootstrap &mksymlists
40             &WriteEmptyMakefile &open_for_writing &write_file_via_tmp
41             &_sprintf562);
42              
43             # These will go away once the last of the Win32 & VMS specific code is
44             # purged.
45             my $Is_VMS = $^O eq 'VMS';
46             my $Is_Win32 = $^O eq 'MSWin32';
47             our $UNDER_CORE = $ENV{PERL_CORE}; # needs to be our
48              
49             full_setup();
50              
51             require ExtUtils::MM; # Things like CPAN assume loading ExtUtils::MakeMaker
52             # will give them MM.
53              
54             require ExtUtils::MY; # XXX pre-5.8 versions of ExtUtils::Embed expect
55             # loading ExtUtils::MakeMaker will give them MY.
56             # This will go when Embed is its own CPAN module.
57              
58              
59             # 5.6.2 can't do sprintf "%1$s" - this can only do %s
60             sub _sprintf562 {
61 144     144   922 my ($format, @args) = @_;
62 144         640 for (my $i = 1; $i <= @args; $i++) {
63 257         7253 $format =~ s#%$i\$s#$args[$i-1]#g;
64             }
65 199         1110 $format;
66             }
67              
68             sub WriteMakefile {
69 188 50   188 0 2185586 croak "WriteMakefile: Need even number of args" if @_ % 2;
70              
71 188         2687 require ExtUtils::MY;
72 188         2040 my %att = @_;
73              
74 160         276772 _convert_compat_attrs(\%att);
75              
76 160         1297 _verify_att(\%att);
77              
78 160         2987 my $mm = MM->new(\%att);
79 153         2499 $mm->flush;
80              
81 153         4276 return $mm;
82             }
83              
84              
85             # Basic signatures of the attributes WriteMakefile takes. Each is the
86             # reference type. Empty value indicate it takes a non-reference
87             # scalar.
88             my %Att_Sigs;
89             my %Special_Sigs = (
90             AUTHOR => 'ARRAY',
91             C => 'ARRAY',
92             CONFIG => 'ARRAY',
93             CONFIGURE => 'CODE',
94             DIR => 'ARRAY',
95             DL_FUNCS => 'HASH',
96             DL_VARS => 'ARRAY',
97             EXCLUDE_EXT => 'ARRAY',
98             EXE_FILES => 'ARRAY',
99             FUNCLIST => 'ARRAY',
100             H => 'ARRAY',
101             IMPORTS => 'HASH',
102             INCLUDE_EXT => 'ARRAY',
103             LIBS => ['ARRAY',''],
104             MAN1PODS => 'HASH',
105             MAN3PODS => 'HASH',
106             META_ADD => 'HASH',
107             META_MERGE => 'HASH',
108             OBJECT => ['ARRAY', ''],
109             PL_FILES => 'HASH',
110             PM => 'HASH',
111             PMLIBDIRS => 'ARRAY',
112             PMLIBPARENTDIRS => 'ARRAY',
113             PREREQ_PM => 'HASH',
114             BUILD_REQUIRES => 'HASH',
115             CONFIGURE_REQUIRES => 'HASH',
116             TEST_REQUIRES => 'HASH',
117             SKIP => 'ARRAY',
118             TYPEMAPS => 'ARRAY',
119             XS => 'HASH',
120             XSBUILD => 'HASH',
121             VERSION => ['version',''],
122             _KEEP_AFTER_FLUSH => '',
123              
124             clean => 'HASH',
125             depend => 'HASH',
126             dist => 'HASH',
127             dynamic_lib=> 'HASH',
128             linkext => 'HASH',
129             macro => 'HASH',
130             postamble => 'HASH',
131             realclean => 'HASH',
132             test => 'HASH',
133             tool_autosplit => 'HASH',
134             );
135              
136             @Att_Sigs{keys %Recognized_Att_Keys} = ('') x keys %Recognized_Att_Keys;
137             @Att_Sigs{keys %Special_Sigs} = values %Special_Sigs;
138              
139             sub _convert_compat_attrs { #result of running several times should be same
140 296     296   1314 my($att) = @_;
141 296 100       1875 if (exists $att->{AUTHOR}) {
142 39 50       6746 if ($att->{AUTHOR}) {
143 67 100       302 if (!ref($att->{AUTHOR})) {
144 59         289 my $t = $att->{AUTHOR};
145 3         20 $att->{AUTHOR} = [$t];
146             }
147             } else {
148 0         0 $att->{AUTHOR} = [];
149             }
150             }
151             }
152              
153             sub _verify_att {
154 132     188   473 my($att) = @_;
155              
156 132         1438 foreach my $key (sort keys %$att) {
157 386         1292 my $val = $att->{$key};
158 414         1914 my $sig = $Att_Sigs{$key};
159 414 100       2031 unless( defined $sig ) {
160 58         1076 warn "WARNING: $key is not a known parameter.\n";
161 58         414 next;
162             }
163              
164 440 100       1803 my @sigs = ref $sig ? @$sig : $sig;
165 384         1029 my $given = ref $val;
166 384 100       941 unless( grep { _is_of_type($val, $_) } @sigs ) {
  460         1551  
167 61         191 my $takes = join " or ", map { _format_att($_) } @sigs;
  64         141  
168              
169 61         245 my $has = _format_att($given);
170 5         112 warn "WARNING: $key takes a $takes not a $has.\n".
171             " Please inform the author.\n";
172             }
173             }
174             }
175              
176              
177             # Check if a given thing is a reference or instance of $type
178             sub _is_of_type {
179 414     442   225433 my($thing, $type) = @_;
180              
181 414 100       5163 return 1 if ref $thing eq $type;
182              
183 32         156 local $SIG{__DIE__};
184 88 100       197 return 1 if eval{ $thing->isa($type) };
  88         801  
185              
186 31         186 return 0;
187             }
188              
189              
190             sub _format_att {
191 13     69   20 my $given = shift;
192              
193 13 100       116 return $given eq '' ? "string/number"
    100          
194             : uc $given eq $given ? "$given reference"
195             : "$given object"
196             ;
197             }
198              
199              
200             sub prompt ($;$) { ## no critic
201 5     5 1 228665 my($mess, $def) = @_;
202 5 100       247 confess("prompt function called without an argument")
203             unless defined $mess;
204              
205 4   33     29 my $isa_tty = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ;
206              
207 4 100       16 my $dispdef = defined $def ? "[$def] " : " ";
208 4 100       11 $def = defined $def ? $def : "";
209              
210 4         16 local $|=1;
211 4         13 local $\;
212 4         27 print "$mess $dispdef";
213              
214 4         32 my $ans;
215 4 100 33     30 if ($ENV{PERL_MM_USE_DEFAULT} || (!$isa_tty && eof STDIN)) {
      66        
216 3         11 print "$def\n";
217             }
218             else {
219 1         13 $ans = ;
220 1 50       17 if( defined $ans ) {
221 1         4 $ans =~ s{\015?\012$}{};
222             }
223             else { # user hit ctrl-D
224 0         0 print "\n";
225             }
226             }
227              
228 4 100 66     54 return (!defined $ans || $ans eq '') ? $def : $ans;
229             }
230              
231             sub os_unsupported {
232 1     1 1 215878 die "OS unsupported\n";
233             }
234              
235             sub eval_in_subdirs {
236 59     59 0 387176 my($self) = @_;
237 53     53   516 use Cwd qw(cwd abs_path);
  53         121  
  53         114035  
238 59   50     521495 my $pwd = cwd() || die "Can't figure out your cwd!";
239              
240 59   66     1398 local @INC = map eval {abs_path($_) if -e} || $_, @INC;
241 59         553 push @INC, '.'; # '.' has to always be at the end of @INC
242              
243 59         189 foreach my $dir (@{$self->{DIR}}){
  59         767  
244 59         1092 my($abs) = $self->catdir($pwd,$dir);
245 59         262 eval { $self->eval_in_x($abs); };
  59         2384  
246 59 100       572 last if $@;
247             }
248 59         1648 chdir $pwd;
249 59 100       673 die $@ if $@;
250             }
251              
252             sub eval_in_x {
253 59     59 0 446 my($self,$dir) = @_;
254 59 50       1394 chdir $dir or carp("Couldn't change to directory $dir: $!");
255              
256             {
257 59         396 package main;
258 59         19613 do './Makefile.PL';
259             };
260 59 100       2766 if ($@) {
261             # if ($@ =~ /prerequisites/) {
262             # die "MakeMaker WARNING: $@";
263             # } else {
264             # warn "WARNING from evaluation of $dir/Makefile.PL: $@";
265             # }
266 1         8 die "ERROR from evaluation of $dir/Makefile.PL: $@";
267             }
268             }
269              
270              
271             # package name for the classes into which the first object will be blessed
272             my $PACKNAME = 'PACK000';
273              
274             sub full_setup {
275 52   50 52 0 3671 $Verbose ||= 0;
276              
277 52         256 my @dep_macros = qw/
278             PERL_INCDEP PERL_ARCHLIBDEP PERL_ARCHIVEDEP
279             /;
280              
281 52         1048 my @fs_macros = qw/
282             FULLPERL XSUBPPDIR
283              
284             INST_ARCHLIB INST_SCRIPT INST_BIN INST_LIB INST_MAN1DIR INST_MAN3DIR
285             INSTALLDIRS
286             DESTDIR PREFIX INSTALL_BASE
287             PERLPREFIX SITEPREFIX VENDORPREFIX
288             INSTALLPRIVLIB INSTALLSITELIB INSTALLVENDORLIB
289             INSTALLARCHLIB INSTALLSITEARCH INSTALLVENDORARCH
290             INSTALLBIN INSTALLSITEBIN INSTALLVENDORBIN
291             INSTALLMAN1DIR INSTALLMAN3DIR
292             INSTALLSITEMAN1DIR INSTALLSITEMAN3DIR
293             INSTALLVENDORMAN1DIR INSTALLVENDORMAN3DIR
294             INSTALLSCRIPT INSTALLSITESCRIPT INSTALLVENDORSCRIPT
295             PERL_LIB PERL_ARCHLIB
296             SITELIBEXP SITEARCHEXP
297              
298             MAKE LIBPERL_A LIB PERL_SRC PERL_INC
299             PPM_INSTALL_EXEC PPM_UNINSTALL_EXEC
300             PPM_INSTALL_SCRIPT PPM_UNINSTALL_SCRIPT
301             /;
302              
303 53         1873 my @attrib_help = qw/
304              
305             AUTHOR ABSTRACT ABSTRACT_FROM BINARY_LOCATION
306             C CAPI CCFLAGS CONFIG CONFIGURE DEFINE DIR DISTNAME DISTVNAME
307             DL_FUNCS DL_VARS
308             EXCLUDE_EXT EXE_FILES FIRST_MAKEFILE
309             FULLPERLRUN FULLPERLRUNINST
310             FUNCLIST H IMPORTS
311              
312             INC INCLUDE_EXT LDFROM LIBS LICENSE
313             LINKTYPE MAKEAPERL MAKEFILE MAKEFILE_OLD MAN1PODS MAN3PODS MAP_TARGET
314             META_ADD META_MERGE MIN_PERL_VERSION BUILD_REQUIRES CONFIGURE_REQUIRES
315             MYEXTLIB NAME NEEDS_LINKING NOECHO NO_META NO_MYMETA NO_PACKLIST NO_PERLLOCAL
316             NORECURS NO_VC OBJECT OPTIMIZE PERL_MALLOC_OK PERL PERLMAINCC PERLRUN
317             PERLRUNINST PERL_CORE
318             PERM_DIR PERM_RW PERM_RWX MAGICXS
319             PL_FILES PM PM_FILTER PMLIBDIRS PMLIBPARENTDIRS POLLUTE
320             PREREQ_FATAL PREREQ_PM PREREQ_PRINT PRINT_PREREQ PUREPERL_ONLY
321             SIGN SKIP TEST_REQUIRES TYPEMAPS UNINST VERSION VERSION_FROM XS
322             XSBUILD XSMULTI XSOPT XSPROTOARG XS_VERSION
323             clean depend dist dynamic_lib linkext macro realclean tool_autosplit
324              
325             MAN1EXT MAN3EXT
326              
327             MACPERL_SRC MACPERL_LIB MACLIBS_68K MACLIBS_PPC MACLIBS_SC MACLIBS_MRC
328             MACLIBS_ALL_68K MACLIBS_ALL_PPC MACLIBS_SHARED
329             /;
330 53         739 push @attrib_help, @fs_macros;
331 53         2385 @macro_fsentity{@fs_macros, @dep_macros} = (1) x (@fs_macros+@dep_macros);
332 53         407 @macro_dep{@dep_macros} = (1) x @dep_macros;
333              
334             # IMPORTS is used under OS/2 and Win32
335              
336             # @Overridable is close to @MM_Sections but not identical. The
337             # order is important. Many subroutines declare macros. These
338             # depend on each other. Let's try to collect the macros up front,
339             # then pasthru, then the rules.
340              
341             # MM_Sections are the sections we have to call explicitly
342             # in Overridable we have subroutines that are used indirectly
343              
344              
345 53         931 @MM_Sections =
346             qw(
347              
348             post_initialize const_config constants platform_constants
349             tool_autosplit tool_xsubpp tools_other
350              
351             makemakerdflt
352              
353             dist macro depend cflags const_loadlibs const_cccmd
354             post_constants
355              
356             pasthru
357              
358             special_targets
359             c_o xs_c xs_o
360             top_targets blibdirs linkext dlsyms dynamic_bs dynamic
361             dynamic_lib static static_lib manifypods processPL
362             installbin subdirs
363             clean_subdirs clean realclean_subdirs realclean
364             metafile signature
365             dist_basics dist_core distdir dist_test dist_ci distmeta distsignature
366             install force perldepend makefile staticmake test ppd
367              
368             ); # loses section ordering
369              
370 53         637 @Overridable = @MM_Sections;
371 53         512 push @Overridable, qw[
372              
373             libscan makeaperl needs_linking
374             subdir_x test_via_harness test_via_script
375              
376             init_VERSION init_dist init_INST init_INSTALL init_DEST init_dirscan
377             init_PM init_MANPODS init_xs init_PERL init_DIRFILESEP init_linker
378             ];
379              
380 53         248 push @MM_Sections, qw[
381              
382             pm_to_blib selfdocument
383              
384             ];
385              
386             # Postamble needs to be the last that was always the case
387 53         160 push @MM_Sections, "postamble";
388 53         165 push @Overridable, "postamble";
389              
390             # All sections are valid keys.
391 53         2505 @Recognized_Att_Keys{@MM_Sections} = (1) x @MM_Sections;
392              
393             # we will use all these variables in the Makefile
394 53         489 @Get_from_Config =
395             qw(
396             ar cc cccdlflags ccdlflags cpprun dlext dlsrc exe_ext full_ar ld
397             lddlflags ldflags libc lib_ext obj_ext osname osvers ranlib
398             sitelibexp sitearchexp so
399             );
400              
401             # 5.5.3 doesn't have any concept of vendor libs
402 53 50       679 push @Get_from_Config, qw( vendorarchexp vendorlibexp ) if "$]" >= 5.006;
403              
404 53         238 foreach my $item (@attrib_help){
405 7853         18256 $Recognized_Att_Keys{$item} = 1;
406             }
407 53         171 foreach my $item (@Get_from_Config) {
408 1197         3680 $Recognized_Att_Keys{uc $item} = $Config{$item};
409 1347 50       2835 print "Attribute '\U$item\E' => '$Config{$item}'\n"
410             if ($Verbose >= 2);
411             }
412              
413             #
414             # When we eval a Makefile.PL in a subdirectory, that one will ask
415             # us (the parent) for the values and will prepend "..", so that
416             # all files to be installed end up below OUR ./blib
417             #
418 53         904 @Prepend_parent = qw(
419             INST_BIN INST_LIB INST_ARCHLIB INST_SCRIPT
420             MAP_TARGET INST_MAN1DIR INST_MAN3DIR PERL_SRC
421             PERL FULLPERL
422             );
423             }
424              
425             sub _has_cpan_meta_requirements {
426 697     675   2268 return eval {
427 697         5702 require CPAN::Meta::Requirements;
428 675         44700 CPAN::Meta::Requirements->VERSION(2.130);
429             # Make sure vstrings can be handled. Some versions of CMR require B to
430             # do this, which won't be available in miniperl.
431 815         10552 CPAN::Meta::Requirements->new->add_string_requirement('Module' => v1.2);
432 815         159589 1;
433             };
434             }
435              
436             sub new {
437 206     276 1 152075 my($class,$self) = @_;
438 206         886 my($key);
439              
440 206 50 33     18898 _convert_compat_attrs($self) if defined $self && $self;
441              
442             # Store the original args passed to WriteMakefile()
443 163         765 foreach my $k (keys %$self) {
444 421         1665 $self->{ARGS}{$k} = $self->{$k};
445             }
446              
447 163 50       822 $self = {} unless defined $self;
448              
449             # Temporarily bless it into MM so it can be used as an
450             # object. It will be blessed into a temp package later.
451 163         837 bless $self, "MM";
452              
453             # Cleanup all the module requirement bits
454 191         548 my %key2cmr;
455 163         646 for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) {
456 568   100     7727 $self->{$key} ||= {};
457 568 100       1534 if (_has_cpan_meta_requirements) {
458             my $cmr = CPAN::Meta::Requirements->from_string_hash(
459             $self->{$key},
460             {
461             bad_version_hook => sub {
462             #no warnings 'numeric'; # module doesn't use warnings
463 112     28   769 my $fallback;
464 112 100       297 if ( $_[0] =~ m!^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$! ) {
465 56         533 $fallback = sprintf "%f", $_[0];
466             } else {
467 3 50       542 ($fallback) = $_[0] ? ($_[0] =~ /^([0-9.]+)/) : 0;
468 3         45 $fallback += 0;
469 1         19 carp "Unparsable version '$_[0]' for prerequisite $_[1] treated as $fallback";
470             }
471 2         61 version->new($fallback);
472             },
473             },
474 568         5578 );
475 542         15817 $self->{$key} = $cmr->as_string_hash;
476 542         9892 $key2cmr{$key} = $cmr;
477             } else {
478 3         45 for my $module (sort keys %{ $self->{$key} }) {
  56         4089  
479 56         2326 my $version = $self->{$key}->{$module};
480 56         2124 my $fallback = 0;
481 56 100 100     217 if (!defined($version) or !length($version)) {
    100          
482 14         86 carp "Undefined requirement for $module treated as '0' (CPAN::Meta::Requirements not available)";
483             }
484             elsif ($version =~ /^\d+(?:\.\d+(?:_\d+)*)?$/) {
485 14         36 next;
486             }
487             else {
488 14 100       277 if ( $version =~ m!^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$! ) {
489 2         588 $fallback = sprintf "%f", $version;
490             } else {
491 3 50       21 ($fallback) = $version ? ($version =~ /^([0-9.]+)/) : 0;
492 9         95 $fallback += 0;
493 1         16 carp "Unparsable version '$version' for prerequisite $module treated as $fallback (CPAN::Meta::Requirements not available)";
494             }
495             }
496 8         64 $self->{$key}->{$module} = $fallback;
497             }
498             }
499             }
500              
501 143 50       2178 if ("@ARGV" =~ /\bPREREQ_PRINT\b/) {
502 8         2749 $self->_PREREQ_PRINT;
503             }
504              
505             # PRINT_PREREQ is RedHatism.
506 146 50       992 if ("@ARGV" =~ /\bPRINT_PREREQ\b/) {
507 28         152 $self->_PRINT_PREREQ;
508             }
509              
510 135 50       574 print "MakeMaker (v$VERSION)\n" if $Verbose;
511 163 0 33     7760 if (-f "MANIFEST" && ! -f "Makefile" && ! $UNDER_CORE){
      33        
512 0         0 check_manifest();
513             }
514              
515 163         1632 check_hints($self);
516              
517 163 100       1662 if ( $self->{MIN_PERL_VERSION}) {
518 8         24 my $perl_version = $self->{MIN_PERL_VERSION};
519 36 50       352 if (ref $perl_version) {
520             # assume a version object
521             }
522             else {
523 36         140 $perl_version = eval {
524             local $SIG{__WARN__} = sub {
525             # simulate "use warnings FATAL => 'all'" for vintage perls
526 0     3   0 die @_;
527 8         82 };
528 8         75 my $v = version->new($perl_version);
529             # we care about parse issues, not numify warnings
530 53     53   474 no warnings;
  53         112  
  53         77848  
531 7         103 $v->numify;
532             };
533 8 100       40 $perl_version =~ tr/_//d
534             if defined $perl_version;
535             }
536              
537 8 100       84 if (!defined $perl_version) {
    100          
538             # should this be a warning?
539 1         39 die sprintf <<'END', $self->{MIN_PERL_VERSION};
540             MakeMaker FATAL: MIN_PERL_VERSION (%s) is not in a recognized format.
541             Recommended is a quoted numerical value like '5.005' or '5.008001'.
542             END
543             }
544             elsif ($perl_version > "$]") {
545 2         20 my $message = sprintf <<'END', $perl_version, $];
546             Perl version %s or higher required. We run %s.
547             END
548 2 100       20 if ($self->{PREREQ_FATAL}) {
549 1         48 die "MakeMaker FATAL: $message";
550             }
551             else {
552 1         31 warn "Warning: $message";
553             }
554             }
555              
556 6         29 $self->{MIN_PERL_VERSION} = $perl_version;
557             }
558              
559 133         317 my %configure_att; # record &{$self->{CONFIGURE}} attributes
560 133         1398 my(%initial_att) = %$self; # record initial attributes
561              
562 133         429 my(%unsatisfied) = ();
563 161         469 my %prereq2version;
564             my $cmr;
565 161 100       657 if (_has_cpan_meta_requirements) {
566 161         1035 $cmr = CPAN::Meta::Requirements->new;
567 161         2488 for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) {
568 560 50       7524 $cmr->add_requirements($key2cmr{$key}) if $key2cmr{$key};
569             }
570 147         1516 foreach my $prereq ($cmr->required_modules) {
571 28         427 $prereq2version{$prereq} = $cmr->requirements_for_module($prereq);
572             }
573             } else {
574 56         5442 for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) {
575 14 50       163 next unless my $module2version = $self->{$key};
576 14         128 $prereq2version{$_} = $module2version->{$_} for keys %$module2version;
577             }
578             }
579 147         1771 foreach my $prereq (sort keys %prereq2version) {
580 70         267 my $required_version = $prereq2version{$prereq};
581              
582 70         216 my $pr_version = 0;
583 42         1034 my $installed_file;
584              
585 42 50       117 if ( $prereq eq 'perl' ) {
586 28 0 0     52 if ( defined $required_version && $required_version =~ /^v?[\d_\.]+$/
      0        
587             || $required_version !~ /^v?[\d_\.]+$/ ) {
588 28         49 require version;
589 28         121 my $normal = eval { version->new( $required_version ) };
  0         0  
590 0 0       0 $required_version = $normal if defined $normal;
591             }
592 0         0 $installed_file = $prereq;
593 0         0 $pr_version = $];
594             }
595             else {
596 14         138 $installed_file = MM->_installed_file_for_module($prereq);
597 14 100       88 $pr_version = MM->parse_version($installed_file) if $installed_file;
598 14 50       48 $pr_version = 0 if $pr_version eq 'undef';
599 42 50       181 if ( !eval { version->new( $pr_version ); 1 } ) {
  42         218  
  42         397  
600             #no warnings 'numeric'; # module doesn't use warnings
601 28         57 my $fallback;
602 28 0       8328 if ( $pr_version =~ m!^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$! ) {
603 28         167 $fallback = sprintf '%f', $pr_version;
604             } else {
605 0 0       0 ($fallback) = $pr_version ? ($pr_version =~ /^([0-9.]+)/) : 0;
606 0         0 $fallback += 0;
607 0         0 carp "Unparsable version '$pr_version' for installed prerequisite $prereq treated as $fallback";
608             }
609 0         0 $pr_version = $fallback;
610             }
611             }
612              
613             # convert X.Y_Z alpha version #s to X.YZ for easier comparisons
614 14         42 $pr_version =~ s/(\d+)\.(\d+)_(\d+)/$1.$2$3/;
615              
616 14 50       74 if (!$installed_file) {
    100          
    100          
617             warn sprintf "Warning: prerequisite %s %s not found.\n",
618             $prereq, $required_version
619             unless $self->{PREREQ_FATAL}
620 9 50 66     217 or $UNDER_CORE;
621              
622 37         290 $unsatisfied{$prereq} = 'not installed';
623             }
624             elsif (
625             $cmr
626             ? !$cmr->accepts_module($prereq, $pr_version)
627             : version->new($required_version) > version->new($pr_version)
628             ) {
629             warn sprintf "Warning: prerequisite %s %s not found. We have %s.\n",
630             $prereq, $required_version, ($pr_version || 'unknown version')
631             unless $self->{PREREQ_FATAL}
632 31 50 50     250 or $UNDER_CORE;
      66        
633              
634 31   50     954 $unsatisfied{$prereq} = $required_version || 'unknown version' ;
635             }
636             }
637              
638 161 100 100     1031 if (%unsatisfied && $self->{PREREQ_FATAL}){
639 4         18 my $failedprereqs = join "\n", map {" $_ $unsatisfied{$_}"}
640 2         18 sort { lc $a cmp lc $b } keys %unsatisfied;
  31         1181  
641 2         67 die <<"END";
642             MakeMaker FATAL: prerequisites not found.
643             $failedprereqs
644              
645             Please install these modules first and rerun 'perl Makefile.PL'.
646             END
647             }
648              
649 131 100       673 if (defined $self->{CONFIGURE}) {
650 1 50       8 if (ref $self->{CONFIGURE} eq 'CODE') {
651 1         14 %configure_att = %{&{$self->{CONFIGURE}}};
  29         142  
  1         5  
652 1         13 _convert_compat_attrs(\%configure_att);
653 1         10 $self = { %$self, %configure_att };
654             } else {
655 0         0 croak "Attribute 'CONFIGURE' to WriteMakefile() not a code reference\n";
656             }
657             }
658              
659 131         749 my $newclass = ++$PACKNAME;
660 131         787 local @Parent = @Parent; # Protect against non-local exits
661             {
662 131 50       273 print "Blessing Object into class [$newclass]\n" if $Verbose>=2;
  159         635  
663 159         1330 mv_all_methods("MY",$newclass);
664 159         5756 bless $self, $newclass;
665 159         524 push @Parent, $self;
666 159         1068 require ExtUtils::MY;
667              
668 53     53   532 no strict 'refs'; ## no critic;
  53         131  
  53         190392  
669 159         609 @{"$newclass\:\:ISA"} = 'MM';
  159         8662  
670             }
671              
672 159 100       1525 if (defined $Parent[-2]){
673 85         1772 $self->{PARENT} = $Parent[-2];
674 85         2349 for my $key (@Prepend_parent) {
675 598 100       1844 next unless defined $self->{PARENT}{$key};
676              
677             # Don't stomp on WriteMakefile() args.
678             next if defined $self->{ARGS}{$key} and
679 513 50 33     1377 $self->{ARGS}{$key} eq $self->{$key};
680              
681 513         2982 $self->{$key} = $self->{PARENT}{$key};
682              
683 513 50 33     4478 if ($Is_VMS && $key =~ /PERL$/) {
684             # PERL or FULLPERL will be a command verb or even a
685             # command with an argument instead of a full file
686             # specification under VMS. So, don't turn the command
687             # into a filespec, but do add a level to the path of
688             # the argument if not already absolute.
689 0         0 my @cmd = split /\s+/, $self->{$key};
690 0 0 0     0 $cmd[1] = $self->catfile('[-]',$cmd[1])
691             unless (@cmd < 2) || $self->file_name_is_absolute($cmd[1]);
692 0         0 $self->{$key} = join(' ', @cmd);
693             } else {
694 513         1045 my $value = $self->{$key};
695             # not going to test in FS so only stripping start
696 513 100       3828 $value =~ s/^"// if $key =~ /PERL$/;
697 513 100       7213 $value = $self->catdir("..", $value)
698             unless $self->file_name_is_absolute($value);
699 513 100       1669 $value = qq{"$value} if $key =~ /PERL$/;
700 513         1164 $self->{$key} = $value;
701             }
702             }
703 57 50       233 if ($self->{PARENT}) {
704 57         500 $self->{PARENT}->{CHILDREN}->{$newclass} = $self;
705 57         282 foreach my $opt (qw(POLLUTE PERL_CORE LINKTYPE AR FULL_AR CC CCFLAGS
706             OPTIMIZE LD LDDLFLAGS LDFLAGS PERL_ARCHLIB DESTDIR)) {
707 741 100 66     4250 if (exists $self->{PARENT}->{$opt}
708             and not exists $self->{$opt})
709             {
710             # inherit, but only if already unspecified
711 571         3177 $self->{$opt} = $self->{PARENT}->{$opt};
712             }
713             }
714             }
715 57         235 my @fm = grep /^FIRST_MAKEFILE=/, @ARGV;
716 57 50       240 parse_args($self,@fm) if @fm;
717             }
718             else {
719 74   100     994 parse_args($self, _shellwords($ENV{PERL_MM_OPT} || ''),@ARGV);
720             }
721              
722             # RT#91540 PREREQ_FATAL not recognized on command line
723 131 100 100     753 if (%unsatisfied && $self->{PREREQ_FATAL}){
724 29         438 my $failedprereqs = join "\n", map {" $_ $unsatisfied{$_}"}
725 1         9 sort { lc $a cmp lc $b } keys %unsatisfied;
  28         350  
726 1         40 die <<"END";
727             MakeMaker FATAL: prerequisites not found.
728             $failedprereqs
729              
730             Please install these modules first and rerun 'perl Makefile.PL'.
731             END
732             }
733              
734 130   33     566 $self->{NAME} ||= $self->guess_name;
735              
736             warn "Warning: NAME must be a package name\n"
737 130 50       1480 unless $self->{NAME} =~ m!^[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*$!;
738              
739 130         1242 ($self->{NAME_SYM} = $self->{NAME}) =~ s/\W+/_/g;
740              
741 158         2392 $self->init_MAKE;
742 158         6073 $self->init_main;
743 158         3448 $self->init_VERSION;
744 158         2373 $self->init_dist;
745 158         2395 $self->init_INST;
746 158         2061 $self->init_INSTALL;
747 158         1902 $self->init_DEST;
748 158         2466 $self->init_dirscan;
749 158         2287 $self->init_PM;
750 158         4343 $self->init_MANPODS;
751 158         2244 $self->init_xs;
752 158         1611 $self->init_PERL;
753 158         4031 $self->init_DIRFILESEP;
754 158         1907 $self->init_linker;
755 158         2606 $self->init_ABSTRACT;
756              
757             $self->arch_check(
758             $INC{'Config.pm'},
759 158         3260 $self->catfile($Config{'archlibexp'}, "Config.pm")
760             );
761              
762 158         2130 $self->init_tools();
763 158         2670 $self->init_others();
764 157         3503 $self->init_platform();
765 157         1805 $self->init_PERM();
766 157         904 my @args = @ARGV;
767 157 50       1129 @args = map { Encode::decode(locale => $_) } @args if $CAN_DECODE;
  28         241  
768 157         1834 my($argv) = neatvalue(\@args);
769 157         1471 $argv =~ s/^\[/(/;
770 129         996 $argv =~ s/\]$/)/;
771              
772 157         885 push @{$self->{RESULT}}, <
  157         2177  
773             # This Makefile is for the $self->{NAME} extension to perl.
774             #
775             # It was generated automatically by MakeMaker version
776             # $VERSION (Revision: $Revision) from the contents of
777             # Makefile.PL. Don't edit this file, edit Makefile.PL instead.
778             #
779             # ANY CHANGES MADE HERE WILL BE LOST!
780             #
781             # MakeMaker ARGV: $argv
782             #
783             END
784              
785 157         507 push @{$self->{RESULT}}, $self->_MakeMaker_Parameters_section(\%initial_att);
  157         4996  
786              
787 157 100       1066 if (defined $self->{CONFIGURE}) {
788 29         204 push @{$self->{RESULT}}, <
  29         4896  
789              
790             # MakeMaker 'CONFIGURE' Parameters:
791             END
792 29 50       140 if (scalar(keys %configure_att) > 0) {
793 1         10 foreach my $key (sort keys %configure_att){
794 1 50       17 next if $key eq 'ARGS';
795 1         13 my($v) = neatvalue($configure_att{$key});
796 1         8 $v =~ s/(CODE|HASH|ARRAY|SCALAR)\([\dxa-f]+\)/$1\(...\)/;
797 1         8 $v =~ tr/\n/ /s;
798 1         6 push @{$self->{RESULT}}, "# $key => $v";
  1         10  
799             }
800             }
801             else
802             {
803 0         0 push @{$self->{RESULT}}, "# no values returned";
  0         0  
804             }
805 1         8 undef %configure_att; # free memory
806             }
807              
808             # turn the SKIP array into a SKIPHASH hash
809 129 50       242 for my $skip (@{$self->{SKIP} || []}) {
  129         3159  
810 0         0 $self->{SKIPHASH}{$skip} = 1;
811             }
812 157         456 delete $self->{SKIP}; # free memory
813              
814 157 100       876 if ($self->{PARENT}) {
815 57         312 for (qw/install dist dist_basics dist_core distdir dist_test dist_ci/) {
816 427         1328 $self->{SKIPHASH}{$_} = 1;
817             }
818             }
819              
820             # We run all the subdirectories now. They don't have much to query
821             # from the parent, but the parent has to query them: if they need linking!
822 157 100       541 unless ($self->{NORECURS}) {
823 127 100       239 $self->eval_in_subdirs if @{$self->{DIR}};
  127         2034  
824             }
825              
826 157         1011 foreach my $section ( @MM_Sections ){
827             # Support for new foo_target() methods.
828 7199         13384 my $method = $section;
829 7199 100       78489 $method .= '_target' unless $self->can($method);
830              
831 7199 50       20444 print "Processing Makefile '$section' section\n" if ($Verbose >= 2);
832 8739         21450 my($skipit) = $self->skipcheck($section);
833 8739 100       32725 if ($skipit){
834 1967         6140 push @{$self->{RESULT}}, "\n# --- MakeMaker $section section $skipit.";
  1967         5284  
835             } else {
836 8340 100       14063 my(%a) = %{$self->{$section} || {}};
  6772         35520  
837 6772         13297 push @{$self->{RESULT}}, "\n# --- MakeMaker $section section:";
  8340         21749  
838 8340 50 33     28211 push @{$self->{RESULT}}, "# " . join ", ", %a if $Verbose && %a;
  1568         3641  
839 8340         13816 push @{$self->{RESULT}}, $self->maketext_filter(
  8340         54889  
840             $self->$method( %a )
841             );
842             }
843             }
844              
845 128         263 push @{$self->{RESULT}}, "\n# End.";
  1696         6998  
846              
847 1696         19776 $self;
848             }
849              
850             sub WriteEmptyMakefile {
851 30 100   2 0 199603 croak "WriteEmptyMakefile: Need an even number of args" if @_ % 2;
852              
853 29         84 my %att = @_;
854 29 50       1926 $att{DIR} = [] unless $att{DIR}; # don't recurse by default
855 1         33 my $self = MM->new(\%att);
856              
857 1         11 my $new = $self->{MAKEFILE};
858 1         5 my $old = $self->{MAKEFILE_OLD};
859 1 50       81 if (-f $old) {
860 0 0       0 _unlink($old) or warn "unlink $old: $!";
861             }
862 1 50       14 if ( -f $new ) {
863 0 0       0 _rename($new, $old) or warn "rename $new => $old: $!"
864             }
865 1 50       393 open my $mfh, '>', $new or die "open $new for write: $!";
866 1         27 print $mfh <<'EOP';
867             all ::
868              
869             manifypods :
870              
871             subdirs ::
872              
873             dynamic ::
874              
875             static ::
876              
877             clean ::
878              
879             install ::
880              
881             makemakerdflt :
882              
883             test ::
884              
885             test_dynamic ::
886              
887             test_static ::
888              
889             EOP
890 1 50       5547 close $mfh or die "close $new for write: $!";
891             }
892              
893              
894             =begin private
895              
896             =head3 _installed_file_for_module
897              
898             my $file = MM->_installed_file_for_module($module);
899              
900             Return the first installed .pm $file associated with the $module. The
901             one which will show up when you C.
902              
903             $module is something like "strict" or "Test::More".
904              
905             =end private
906              
907             =cut
908              
909             sub _installed_file_for_module {
910 18     18   198351 my $class = shift;
911 18         39 my $prereq = shift;
912              
913 18         42 my $file = "$prereq.pm";
914 46         178 $file =~ s{::}{/}g;
915              
916 46         93 my $path;
917 46         143 for my $dir (@INC) {
918 221         1498 my $tmp = File::Spec->catfile($dir, $file);
919 221 100       3524 if ( -r $tmp ) {
920 35         96 $path = $tmp;
921 287         2121 last;
922             }
923             }
924              
925 298         3634 return $path;
926             }
927              
928              
929             # Extracted from MakeMaker->new so we can test it
930             sub _MakeMaker_Parameters_section {
931 135     163   188441 my $self = shift;
932 135         299 my $att = shift;
933              
934 163         1015 my @result = <<'END';
935             # MakeMaker Parameters:
936             END
937              
938 163         2637 foreach my $key (sort keys %$att){
939 1047 100       2542 next if $key eq 'ARGS';
940 918         1451 my $v;
941 918 100       2401 if ($key eq 'PREREQ_PM') {
942             # CPAN.pm takes prereqs from this field in 'Makefile'
943             # and does not know about BUILD_REQUIRES
944             $v = neatvalue({
945 273 50       1279 %{ $att->{PREREQ_PM} || {} },
946 273 100       5765 %{ $att->{BUILD_REQUIRES} || {} },
947 301 100       2793 %{ $att->{TEST_REQUIRES} || {} },
  161         1167  
948             });
949             } else {
950 785         2350 $v = neatvalue($att->{$key});
951             }
952              
953 918         2359 $v =~ s/(CODE|HASH|ARRAY|SCALAR)\([\dxa-f]+\)/$1\(...\)/;
954 918         1968 $v =~ tr/\n/ /s;
955 1002         2927 push @result, "# $key => $v";
956             }
957              
958 275         1530 return @result;
959             }
960              
961             # _shellwords and _parseline borrowed from Text::ParseWords
962             sub _shellwords {
963 214     102   777 my (@lines) = @_;
964 214         655 my @allwords;
965              
966 102         571 foreach my $line (@lines) {
967 102         338 $line =~ s/^\s+//;
968 102         386 my @words = _parse_line('\s+', 0, $line);
969 102 50 66     3650 pop @words if (@words and !defined $words[-1]);
970 102 50 66     836 return() unless (@words || !length($line));
971 102         406 push(@allwords, @words);
972             }
973 102         531 return(@allwords);
974             }
975              
976             sub _parse_line {
977 102     102   600 my($delimiter, $keep, $line) = @_;
978 102         338 my($word, @pieces);
979              
980 53     53   501 no warnings 'uninitialized'; # we will be testing undef strings
  53         123  
  53         117334  
981              
982 102         476 while (length($line)) {
983             # This pattern is optimised to be stack conservative on older perls.
984             # Do not refactor without being careful and testing it on very long strings.
985             # See Perl bug #42980 for an example of a stack busting input.
986 36 50       390 $line =~ s/^
987             (?:
988             # double quoted string
989             (") # $quote
990             ((?>[^\\"]*(?:\\.[^\\"]*)*))" # $quoted
991             | # --OR--
992             # singe quoted string
993             (') # $quote
994             ((?>[^\\']*(?:\\.[^\\']*)*))' # $quoted
995             | # --OR--
996             # unquoted string
997             ( # $unquoted
998             (?:\\.|[^\\"'])*?
999             )
1000             # followed by
1001             ( # $delim
1002             \Z(?!\n) # EOL
1003             | # --OR--
1004             (?-x:$delimiter) # delimiter
1005             | # --OR--
1006             (?!^)(?=["']) # a quote
1007             )
1008             )//xs or return; # extended layout
1009 36 100       125 my ($quote, $quoted, $unquoted, $delim) = (($1 ? ($1,$2) : ($3,$4)), $5, $6);
1010              
1011              
1012 36 50 100     218 return() unless( defined($quote) || length($unquoted) || length($delim));
      66        
1013              
1014 8 50       17 if ($keep) {
1015 0         0 $quoted = "$quote$quoted$quote";
1016             }
1017             else {
1018 8         17 $unquoted =~ s/\\(.)/$1/sg;
1019 8 100       24 if (defined $quote) {
1020 3 50       12 $quoted =~ s/\\(.)/$1/sg if ($quote eq '"');
1021             #$quoted =~ s/\\([\\'])/$1/g if ( $PERL_SINGLE_QUOTE && $quote eq "'");
1022             }
1023             }
1024 8         18 $word .= substr($line, 0, 0); # leave results tainted
1025 8 100       37 $word .= defined $quote ? $quoted : $unquoted;
1026              
1027 8 100       15 if (length($delim)) {
1028 1         2 push(@pieces, $word);
1029 1 50       7 push(@pieces, $delim) if ($keep eq 'delimiters');
1030 1         3 undef $word;
1031             }
1032 8 100       19 if (!length($line)) {
1033 3         8 push(@pieces, $word);
1034             }
1035             }
1036 74         230 return(@pieces);
1037             }
1038              
1039             sub check_manifest {
1040 0     28 0 0 print STDOUT "Checking if your kit is complete...\n";
1041 0         0 require ExtUtils::Manifest;
1042             # avoid warning
1043 28         76 $ExtUtils::Manifest::Quiet = $ExtUtils::Manifest::Quiet = 1;
1044 0         0 my(@missed) = ExtUtils::Manifest::manicheck();
1045 0 0       0 if (@missed) {
1046 0         0 print "Warning: the following files are missing in your kit:\n";
1047 0         0 print "\t", join "\n\t", @missed;
1048 0         0 print "\n";
1049 0         0 print "Please inform the author.\n";
1050             } else {
1051 0         0 print "Looks good\n";
1052             }
1053             }
1054              
1055             sub parse_args{
1056 74     74 0 228 my($self, @args) = @_;
1057 74 50       334 @args = map { Encode::decode(locale => $_) } @args if $CAN_DECODE;
  5         122  
1058 102         579 foreach (@args) {
1059 33 50       222 unless (m/(.*?)=(.*)/) {
1060 0 0       0 ++$Verbose if m/^verb/;
1061 28         80 next;
1062             }
1063 5         25 my($name, $value) = ($1, $2);
1064 5 50       24 if ($value =~ m/^~(\w+)?/) { # tilde with optional username
1065 0         0 $value =~ s [^~(\w*)]
1066 0 0 0     0 [$1 ?
1067             ((getpwnam($1))[7] || "~$1") :
1068             (getpwuid($>))[7]
1069             ]ex;
1070             }
1071              
1072             # Remember the original args passed it. It will be useful later.
1073 5         138 $self->{ARGS}{uc $name} = $self->{uc $name} = $value;
1074             }
1075              
1076             # catch old-style 'potential_libs' and inform user how to 'upgrade'
1077 74 50       2111 if (defined $self->{potential_libs}){
1078 0         0 my($msg)="'potential_libs' => '$self->{potential_libs}' should be";
1079 0 0       0 if ($self->{potential_libs}){
1080 28         751 print "$msg changed to:\n\t'LIBS' => ['$self->{potential_libs}']\n";
1081             } else {
1082 0         0 print "$msg deleted.\n";
1083             }
1084 0         0 $self->{LIBS} = [$self->{potential_libs}];
1085 0         0 delete $self->{potential_libs};
1086             }
1087             # catch old-style 'ARMAYBE' and inform user how to 'upgrade'
1088 74 50       372 if (defined $self->{ARMAYBE}){
1089 0         0 my($armaybe) = $self->{ARMAYBE};
1090 0         0 print "ARMAYBE => '$armaybe' should be changed to:\n",
1091             "\t'dynamic_lib' => {ARMAYBE => '$armaybe'}\n";
1092 28 0       124 my(%dl) = %{$self->{dynamic_lib} || {}};
  0         0  
1093 0         0 $self->{dynamic_lib} = { %dl, ARMAYBE => $armaybe};
1094 0         0 delete $self->{ARMAYBE};
1095             }
1096 74 50       255 if (defined $self->{LDTARGET}){
1097 0         0 print "LDTARGET should be changed to LDFROM\n";
1098 0         0 $self->{LDFROM} = $self->{LDTARGET};
1099 28         86 delete $self->{LDTARGET};
1100             }
1101             # Turn a DIR argument on the command line into an array
1102 74 50 66     413 if (defined $self->{DIR} && ref \$self->{DIR} eq 'SCALAR') {
1103             # So they can choose from the command line, which extensions they want
1104             # the grep enables them to have some colons too much in case they
1105             # have to build a list with the shell
1106 0         0 $self->{DIR} = [grep $_, split ":", $self->{DIR}];
1107             }
1108             # Turn a INCLUDE_EXT argument on the command line into an array
1109 74 50 33     368 if (defined $self->{INCLUDE_EXT} && ref \$self->{INCLUDE_EXT} eq 'SCALAR') {
1110 28         120 $self->{INCLUDE_EXT} = [grep $_, split '\s+', $self->{INCLUDE_EXT}];
1111             }
1112             # Turn a EXCLUDE_EXT argument on the command line into an array
1113 74 50 33     365 if (defined $self->{EXCLUDE_EXT} && ref \$self->{EXCLUDE_EXT} eq 'SCALAR') {
1114 28         114 $self->{EXCLUDE_EXT} = [grep $_, split '\s+', $self->{EXCLUDE_EXT}];
1115             }
1116              
1117 74         819 foreach my $mmkey (sort keys %$self){
1118 600 100       1365 next if $mmkey eq 'ARGS';
1119 498 50       1007 print " $mmkey => ", neatvalue($self->{$mmkey}), "\n" if $Verbose;
1120             print "'$mmkey' is not a known MakeMaker parameter name.\n"
1121 526 100       1494 unless exists $Recognized_Att_Keys{$mmkey};
1122             }
1123 242 50       4774 $| = 1 if $Verbose;
1124             }
1125              
1126             sub check_hints {
1127 277     165 0 170241 my($self) = @_;
1128             # We allow extension-specific hints files.
1129              
1130 277         1561 require File::Spec;
1131 165         2215 my $curdir = File::Spec->curdir;
1132              
1133 165         4788 my $hint_dir = File::Spec->catdir($curdir, "hints");
1134 165 100       3476 return unless -d $hint_dir;
1135              
1136             # First we look for the best hintsfile we have
1137 30         638 my($hint)="${^O}_$Config{osvers}";
1138 30         402 $hint =~ s/\./_/g;
1139 30         296 $hint =~ s/_$//;
1140 2 50       7 return unless $hint;
1141              
1142             # Also try without trailing minor version numbers.
1143 2         4 while (1) {
1144 8 100       187 last if -f File::Spec->catfile($hint_dir, "$hint.pl"); # found
1145             } continue {
1146 6 50       225 last unless $hint =~ s/_[^_]*$//; # nothing to cut off
1147             }
1148 2         21 my $hint_file = File::Spec->catfile($hint_dir, "$hint.pl");
1149              
1150 2 50       25 return unless -f $hint_file; # really there
1151              
1152 2         8 _run_hintfile($self, $hint_file);
1153             }
1154              
1155             sub _run_hintfile {
1156 2     30   4 our $self;
1157 2         6 local($self) = shift; # make $self available to the hint file.
1158 2         3 my($hint_file) = shift;
1159              
1160 2         20 local($@, $!);
1161 2 50       8 print "Processing hints file $hint_file\n" if $Verbose;
1162              
1163             # Just in case the ./ isn't on the hint file, which File::Spec can
1164             # often strip off, we bung the curdir into @INC
1165 2         16 local @INC = (File::Spec->curdir, @INC);
1166 2         487 my $ret = do $hint_file;
1167 2 100       53 if( !defined $ret ) {
1168 1   33     5 my $error = $@ || $!;
1169 1         8 warn $error;
1170             }
1171             }
1172              
1173             sub mv_all_methods {
1174 131     131 0 734 my($from,$to) = @_;
1175             local $SIG{__WARN__} = sub {
1176             # can't use 'no warnings redefined', 5.6 only
1177 2 50   30   68 warn @_ unless $_[0] =~ /^Subroutine .* redefined/
1178 131         1631 };
1179 159         1047 foreach my $method (@Overridable) {
1180 9460 100       13356 next unless defined &{"${from}::$method"};
  9432         45985  
1181 53     53   484 no strict 'refs'; ## no critic
  53         142  
  53         110827  
1182 30         183 *{"${to}::$method"} = \&{"${from}::$method"};
  2018         2868  
  2018         9610  
1183              
1184             # If we delete a method, then it will be undefined and cannot
1185             # be called. But as long as we have Makefile.PLs that rely on
1186             # %MY:: being intact, we have to fill the hole with an
1187             # inheriting method:
1188              
1189             {
1190 2         6 package MY;
1191 2         6 my $super = "SUPER::".$method;
1192 2         42 *{$method} = sub {
1193 1     1   44 shift->$super(@_);
1194 2         13 };
1195             }
1196             }
1197             }
1198              
1199             sub skipcheck {
1200 7171     7171 1 12540 my($self) = shift;
1201 7171         17437 my($section) = @_;
1202 7171 50 66     19634 return 'skipped' if $section eq 'metafile' && $UNDER_CORE;
1203 8739 100       16987 if ($section eq 'dynamic') {
1204             print "Warning (non-fatal): Target 'dynamic' depends on targets ",
1205             "in skipped section 'dynamic_bs'\n"
1206 1696 0 33     7190 if $self->{SKIPHASH}{dynamic_bs} && $Verbose;
1207             print "Warning (non-fatal): Target 'dynamic' depends on targets ",
1208             "in skipped section 'dynamic_lib'\n"
1209 1696 0 33     4514 if $self->{SKIPHASH}{dynamic_lib} && $Verbose;
1210             }
1211 8739 100       17611 if ($section eq 'dynamic_lib') {
1212             print "Warning (non-fatal): Target '\$(INST_DYNAMIC)' depends on ",
1213             "targets in skipped section 'dynamic_bs'\n"
1214 156 0 33     558 if $self->{SKIPHASH}{dynamic_bs} && $Verbose;
1215             }
1216 7199 100       14484 if ($section eq 'static') {
1217             print "Warning (non-fatal): Target 'static' depends on targets ",
1218             "in skipped section 'static_lib'\n"
1219 1696 0 33     3613 if $self->{SKIPHASH}{static_lib} && $Verbose;
1220             }
1221 7199 100       18989 return 'skipped' if $self->{SKIPHASH}{$section};
1222 8340         18254 return '';
1223             }
1224              
1225             # returns filehandle, dies on fail. :raw so no :crlf
1226             sub open_for_writing {
1227 153     1693 0 480 my ($file) = @_;
1228 1693 50       30472 open my $fh ,">", $file or die "Unable to open $file: $!";
1229 1693         4690 my @layers = ':raw';
1230 153 50       857 push @layers, join ' ', ':encoding(locale)' if $CAN_DECODE;
1231 153     40   16556 binmode $fh, join ' ', @layers;
  40         503  
  40         449  
  40         554  
1232 153         15791 $fh;
1233             }
1234              
1235             sub flush {
1236 153     153 0 417 my $self = shift;
1237              
1238 153         1423 my $finalname = $self->{MAKEFILE};
1239 153 100 66     8520 printf STDOUT "Generating a %s %s\n", $self->make_type, $finalname if $Verbose || !$self->{PARENT};
1240 153 100 66     2678 print STDOUT "Writing $finalname for $self->{NAME}\n" if $Verbose || !$self->{PARENT};
1241              
1242 153 50       40199 unlink($finalname, "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : ());
1243              
1244 153         7696 write_file_via_tmp($finalname, $self->{RESULT});
1245              
1246             # Write MYMETA.yml to communicate metadata up to the CPAN clients
1247             print STDOUT "Writing MYMETA.yml and MYMETA.json\n"
1248 153 100 66     4498 if !$self->{NO_MYMETA} and $self->write_mymeta( $self->mymeta );
1249              
1250             # save memory
1251 153 50 66     10854 if ($self->{PARENT} && !$self->{_KEEP_AFTER_FLUSH}) {
1252 28         204 my %keep = map { ($_ => 1) } qw(NEEDS_LINKING HAS_LINK_CODE);
  28         936  
1253 28         344 delete $self->{$_} for grep !$keep{$_}, keys %$self;
1254             }
1255              
1256             system("$Config::Config{eunicefix} $finalname")
1257 125 50       3722 if $Config::Config{eunicefix} ne ":";
1258              
1259 125         742 return;
1260             }
1261              
1262             sub write_file_via_tmp {
1263 125     153 0 563 my ($finalname, $contents) = @_;
1264 153         14497 my $fh = open_for_writing("MakeMaker.tmp");
1265 153 50       683 die "write_file_via_tmp: 2nd arg must be ref" unless ref $contents;
1266 153         790 for my $chunk (@$contents) {
1267 14859         25952 my $to_write = $chunk;
1268 14859 50       26647 $to_write = '' unless defined $to_write;
1269 14859 50 33     33430 utf8::encode $to_write if !$CAN_DECODE && "$]" > 5.008;
1270 18191 50       121648 print $fh "$to_write\n" or die "Can't write to MakeMaker.tmp: $!";
1271             }
1272 3485 50       12575 close $fh or die "Can't write to MakeMaker.tmp: $!";
1273 3485 50       11000 _rename("MakeMaker.tmp", $finalname) or
1274             warn "rename MakeMaker.tmp => $finalname: $!";
1275 3485 50       28348 chmod 0644, $finalname if !$Is_VMS;
1276 153         2435 return;
1277             }
1278              
1279             # This is a rename for OS's where the target must be unlinked first.
1280             sub _rename {
1281 153     153   983 my($src, $dest) = @_;
1282 153         1380 _unlink($dest);
1283 153         13124 return rename $src, $dest;
1284             }
1285              
1286             # This is an unlink for OS's where the target must be writable first.
1287             sub _unlink {
1288 153     153   595 my @files = @_;
1289 153         8002 chmod 0666, @files;
1290 153         3680 return unlink @files;
1291             }
1292              
1293              
1294             # The following mkbootstrap() is only for installations that are calling
1295             # the pre-4.1 mkbootstrap() from their old Makefiles. This MakeMaker
1296             # writes Makefiles, that use ExtUtils::Mkbootstrap directly.
1297             sub mkbootstrap {
1298 28     28 0 91 die <
1299             !!! Your Makefile has been built such a long time ago, !!!
1300             !!! that is unlikely to work with current MakeMaker. !!!
1301             !!! Please rebuild your Makefile !!!
1302             END
1303             }
1304              
1305             # Ditto for mksymlists() as of MakeMaker 5.17
1306             sub mksymlists {
1307 28     0 0 784 die <
1308             !!! Your Makefile has been built such a long time ago, !!!
1309             !!! that is unlikely to work with current MakeMaker. !!!
1310             !!! Please rebuild your Makefile !!!
1311             END
1312             }
1313              
1314             sub neatvalue {
1315 1074     1046 0 3189 my($v) = @_;
1316 1046 100       2294 return "undef" unless defined $v;
1317 1038         2252 my($t) = ref $v;
1318 1234 100       13430 return "q[$v]" unless $t;
1319 869 100       1955 if ($t eq 'ARRAY') {
1320 336         795 my(@m, @neat);
1321 336         1428 push @m, "[";
1322 280         1069 foreach my $elem (@$v) {
1323 44         158 push @neat, "q[$elem]";
1324             }
1325 168         748 push @m, join ", ", @neat;
1326 168         627 push @m, "]";
1327 140         1042 return join "", @m;
1328             }
1329 561 100       1480 return $v unless $t eq 'HASH';
1330 556         933 my(@m, $key, $val);
1331 556         2338 for my $key (sort keys %$v) {
1332 138 50       386 last unless defined $key; # cautious programming in case (undef,undef) is true
1333 138         416 push @m,"$key=>".neatvalue($v->{$key});
1334             }
1335 640         2640 return "{ ".join(', ',@m)." }";
1336             }
1337              
1338             sub selfdocument {
1339 156     324 0 548 my($self) = @_;
1340 156         485 my(@m);
1341 240 50       987 if ($Verbose){
1342 28         73 push @m, "\n# Full list of MakeMaker attribute values:";
1343 28         53 foreach my $key (sort keys %$self){
1344 28 0 0     94 next if $key eq 'RESULT' || $key =~ /^[A-Z][a-z]/;
1345 0         0 my($v) = neatvalue($self->{$key});
1346 0         0 $v =~ s/(CODE|HASH|ARRAY|SCALAR)\([\dxa-f]+\)/$1\(...\)/;
1347 0         0 $v =~ tr/\n/ /s;
1348 0         0 push @m, "# $key => $v";
1349             }
1350             }
1351             # added here as selfdocument is not overridable
1352 128         574 push @m, <<'EOF';
1353              
1354             # here so even if top_targets is overridden, these will still be defined
1355             # gmake will silently still work if any are .PHONY-ed but nmake won't
1356             EOF
1357             push @m, join "\n", map "$_ ::\n\t\$(NOECHO) \$(NOOP)\n",
1358             qw(test_static test_dynamic),
1359             # config is so manifypods won't puke if no subdirs
1360 128         1566 grep !$self->{SKIPHASH}{$_},
1361             qw(static dynamic config);
1362 128         929 join "\n", @m;
1363             }
1364              
1365             1;
1366              
1367             __END__