File Coverage

lib/ExtUtils/MM_Any.pm
Criterion Covered Total %
statement 641 785 81.6
branch 225 346 65.0
condition 144 302 47.6
subroutine 85 102 83.3
pod 69 73 94.5
total 1164 1608 72.3


line stmt bran cond sub pod time code
1              
2             use strict;
3 52     52   1364 use warnings;
  52         99  
  52         1455  
4 52     52   236 our $VERSION = '7.64';
  52         94  
  52         2432  
5             $VERSION =~ tr/_//d;
6              
7             use Carp;
8 52     52   269 use File::Spec;
  52         98  
  52         2589  
9 52     52   260 use File::Basename;
  52         93  
  52         1022  
10 52     52   226 BEGIN { our @ISA = qw(File::Spec); }
  52         120  
  52         2872  
11 52     52   2007  
12             # We need $Verbose
13             use ExtUtils::MakeMaker qw($Verbose neatvalue _sprintf562);
14 52     52   1454  
  52         104  
  52         5005  
15             use ExtUtils::MakeMaker::Config;
16 52     52   303  
  52         109  
  52         364  
17              
18             # So we don't have to keep calling the methods over and over again,
19             # we have these globals to cache the values. Faster and shrtr.
20             my $Curdir = __PACKAGE__->curdir;
21             #my $Updir = __PACKAGE__->updir;
22              
23             my $METASPEC_URL = 'https://metacpan.org/pod/CPAN::Meta::Spec';
24             my $METASPEC_V = 2;
25              
26             =head1 NAME
27              
28             ExtUtils::MM_Any - Platform-agnostic MM methods
29              
30             =head1 SYNOPSIS
31              
32             FOR INTERNAL USE ONLY!
33              
34             package ExtUtils::MM_SomeOS;
35              
36             # Temporarily, you have to subclass both. Put MM_Any first.
37             require ExtUtils::MM_Any;
38             require ExtUtils::MM_Unix;
39             @ISA = qw(ExtUtils::MM_Any ExtUtils::Unix);
40              
41             =head1 DESCRIPTION
42              
43             B<FOR INTERNAL USE ONLY!>
44              
45             ExtUtils::MM_Any is a superclass for the ExtUtils::MM_* set of
46             modules. It contains methods which are either inherently
47             cross-platform or are written in a cross-platform manner.
48              
49             Subclass off of ExtUtils::MM_Any I<and> L<ExtUtils::MM_Unix>. This is a
50             temporary solution.
51              
52             B<THIS MAY BE TEMPORARY!>
53              
54              
55             =head1 METHODS
56              
57             Any methods marked I<Abstract> must be implemented by subclasses.
58              
59              
60             =head2 Cross-platform helper methods
61              
62             These are methods which help writing cross-platform code.
63              
64              
65              
66             =head3 os_flavor I<Abstract>
67              
68             my @os_flavor = $mm->os_flavor;
69              
70             @os_flavor is the style of operating system this is, usually
71             corresponding to the MM_*.pm file we're using.
72              
73             The first element of @os_flavor is the major family (ie. Unix,
74             Windows, VMS, OS/2, etc...) and the rest are sub families.
75              
76             Some examples:
77              
78             Cygwin98 ('Unix', 'Cygwin', 'Cygwin9x')
79             Windows ('Win32')
80             Win98 ('Win32', 'Win9x')
81             Linux ('Unix', 'Linux')
82             MacOS X ('Unix', 'Darwin', 'MacOS', 'MacOS X')
83             OS/2 ('OS/2')
84              
85             This is used to write code for styles of operating system.
86             See os_flavor_is() for use.
87              
88              
89             =head3 os_flavor_is
90              
91             my $is_this_flavor = $mm->os_flavor_is($this_flavor);
92             my $is_this_flavor = $mm->os_flavor_is(@one_of_these_flavors);
93              
94             Checks to see if the current operating system is one of the given flavors.
95              
96             This is useful for code like:
97              
98             if( $mm->os_flavor_is('Unix') ) {
99             $out = `foo 2>&1`;
100             }
101             else {
102             $out = `foo`;
103             }
104              
105             =cut
106              
107             my $self = shift;
108             my %flavors = map { ($_ => 1) } $self->os_flavor;
109 222     222 1 1121 return (grep { $flavors{$_} } @_) ? 1 : 0;
110 222         2170 }
  222         1718  
111 222 100       680  
  222         2096  
112              
113             =head3 can_load_xs
114              
115             my $can_load_xs = $self->can_load_xs;
116              
117             Returns true if we have the ability to load XS.
118              
119             This is important because miniperl, used to build XS modules in the
120             core, can not load XS.
121              
122             =cut
123              
124             return defined &DynaLoader::boot_DynaLoader ? 1 : 0;
125             }
126              
127 0 0   0 1 0  
128             =head3 can_run
129              
130             use ExtUtils::MM;
131             my $runnable = MM->can_run($Config{make});
132              
133             If called in a scalar context it will return the full path to the binary
134             you asked for if it was found, or C<undef> if it was not.
135              
136             If called in a list context, it will return a list of the full paths to instances
137             of the binary where found in C<PATH>, or an empty list if it was not found.
138              
139             Copied from L<IPC::Cmd|IPC::Cmd/"$path = can_run( PROGRAM );">, but modified into
140             a method (and removed C<$INSTANCES> capability).
141              
142             =cut
143              
144             my ($self, $command) = @_;
145              
146             # a lot of VMS executables have a symbol defined
147             # check those first
148 9     9 1 167285 if ( $^O eq 'VMS' ) {
149             require VMS::DCLsym;
150             my $syms = VMS::DCLsym->new;
151             return $command if scalar $syms->getsym( uc $command );
152 9 50       50 }
153 0         0  
154 0         0 my @possibles;
155 0 0       0  
156             if( File::Spec->file_name_is_absolute($command) ) {
157             return $self->maybe_command($command);
158 9         21  
159             } else {
160 9 50       116 for my $dir (
161 0         0 File::Spec->path,
162             File::Spec->curdir
163             ) {
164 9         176 next if ! $dir || ! -d $dir;
165             my $abs = File::Spec->catfile($self->os_flavor_is('Win32') ? Win32::GetShortPathName( $dir ) : $dir, $command);
166             push @possibles, $abs if $abs = $self->maybe_command($abs);
167             }
168 90 100 66     1081 }
169 81 50       265 return @possibles if wantarray;
170 81 50       244 return shift @possibles;
171             }
172              
173 9 50       49  
174 9         32 =head3 can_redirect_error
175              
176             $useredirect = MM->can_redirect_error;
177              
178             True if on an OS where qx operator (or backticks) can redirect C<STDERR>
179             onto C<STDOUT>.
180              
181             =cut
182              
183             my $self = shift;
184             $self->os_flavor_is('Unix')
185             or ($self->os_flavor_is('Win32') and !$self->os_flavor_is('Win9x'))
186             or $self->os_flavor_is('OS/2')
187             }
188 137     137 1 44485162  
189 137 0 0     1479  
      33        
190             =head3 is_make_type
191              
192             my $is_dmake = $self->is_make_type('dmake');
193              
194             Returns true if C<< $self->make >> is the given type; possibilities are:
195              
196             gmake GNU make
197             dmake
198             nmake
199             bsdmake BSD pmake-derived
200              
201             =cut
202              
203             my %maketype2true;
204             # undocumented - so t/cd.t can still do its thing
205              
206             my($self, $type) = @_;
207             return $maketype2true{$type} if defined $maketype2true{$type};
208             (undef, undef, my $make_basename) = $self->splitpath($self->make);
209             return $maketype2true{$type} = 1
210 2     2   1191 if $make_basename =~ /\b$type\b/i; # executable's filename
211             return $maketype2true{$type} = 0
212             if $make_basename =~ /\b[gdn]make\b/i; # Never fall through for dmake/nmake/gmake
213 583     583 1 2370 # now have to run with "-v" and guess
214 583 100       3804 my $redirect = $self->can_redirect_error ? '2>&1' : '';
215 35         615 my $make = $self->make || $self->{MAKE};
216 35 100       707 my $minus_v = `"$make" -v $redirect`;
217             return $maketype2true{$type} = 1
218 34 100       213 if $type eq 'gmake' and $minus_v =~ /GNU make/i;
219             return $maketype2true{$type} = 1
220             if $type eq 'bsdmake'
221 33 50       428 and $minus_v =~ /^usage: make \[-BeikNnqrstWwX\]/im;
222 33   33     279 $maketype2true{$type} = 0; # it wasn't whatever you asked
223 33         146618 }
224 33 100 66     1042  
225              
226 31 50 33     347 =head3 can_dep_space
227              
228             my $can_dep_space = $self->can_dep_space;
229 31         1847  
230             Returns true if C<make> can handle (probably by quoting)
231             dependencies that contain a space. Currently known true for GNU make,
232             false for BSD pmake derivative.
233              
234             =cut
235              
236             my $cached_dep_space;
237             my $self = shift;
238             return $cached_dep_space if defined $cached_dep_space;
239             return $cached_dep_space = 1 if $self->is_make_type('gmake');
240             return $cached_dep_space = 0 if $self->is_make_type('dmake'); # only on W32
241             return $cached_dep_space = 0 if $self->is_make_type('bsdmake');
242             return $cached_dep_space = 0; # assume no
243             }
244              
245 2     2 1 40  
246 2 50       12 =head3 quote_dep
247 2 50       17  
248 0 0       0 $text = $mm->quote_dep($text);
249 0 0       0  
250 0         0 Method that protects Makefile single-value constants (mainly filenames),
251             so that make will still treat them as single values even if they
252             inconveniently have spaces in. If the make program being used cannot
253             achieve such protection and the given text would need it, throws an
254             exception.
255              
256             =cut
257              
258             my ($self, $arg) = @_;
259             die <<EOF if $arg =~ / / and not $self->can_dep_space;
260             Tried to use make dependency with space for make that can't:
261             '$arg'
262             EOF
263             $arg =~ s/( )/\\$1/g; # how GNU make does it
264             return $arg;
265             }
266              
267 429     429 1 1144  
268 429 50 33     1286 =head3 split_command
269              
270             my @cmds = $MM->split_command($cmd, @args);
271              
272 429         875 Most OS have a maximum command length they can execute at once. Large
273 429         1432 modules can easily generate commands well past that limit. Its
274             necessary to split long commands up into a series of shorter commands.
275              
276             C<split_command> will return a series of @cmds each processing part of
277             the args. Collectively they will process all the arguments. Each
278             individual line in @cmds will not be longer than the
279             $self->max_exec_len being careful to take into account macro expansion.
280              
281             $cmd should include any switches and repeated initial arguments.
282              
283             If no @args are given, no @cmds will be returned.
284              
285             Pairs of arguments will always be preserved in a single command, this
286             is a heuristic for things like pm_to_blib and pod2man which work on
287             pairs of arguments. This makes things like this safe:
288              
289             $self->split_command($cmd, %pod2man);
290              
291              
292             =cut
293              
294             my($self, $cmd, @args) = @_;
295              
296             my @cmds = ();
297             return(@cmds) unless @args;
298              
299             # If the command was given as a here-doc, there's probably a trailing
300             # newline.
301             chomp $cmd;
302              
303             # set aside 30% for macro expansion.
304 1075     1075 1 18446 my $len_left = int($self->max_exec_len * 0.70);
305             $len_left -= length $self->_expand_macros($cmd);
306 1075         1584  
307 1075 100       2643 do {
308             my $arg_str = '';
309             my @next_args;
310             while( @next_args = splice(@args, 0, 2) ) {
311 760         1464 # Two at a time to preserve pairs.
312             my $next_arg_str = "\t ". join ' ', @next_args, "\n";
313              
314 760         2693 if( !length $arg_str ) {
315 760         1994 $arg_str .= $next_arg_str
316             }
317 760         1178 elsif( length($arg_str) + length($next_arg_str) > $len_left ) {
318 765         1583 unshift @args, @next_args;
319 765         1130 last;
320 765         2484 }
321             else {
322 3065         5886 $arg_str .= $next_arg_str;
323             }
324 3065 100       5163 }
    100          
325 765         1891 chop $arg_str;
326              
327             push @cmds, $self->escape_newlines("$cmd \n$arg_str");
328 5         9 } while @args;
329 5         8  
330             return @cmds;
331             }
332 2295         4360  
333              
334             my($self, $cmd) = @_;
335 765         1369  
336             $cmd =~ s{\$\((\w+)\)}{
337 765         2986 defined $self->{$1} ? $self->{$1} : "\$($1)"
338             }e;
339             return $cmd;
340 760         3030 }
341              
342              
343             =head3 make_type
344              
345 1070     1070   2572 Returns a suitable string describing the type of makefile being written.
346              
347 1070         6161 =cut
348 1057 100       6224  
349             # override if this isn't suitable!
350 1070         4125  
351              
352             =head3 stashmeta
353              
354             my @recipelines = $MM->stashmeta($text, $file);
355              
356             Generates a set of C<@recipelines> which will result in the literal
357             C<$text> ending up in literal C<$file> when the recipe is executed. Call
358             it once, with all the text you want in C<$file>. Make macros will not
359             be expanded, so the locations will be fixed at configure-time, not
360             at build-time.
361 93     93 1 1295  
362             =cut
363              
364             my($self, $text, $file) = @_;
365             $self->echo($text, $file, { allow_variables => 0, append => 0 });
366             }
367              
368              
369             =head3 echo
370              
371             my @commands = $MM->echo($text);
372             my @commands = $MM->echo($text, $file);
373             my @commands = $MM->echo($text, $file, \%opts);
374              
375             Generates a set of @commands which print the $text to a $file.
376              
377 417     417 1 793254 If $file is not given, output goes to STDOUT.
378 417         3607  
379             If $opts{append} is true the $file will be appended to rather than
380             overwritten. Default is to overwrite.
381              
382             If $opts{allow_variables} is true, make variables of the form
383             C<$(...)> will not be escaped. Other C<$> will. Default is to escape
384             all C<$>.
385              
386             Example of use:
387              
388             my $make = join '', map "\t$_\n", $MM->echo($text, $file);
389              
390             =cut
391              
392             my($self, $text, $file, $opts) = @_;
393              
394             # Compatibility with old options
395             if( !ref $opts ) {
396             my $append = $opts;
397             $opts = { append => $append || 0 };
398             }
399             $opts->{allow_variables} = 0 unless defined $opts->{allow_variables};
400              
401             my $ql_opts = { allow_variables => $opts->{allow_variables} };
402             my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_, $ql_opts) }
403             split /\n/, $text;
404             if( $file ) {
405             my $redirect = $opts->{append} ? '>>' : '>';
406 425     425 1 50848 $cmds[0] .= " $redirect $file";
407             $_ .= " >> $file" foreach @cmds[1..$#cmds];
408             }
409 425 100       1548  
410 6         13 return @cmds;
411 6   100     59 }
412              
413 425 100       1433  
414             =head3 wraplist
415 425         1256  
416 425         3021 my $args = $mm->wraplist(@list);
  9058         15962  
417              
418 425 50       1990 Takes an array of items and turns them into a well-formatted list of
419 425 100       1850 arguments. In most cases this is simply something like:
420 425         1433  
421 425         5481 FOO \
422             BAR \
423             BAZ
424 425         3181  
425             =cut
426              
427             my $self = shift;
428             return join " \\\n\t", @_;
429             }
430              
431              
432             =head3 maketext_filter
433              
434             my $filter_make_text = $mm->maketext_filter($make_text);
435              
436             The text of the Makefile is run through this method before writing to
437             disk. It allows systems a chance to make portability fixes to the
438             Makefile.
439              
440             By default it does nothing.
441              
442 1076     1076 1 1566 This method is protected and not intended to be called outside of
443 1076         2913 MakeMaker.
444              
445             =cut
446              
447              
448              
449             =head3 cd I<Abstract>
450              
451             my $subdir_cmd = $MM->cd($subdir, @cmds);
452              
453             This will generate a make fragment which runs the @cmds in the given
454             $dir. The rough equivalent to this, except cross platform.
455              
456             cd $subdir && $cmd
457              
458             Currently $dir can only go down one level. "foo" is fine. "foo/bar" is
459             not. "../foo" is right out.
460              
461             The resulting $subdir_cmd has no leading tab nor trailing newline. This
462 8174     8174 1 29983 makes it easier to embed in a make string. For example.
463              
464             my $make = sprintf <<'CODE', $subdir_cmd;
465             foo :
466             $(ECHO) what
467             %s
468             $(ECHO) mouche
469             CODE
470              
471              
472             =head3 oneliner I<Abstract>
473              
474             my $oneliner = $MM->oneliner($perl_code);
475             my $oneliner = $MM->oneliner($perl_code, \@switches);
476              
477             This will generate a perl one-liner safe for the particular platform
478             you're on based on the given $perl_code and @switches (a -e is
479             assumed) suitable for using in a make target. It will use the proper
480             shell quoting and escapes.
481              
482             $(PERLRUN) will be used as perl.
483              
484             Any newlines in $perl_code will be escaped. Leading and trailing
485             newlines will be stripped. Makes this idiom much easier:
486              
487             my $code = $MM->oneliner(<<'CODE', [...switches...]);
488             some code here
489             another line here
490             CODE
491              
492             Usage might be something like:
493              
494             # an echo emulation
495             $oneliner = $MM->oneliner('print "Foo\n"');
496             $make = '$oneliner > somefile';
497              
498             Dollar signs in the $perl_code will be protected from make using the
499             C<quote_literal> method, unless they are recognised as being a make
500             variable, C<$(varname)>, in which case they will be left for make
501             to expand. Remember to quote make macros else it might be used as a
502             bareword. For example:
503              
504             # Assign the value of the $(VERSION_FROM) make macro to $vf.
505             $oneliner = $MM->oneliner('$vf = "$(VERSION_FROM)"');
506              
507             Its currently very simple and may be expanded sometime in the figure
508             to include more flexible code and switches.
509              
510              
511             =head3 quote_literal I<Abstract>
512              
513             my $safe_text = $MM->quote_literal($text);
514             my $safe_text = $MM->quote_literal($text, \%options);
515              
516             This will quote $text so it is interpreted literally in the shell.
517              
518             For example, on Unix this would escape any single-quotes in $text and
519             put single-quotes around the whole thing.
520              
521             If $options{allow_variables} is true it will leave C<'$(FOO)'> make
522             variables untouched. If false they will be escaped like any other
523             C<$>. Defaults to true.
524              
525             =head3 escape_dollarsigns
526              
527             my $escaped_text = $MM->escape_dollarsigns($text);
528              
529             Escapes stray C<$> so they are not interpreted as make variables.
530              
531             It lets by C<$(...)>.
532              
533             =cut
534              
535             my($self, $text) = @_;
536              
537             # Escape dollar signs which are not starting a variable
538             $text =~ s{\$ (?!\() }{\$\$}gx;
539              
540             return $text;
541             }
542              
543              
544             =head3 escape_all_dollarsigns
545              
546             my $escaped_text = $MM->escape_all_dollarsigns($text);
547              
548             Escapes all C<$> so they are not interpreted as make variables.
549              
550             =cut
551              
552 4183     4183 1 6606 my($self, $text) = @_;
553              
554             # Escape dollar signs
555 4183         9263 $text =~ s{\$}{\$\$}gx;
556              
557 4183         8256 return $text;
558             }
559              
560              
561             =head3 escape_newlines I<Abstract>
562              
563             my $escaped_text = $MM->escape_newlines($text);
564              
565             Shell escapes newlines in $text.
566              
567              
568             =head3 max_exec_len I<Abstract>
569              
570 8632     8632 1 11709 my $max_exec_len = $MM->max_exec_len;
571              
572             Calculates the maximum command size the OS can exec. Effectively,
573 8632         10343 this is the max size of a shell command line.
574              
575 8632         13649 =for _private
576             $self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes.
577              
578              
579             =head3 make
580              
581             my $make = $MM->make;
582              
583             Returns the make variant we're generating the Makefile for. This attempts
584             to do some normalization on the information from %Config or the user.
585              
586             =cut
587              
588             my $self = shift;
589              
590             my $make = lc $self->{MAKE};
591              
592             # Truncate anything like foomake6 to just foomake.
593             $make =~ s/^(\w+make).*/$1/;
594              
595             # Turn gnumake into gmake.
596             $make =~ s/^gnu/g/;
597              
598             return $make;
599             }
600              
601              
602             =head2 Targets
603              
604             These are methods which produce make targets.
605              
606              
607 69     69 1 208 =head3 all_target
608              
609 69         232 Generate the default target 'all'.
610              
611             =cut
612 69         189  
613             my $self = shift;
614              
615 69         427 return <<'MAKE_EXT';
616             all :: pure_all
617 69         1644 $(NOECHO) $(NOOP)
618             MAKE_EXT
619              
620             }
621              
622              
623             =head3 blibdirs_target
624              
625             my $make_frag = $mm->blibdirs_target;
626              
627             Creates the blibdirs target which creates all the directories we use
628             in blib/.
629              
630             The blibdirs.ts target is deprecated. Depend on blibdirs instead.
631              
632              
633 0     0 1 0 =cut
634              
635 0         0 my ($self) = @_;
636             map { (my $b = $_) =~ s/\.xs$//; $b } sort keys %{ $self->{XS} };
637             }
638              
639             my $self = shift;
640              
641             my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib
642             autodir archautodir
643             bin script
644             man1dir man3dir
645             );
646             if ($self->{XSMULTI}) {
647             for my $ext ($self->_xs_list_basenames) {
648             my ($v, $d, $f) = File::Spec->splitpath($ext);
649             my @d = File::Spec->splitdir($d);
650             shift @d if $d[0] eq 'lib';
651             push @dirs, $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
652             }
653             }
654              
655             my @exists = map { $_.'$(DFSEP).exists' } @dirs;
656 153     153   337  
657 153         265 my $make = sprintf <<'MAKE', join(' ', @exists);
  0         0  
  0         0  
  153         502  
658             blibdirs : %s
659             $(NOECHO) $(NOOP)
660              
661 153     153 1 407 # Backwards compat with 6.18 through 6.25
662             blibdirs.ts : blibdirs
663 153         453 $(NOECHO) $(NOOP)
  1224         2904  
664              
665             MAKE
666              
667             $make .= $self->dir_target(@dirs);
668 153 50       604  
669 0         0 return $make;
670 0         0 }
671 0         0  
672 0 0       0  
673 0         0 =head3 clean (o)
674              
675             Defines the clean target.
676              
677 153         364 =cut
  1224         2514  
678              
679 153         1075 # --- Cleanup and Distribution Sections ---
680              
681             my($self, %attribs) = @_;
682             my @m;
683             push(@m, '
684             # Delete temporary files but do not touch installed files. We don\'t delete
685             # the Makefile here so a later make realclean still has a makefile to use.
686              
687             clean :: clean_subdirs
688             ');
689 153         1931  
690             my @files = sort values %{$self->{XS}}; # .c files from *.xs files
691 153         656 push @files, map {
692             my $file = $_;
693             map { $file.$_ } $self->{OBJ_EXT}, qw(.def _def.old .bs .bso .exp .base);
694             } $self->_xs_list_basenames;
695             my @dirs = qw(blib);
696              
697             # Normally these are all under blib but they might have been
698             # redefined.
699             # XXX normally this would be a good idea, but the Perl core sets
700             # INST_LIB = ../../lib rather than actually installing the files.
701             # So a "make clean" in an ext/ directory would blow away lib.
702             # Until the core is adjusted let's leave this out.
703             # push @dirs, qw($(INST_ARCHLIB) $(INST_LIB)
704 153     153 1 432 # $(INST_BIN) $(INST_SCRIPT)
705 153         326 # $(INST_MAN1DIR) $(INST_MAN3DIR)
706 153         660 # $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR)
707             # $(INST_STATIC) $(INST_DYNAMIC)
708             # );
709              
710              
711             if( $attribs{FILES} ) {
712             # Use @dirs because we don't know what's in here.
713 153         343 push @dirs, ref $attribs{FILES} ?
  153         601  
714             @{$attribs{FILES}} :
715 153         1144 split /\s+/, $attribs{FILES} ;
  0         0  
716 0         0 }
  0         0  
717              
718 153         759 push(@files, qw[$(MAKE_APERL_FILE)
719             MYMETA.json MYMETA.yml perlmain.c tmon.out mon.out so_locations
720             blibdirs.ts pm_to_blib pm_to_blib.ts
721             *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
722             $(BOOTSTRAP) $(BASEEXT).bso
723             $(BASEEXT).def lib$(BASEEXT).def
724             $(BASEEXT).exp $(BASEEXT).x
725             ]);
726              
727             push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
728             push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld'));
729              
730             # core files
731             if ($^O eq 'vos') {
732             push(@files, qw[perl*.kp]);
733             }
734 153 50       528 else {
735             push(@files, qw[core core.*perl.*.? *perl.core]);
736             }
737 0         0  
738 0 0       0 push(@files, map { "core." . "[0-9]"x$_ } (1..5));
739              
740             # OS specific things to clean up. Use @dirs since we don't know
741 153         1390 # what might be in here.
742             push @dirs, $self->extra_clean_files;
743              
744             # Occasionally files are repeated several times from different sources
745             { my(%f) = map { ($_ => 1) } @files; @files = sort keys %f; }
746             { my(%d) = map { ($_ => 1) } @dirs; @dirs = sort keys %d; }
747              
748             push @m, map "\t$_\n", $self->split_command('- $(RM_F)', @files);
749             push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs);
750 153         674  
751 153         463 # Leave Makefile.old around for realclean
752             push @m, <<'MAKE';
753             $(NOECHO) $(RM_F) $(MAKEFILE_OLD)
754 153 50       705 - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL)
755 0         0 MAKE
756              
757             push(@m, "\t$attribs{POSTOP}\n") if $attribs{POSTOP};
758 153         424  
759             join("", @m);
760             }
761 153         359  
  765         1969  
762              
763             =head3 clean_subdirs_target
764              
765 153         1122 my $make_frag = $MM->clean_subdirs_target;
766              
767             Returns the clean_subdirs target. This is used by the clean target to
768 153         336 call clean on any subdirectories which contain Makefiles.
  4743         12213  
  153         3176  
769 153         271  
  153         482  
  153         354  
  153         516  
  153         489  
770             =cut
771 153         598  
772 153         608 my($self) = shift;
773              
774             # No subdirectories, no cleaning.
775 153         376 return <<'NOOP_FRAG' unless @{$self->{DIR}};
776             clean_subdirs :
777             $(NOECHO) $(NOOP)
778             NOOP_FRAG
779              
780 153 50       410  
781             my $clean = "clean_subdirs :\n";
782 153         1147  
783             for my $dir (@{$self->{DIR}}) {
784             my $subclean = $self->oneliner(sprintf <<'CODE', $dir);
785             exit 0 unless chdir '%s'; system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)';
786             CODE
787              
788             $clean .= "\t$subclean\n";
789             }
790              
791             return $clean;
792             }
793              
794              
795             =head3 dir_target
796 153     153 1 435  
797             my $make_frag = $mm->dir_target(@directories);
798              
799 153 100       230 Generates targets to create the specified directories and set its
  153         846  
800             permission to PERM_DIR.
801              
802             Because depending on a directory to just ensure it exists doesn't work
803             too well (the modified time changes too often) dir_target() creates a
804             .exists file in the created directory. It is this you should depend on.
805 56         138 For portability purposes you should use the $(DIRFILESEP) macro rather
806             than a '/' to separate the directory from the file.
807 56         105  
  56         298  
808 56         428 yourdirectory$(DIRFILESEP).exists
809              
810             =cut
811              
812 56         276 my($self, @dirs) = @_;
813              
814             my $make = '';
815 56         157 foreach my $dir (@dirs) {
816             $make .= sprintf <<'MAKE', ($dir) x 4;
817             %s$(DFSEP).exists :: Makefile.PL
818             $(NOECHO) $(MKPATH) %s
819             $(NOECHO) $(CHMOD) $(PERM_DIR) %s
820             $(NOECHO) $(TOUCH) %s$(DFSEP).exists
821              
822             MAKE
823              
824             }
825              
826             return $make;
827             }
828              
829              
830             =head3 distdir
831              
832             Defines the scratch directory target that will hold the distribution
833             before tar-ing (or shar-ing).
834              
835             =cut
836              
837 153     153 1 620 # For backwards compatibility.
838             *dist_dir = *distdir;
839 153         546  
840 153         658 my($self) = shift;
841 1224         3136  
842             my $meta_target = $self->{NO_META} ? '' : 'distmeta';
843             my $sign_target = !$self->{SIGN} ? '' : 'distsignature';
844              
845             return sprintf <<'MAKE_FRAG', $meta_target, $sign_target;
846             create_distdir :
847             $(RM_RF) $(DISTVNAME)
848             $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
849             -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
850              
851 153         1191 distdir : create_distdir %s %s
852             $(NOECHO) $(NOOP)
853              
854             MAKE_FRAG
855              
856             }
857              
858              
859             =head3 dist_test
860              
861             Defines a target that produces the distribution in the
862             scratch directory, and runs 'perl Makefile.PL; make ;make test' in that
863             subdirectory.
864              
865             =cut
866 96     96 1 285  
867             my($self) = shift;
868 96 50       743  
869 96 50       562 my $mpl_args = join " ", map qq["$_"], @ARGV;
870              
871 96         589 my $test = $self->cd('$(DISTVNAME)',
872             '$(ABSPERLRUN) Makefile.PL '.$mpl_args,
873             '$(MAKE) $(PASTHRU)',
874             '$(MAKE) test $(PASTHRU)'
875             );
876              
877             return sprintf <<'MAKE_FRAG', $test;
878             disttest : distdir
879             %s
880              
881             MAKE_FRAG
882              
883              
884             }
885              
886              
887             =head3 xs_dlsyms_arg
888              
889             Returns command-line arg(s) to linker for file listing dlsyms to export.
890             Defaults to returning empty string, can be overridden by e.g. AIX.
891              
892             =cut
893              
894 96     96 1 269 return '';
895             }
896 96         454  
897             =head3 xs_dlsyms_ext
898 96         1038  
899             Returns file-extension for C<xs_make_dlsyms> method's output file,
900             including any "." character.
901              
902             =cut
903              
904 96         524 die "Pure virtual method";
905             }
906              
907             =head3 xs_dlsyms_extra
908              
909             Returns any extra text to be prepended to the C<$extra> argument of
910             C<xs_make_dlsyms>.
911              
912             =cut
913              
914             '';
915             }
916              
917             =head3 xs_dlsyms_iterator
918              
919             Iterates over necessary shared objects, calling C<xs_make_dlsyms> method
920             for each with appropriate arguments.
921              
922 0     0 1 0 =cut
923              
924             my ($self, $attribs) = @_;
925             if ($self->{XSMULTI}) {
926             my @m;
927             for my $ext ($self->_xs_list_basenames) {
928             my @parts = File::Spec->splitdir($ext);
929             shift @parts if $parts[0] eq 'lib';
930             my $name = join '::', @parts;
931             push @m, $self->xs_make_dlsyms(
932             $attribs,
933 0     0 1 0 $ext . $self->xs_dlsyms_ext,
934             "$ext.xs",
935             $name,
936             $parts[-1],
937             {}, [], {}, [],
938             $self->xs_dlsyms_extra . q!, 'FILE' => ! . neatvalue($ext),
939             );
940             }
941             return join "\n", @m;
942             } else {
943             return $self->xs_make_dlsyms(
944 0     0 1 0 $attribs,
945             $self->{BASEEXT} . $self->xs_dlsyms_ext,
946             'Makefile.PL',
947             $self->{NAME},
948             $self->{DLBASE},
949             $attribs->{DL_FUNCS} || $self->{DL_FUNCS} || {},
950             $attribs->{FUNCLIST} || $self->{FUNCLIST} || [],
951             $attribs->{IMPORTS} || $self->{IMPORTS} || {},
952             $attribs->{DL_VARS} || $self->{DL_VARS} || [],
953             $self->xs_dlsyms_extra,
954             );
955 0     0 1 0 }
956 0 0       0 }
957 0         0  
958 0         0 =head3 xs_make_dlsyms
959 0         0  
960 0 0       0 $self->xs_make_dlsyms(
961 0         0 \%attribs, # hashref from %attribs in caller
962 0         0 "$self->{BASEEXT}.def", # output file for Makefile target
963             'Makefile.PL', # dependency
964             $self->{NAME}, # shared object's "name"
965             $self->{DLBASE}, # last ::-separated part of name
966             $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {}, # various params
967             $attribs{FUNCLIST} || $self->{FUNCLIST} || [],
968             $attribs{IMPORTS} || $self->{IMPORTS} || {},
969             $attribs{DL_VARS} || $self->{DL_VARS} || [],
970             # optional extra param that will be added as param to Mksymlists
971             );
972 0         0  
973             Utility method that returns Makefile snippet to call C<Mksymlists>.
974              
975             =cut
976              
977             my ($self, $attribs, $target, $dep, $name, $dlbase, $funcs, $funclist, $imports, $vars, $extra) = @_;
978             my @m = (
979             "\n$target: $dep\n",
980             q! $(PERLRUN) -MExtUtils::Mksymlists \\
981             -e "Mksymlists('NAME'=>\"!, $name,
982             q!\", 'DLBASE' => '!,$dlbase,
983 0   0     0 # The above two lines quoted differently to work around
      0        
      0        
      0        
984             # a bug in the 4DOS/4NT command line interpreter. The visible
985             # result of the bug was files named q('extension_name',) *with the
986             # single quotes and the comma* in the extension build directories.
987             q!', 'DL_FUNCS' => !,neatvalue($funcs),
988             q!, 'FUNCLIST' => !,neatvalue($funclist),
989             q!, 'IMPORTS' => !,neatvalue($imports),
990             q!, 'DL_VARS' => !, neatvalue($vars)
991             );
992             push @m, $extra if defined $extra;
993             push @m, qq!);"\n!;
994             join '', @m;
995             }
996              
997             =head3 dynamic (o)
998              
999             Defines the dynamic target.
1000              
1001             =cut
1002              
1003             # --- Dynamic Loading Sections ---
1004              
1005             my($self) = shift;
1006             '
1007             dynamic :: $(FIRST_MAKEFILE) config $(INST_BOOT) $(INST_DYNAMIC)
1008             $(NOECHO) $(NOOP)
1009 0     0 1 0 ';
1010 0         0 }
1011              
1012              
1013             =head3 makemakerdflt_target
1014              
1015             my $make_frag = $mm->makemakerdflt_target
1016              
1017             Returns a make fragment with the makemakerdeflt_target specified.
1018             This target is the first target in the Makefile, is the default target
1019             and simply points off to 'all' just in case any make variant gets
1020             confused or something gets snuck in before the real 'all' target.
1021              
1022             =cut
1023              
1024 0 0       0 return <<'MAKE_FRAG';
1025 0         0 makemakerdflt : all
1026 0         0 $(NOECHO) $(NOOP)
1027             MAKE_FRAG
1028              
1029             }
1030              
1031              
1032             =head3 manifypods_target
1033              
1034             my $manifypods_target = $self->manifypods_target;
1035              
1036             Generates the manifypods target. This target generates man pages from
1037             all POD files in MAN1PODS and MAN3PODS.
1038 153     153 1 319  
1039 153         638 =cut
1040              
1041             my($self) = shift;
1042              
1043             my $man1pods = '';
1044             my $man3pods = '';
1045             my $dependencies = '';
1046              
1047             # populate manXpods & dependencies:
1048             foreach my $name (sort keys %{$self->{MAN1PODS}}, sort keys %{$self->{MAN3PODS}}) {
1049             $dependencies .= " \\\n\t$name";
1050             }
1051              
1052             my $manify = <<END;
1053             manifypods : pure_all config $dependencies
1054             END
1055              
1056             my @man_cmds;
1057             foreach my $num (qw(1 3)) {
1058 153     153 1 745 my $pods = $self->{"MAN${num}PODS"};
1059             my $p2m = sprintf <<'CMD', "\$(MAN${num}SECTION)", "$]" > 5.008 ? " -u" : "";
1060             $(NOECHO) $(POD2MAN) --section=%s --perm_rw=$(PERM_RW)%s
1061             CMD
1062             push @man_cmds, $self->split_command($p2m, map {($_,$pods->{$_})} sort keys %$pods);
1063             }
1064              
1065             $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds;
1066             $manify .= join '', map { "$_\n" } @man_cmds;
1067              
1068             return $manify;
1069             }
1070              
1071             {
1072             my $has_cpan_meta;
1073             return $has_cpan_meta if defined $has_cpan_meta;
1074             return $has_cpan_meta = !!eval {
1075             require CPAN::Meta;
1076 153     153 1 344 CPAN::Meta->VERSION(2.112150);
1077             1;
1078 153         385 };
1079 153         444 }
1080 153         408 }
1081              
1082             =head3 metafile_target
1083 153         277  
  153         390  
  153         734  
1084 24         213 my $target = $mm->metafile_target;
1085              
1086             Generate the metafile target.
1087 153         675  
1088             Writes the file META.yml (YAML encoded meta-data) and META.json
1089             (JSON encoded meta-data) about the module in the distdir.
1090             The format follows Module::Build's as closely as possible.
1091 153         280  
1092 153         320 =cut
1093 306         749  
1094 306 50       1946 my $self = shift;
1095             return <<'MAKE_FRAG' if $self->{NO_META} or ! _has_cpan_meta();
1096             metafile :
1097 306         2106 $(NOECHO) $(NOOP)
  24         115  
1098             MAKE_FRAG
1099              
1100 153 100       534 my $metadata = $self->metafile_data(
1101 153         514 $self->{META_ADD} || {},
  24         150  
1102             $self->{META_MERGE} || {},
1103 153         432 );
1104              
1105             my $meta = $self->_fix_metadata_before_conversion( $metadata );
1106              
1107             my @write_metayml = $self->stashmeta(
1108             $meta->as_string({version => "1.4"}), 'META_new.yml'
1109 723 100   723   3565 );
1110 17         36 my @write_metajson = $self->stashmeta(
1111 17         6601 $meta->as_string({version => "2.0"}), 'META_new.json'
1112 17         241929 );
1113 16         151  
1114             my $metayml = join("\n\t", @write_metayml);
1115             my $metajson = join("\n\t", @write_metajson);
1116             return sprintf <<'MAKE_FRAG', $metayml, $metajson;
1117             metafile : create_distdir
1118             $(NOECHO) $(ECHO) Generating META.yml
1119             %s
1120             -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml
1121             $(NOECHO) $(ECHO) Generating META.json
1122             %s
1123             -$(NOECHO) $(MV) META_new.json $(DISTVNAME)/META.json
1124             MAKE_FRAG
1125              
1126             }
1127              
1128             =begin private
1129              
1130             =head3 _fix_metadata_before_conversion
1131 160     160 1 6522  
1132 160 100 66     1250 $mm->_fix_metadata_before_conversion( \%metadata );
1133              
1134             Fixes errors in the metadata before it's handed off to L<CPAN::Meta> for
1135             conversion. This hopefully results in something that can be used further
1136             on, no guarantee is made though.
1137              
1138             =end private
1139              
1140 132   100     2920 =cut
      100        
1141              
1142 132         1440 my ( $self, $metadata ) = @_;
1143              
1144 132         790 # we should never be called unless this already passed but
1145             # prefer to be defensive in case somebody else calls this
1146              
1147 132         965 return unless _has_cpan_meta;
1148              
1149             my $bad_version = $metadata->{version} &&
1150             !CPAN::Meta::Validator->new->version( 'version', $metadata->{version} );
1151 132         1520 # just delete all invalid versions
1152 132         1333 if( $bad_version ) {
1153 132         4962 warn "Can't parse version '$metadata->{version}'\n";
1154             $metadata->{version} = '';
1155             }
1156              
1157             my $validator2 = CPAN::Meta::Validator->new( $metadata );
1158             my @errors;
1159             push @errors, $validator2->errors if !$validator2->is_valid;
1160             my $validator14 = CPAN::Meta::Validator->new(
1161             {
1162             %$metadata,
1163             'meta-spec' => { version => 1.4 },
1164             }
1165             );
1166             push @errors, $validator14->errors if !$validator14->is_valid;
1167             # fix non-camelcase custom resource keys (only other trick we know)
1168             for my $error ( @errors ) {
1169             my ( $key ) = ( $error =~ /Custom resource '(.*)' must be in CamelCase./ );
1170             next if !$key;
1171              
1172             # first try to remove all non-alphabetic chars
1173             ( my $new_key = $key ) =~ s/[^_a-zA-Z]//g;
1174              
1175             # if that doesn't work, uppercase first one
1176             $new_key = ucfirst $new_key if !$validator14->custom_1( $new_key );
1177              
1178             # copy to new key if that worked
1179             $metadata->{resources}{$new_key} = $metadata->{resources}{$key}
1180 256     256   731 if $validator14->custom_1( $new_key );
1181              
1182             # and delete old one in any case
1183             delete $metadata->{resources}{$key};
1184             }
1185 256 50       562  
1186             # paper over validation issues, but still complain, necessary because
1187             # there's no guarantee that the above will fix ALL errors
1188 256   100     3791 my $meta = eval { CPAN::Meta->create( $metadata, { lazy_validation => 1 } ) };
1189             warn $@ if $@ and
1190 256 100       8405 $@ !~ /encountered CODE.*, but JSON can only represent references to arrays or hashes/;
1191 8         113  
1192 8         129 # use the original metadata straight if the conversion failed
1193             # or if it can't be stringified.
1194             if( !$meta ||
1195 256         1056 !eval { $meta->as_string( { version => $METASPEC_V } ) } ||
1196 256         2363 !eval { $meta->as_string }
1197 256 100       901 ) {
1198 256         145026 $meta = bless $metadata, 'CPAN::Meta';
1199             }
1200              
1201             my $now_license = $meta->as_struct({ version => 2 })->{license};
1202             if ($self->{LICENSE} and $self->{LICENSE} ne 'unknown' and
1203             @{$now_license} == 1 and $now_license->[0] eq 'unknown'
1204 256 50       2652 ) {
1205             warn "Invalid LICENSE value '$self->{LICENSE}' ignored\n";
1206 256         79921 }
1207 520         1163  
1208 520 100       1211 $meta;
1209             }
1210              
1211 1         5  
1212             =begin private
1213              
1214 1 50       5 =head3 _sort_pairs
1215              
1216             my @pairs = _sort_pairs($sort_sub, \%hash);
1217 1 50       10  
1218             Sorts the pairs of a hash based on keys ordered according
1219             to C<$sort_sub>.
1220              
1221 1         8 =end private
1222              
1223             =cut
1224              
1225             my $sort = shift;
1226 256         456 my $pairs = shift;
  256         2800  
1227 256 50 33     433054 return map { $_ => $pairs->{$_} }
1228             sort $sort
1229             keys %$pairs;
1230             }
1231              
1232 256 50 33     1196  
      33        
1233 256         1689 # Taken from Module::Build::Base
1234 256         342079 my ($self, $h, $k, $v) = @_;
1235             if (ref $h->{$k} eq 'ARRAY') {
1236 0         0 push @{$h->{$k}}, ref $v ? @$v : $v;
1237             } elsif (ref $h->{$k} eq 'HASH') {
1238             $self->_hash_merge($h->{$k}, $_, $v->{$_}) foreach keys %$v;
1239 256         303355 } else {
1240 256 50 66     452122 $h->{$k} = $v;
      66        
      33        
1241 2         13 }
1242             }
1243 2         21  
1244              
1245             =head3 metafile_data
1246 256         2042  
1247             my $metadata_hashref = $mm->metafile_data(\%meta_add, \%meta_merge);
1248              
1249             Returns the data which MakeMaker turns into the META.yml file
1250             and the META.json file. It is always in version 2.0 of the format.
1251              
1252             Values of %meta_add will overwrite any existing metadata in those
1253             keys. %meta_merge will be merged with them.
1254              
1255             =cut
1256              
1257             my $self = shift;
1258             my($meta_add, $meta_merge) = @_;
1259              
1260             $meta_add ||= {};
1261             $meta_merge ||= {};
1262              
1263             my $version = _normalize_version($self->{VERSION});
1264 17     17   15 my $release_status = ($version =~ /_/) ? 'unstable' : 'stable';
1265 17         15 my %meta = (
1266 17         35 # required
  34         54  
1267             abstract => $self->{ABSTRACT} || 'unknown',
1268             author => defined($self->{AUTHOR}) ? $self->{AUTHOR} : ['unknown'],
1269             dynamic_config => 1,
1270             generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
1271             license => [ $self->{LICENSE} || 'unknown' ],
1272             'meta-spec' => {
1273             url => $METASPEC_URL,
1274 15     15   29 version => $METASPEC_V,
1275 15 100       34 },
    100          
1276 1 50       1 name => $self->{DISTNAME},
  1         7  
1277             release_status => $release_status,
1278 7         21 version => $version,
1279              
1280 7         20 # optional
1281             no_index => { directory => [qw(t inc)] },
1282             );
1283             $self->_add_requirements_to_meta(\%meta);
1284              
1285             if (!eval { require JSON::PP; require CPAN::Meta::Converter; CPAN::Meta::Converter->VERSION(2.141170) }) {
1286             return \%meta;
1287             }
1288              
1289             # needs to be based on the original version
1290             my $v1_add = _metaspec_version($meta_add) !~ /^2/;
1291              
1292             my ($add_v, $merge_v) = map _metaspec_version($_), $meta_add, $meta_merge;
1293             for my $frag ($meta_add, $meta_merge) {
1294             my $def_v = $frag == $meta_add ? $merge_v : $add_v;
1295             $frag = CPAN::Meta::Converter->new($frag, default_version => $def_v)->upgrade_fragment;
1296             }
1297              
1298 300     300 1 30903 # if we upgraded a 1.x _ADD fragment, we gave it a prereqs key that
1299 300         650 # will override all prereqs, which is more than the user asked for;
1300             # instead, we'll go inside the prereqs and override all those
1301 300   100     835 while( my($key, $val) = each %$meta_add ) {
1302 300   100     666 if ($v1_add and $key eq 'prereqs') {
1303             $meta{$key}{$_} = $val->{$_} for keys %$val;
1304 300         1521 } elsif ($key ne 'meta-spec') {
1305 300 100       1767 $meta{$key} = $val;
1306             }
1307             }
1308              
1309             while( my($key, $val) = each %$meta_merge ) {
1310             next if $key eq 'meta-spec';
1311             $self->_hash_merge(\%meta, $key, $val);
1312             }
1313              
1314             return \%meta;
1315             }
1316              
1317              
1318 300 100 100     10241 =begin private
      100        
1319              
1320             =cut
1321              
1322             my ( $self, $meta ) = @_;
1323             # Check the original args so we can tell between the user setting it
1324 300         2319 # to an empty hash and it just being initialized.
1325             $meta->{prereqs}{configure}{requires} = $self->{ARGS}{CONFIGURE_REQUIRES}
1326 300 50       592 ? $self->{CONFIGURE_REQUIRES}
  300         14153  
  300         236800  
  300         22743  
1327 0         0 : { 'ExtUtils::MakeMaker' => 0, };
1328             $meta->{prereqs}{build}{requires} = $self->{ARGS}{BUILD_REQUIRES}
1329             ? $self->{BUILD_REQUIRES}
1330             : { 'ExtUtils::MakeMaker' => 0, };
1331 300         1837 $meta->{prereqs}{test}{requires} = $self->{TEST_REQUIRES}
1332             if $self->{ARGS}{TEST_REQUIRES};
1333 300         966 $meta->{prereqs}{runtime}{requires} = $self->{PREREQ_PM}
1334 300         1186 if $self->{ARGS}{PREREQ_PM};
1335 600 100       123781 $meta->{prereqs}{runtime}{requires}{perl} = _normalize_version($self->{MIN_PERL_VERSION})
1336 600         3215 if $self->{MIN_PERL_VERSION};
1337             }
1338              
1339             # spec version of given fragment - if not given, assume 1.4
1340             my ( $meta ) = @_;
1341             return $meta->{'meta-spec'}->{version}
1342 300         82315 if defined $meta->{'meta-spec'}
1343 306 100 100     4234 and defined $meta->{'meta-spec'}->{version};
    100          
1344 3         17 return '1.4';
1345             }
1346 3         11  
1347             my ( $self, $meta ) = @_;
1348             # Check the original args so we can tell between the user setting it
1349             # to an empty hash and it just being initialized.
1350 300         1457 if( $self->{ARGS}{CONFIGURE_REQUIRES} ) {
1351 306 100       1499 $meta->{configure_requires} = $self->{CONFIGURE_REQUIRES};
1352 6         25 } else {
1353             $meta->{configure_requires} = {
1354             'ExtUtils::MakeMaker' => 0,
1355 300         1483 };
1356             }
1357             if( $self->{ARGS}{BUILD_REQUIRES} ) {
1358             $meta->{build_requires} = $self->{BUILD_REQUIRES};
1359             } else {
1360             $meta->{build_requires} = {
1361             'ExtUtils::MakeMaker' => 0,
1362             };
1363             }
1364 455     455   1001 if( $self->{ARGS}{TEST_REQUIRES} ) {
1365             $meta->{build_requires} = {
1366             %{ $meta->{build_requires} },
1367             %{ $self->{TEST_REQUIRES} },
1368             };
1369 455 100       2637 }
1370             $meta->{requires} = $self->{PREREQ_PM}
1371             if defined $self->{PREREQ_PM};
1372 455 100       1673 $meta->{requires}{perl} = _normalize_version($self->{MIN_PERL_VERSION})
1373             if $self->{MIN_PERL_VERSION};
1374 455 100       1268 }
1375              
1376 455 100       1116 # Adapted from Module::Build::Base
1377             my ($version) = @_;
1378 455 100       1170 $version = 0 unless defined $version;
1379              
1380             if ( ref $version eq 'version' ) { # version objects
1381             $version = $version->stringify;
1382             }
1383 900     900   1549 elsif ( $version =~ /^[^v][^.]*\.[^.]+\./ ) { # no leading v, multiple dots
1384             # normalize string tuples without "v": "1.2.3" -> "v1.2.3"
1385             $version = "v$version";
1386 900 100 66     2610 }
1387 890         3049 else {
1388             # leave alone
1389             }
1390             return $version;
1391 0     0   0 }
1392              
1393             =head3 _dump_hash
1394 0 0       0  
1395 0         0 $yaml = _dump_hash(\%options, %hash);
1396              
1397             Implements a fake YAML dumper for a hash given
1398 0         0 as a list of pairs. No quoting/escaping is done. Keys
1399             are supposed to be strings. Values are undef, strings,
1400             hash refs or array refs of strings.
1401 0 0       0  
1402 0         0 Supported options are:
1403              
1404             delta => STR - indentation delta
1405 0         0 use_header => BOOL - whether to include a YAML header
1406             indent => STR - a string of spaces
1407             default: ''
1408 0 0       0  
1409             max_key_length => INT - maximum key length used to align
1410 0         0 keys and values of the same hash
1411 0         0 default: 20
  0         0  
1412             key_sort => CODE - a sort sub
1413             It may be undef, which means no sorting by keys
1414             default: sub { lc $a cmp lc $b }
1415 0 0       0  
1416             customs => HASH - special options for certain keys
1417 0 0       0 (whose values are hashes themselves)
1418             may contain: max_key_length, key_sort, customs
1419              
1420             =end private
1421              
1422 318     318   774 =cut
1423 318 100       783  
1424             croak "first argument should be a hash ref" unless ref $_[0] eq 'HASH';
1425 318 100       4582 my $options = shift;
    50          
1426 4         20 my %hash = @_;
1427              
1428             # Use a list to preserve order.
1429             my @pairs;
1430 0         0  
1431             my $k_sort
1432             = exists $options->{key_sort} ? $options->{key_sort}
1433             : sub { lc $a cmp lc $b };
1434             if ($k_sort) {
1435 318         970 croak "'key_sort' should be a coderef" unless ref $k_sort eq 'CODE';
1436             @pairs = _sort_pairs($k_sort, \%hash);
1437             } else { # list of pairs, no sorting
1438             @pairs = @_;
1439             }
1440              
1441             my $yaml = $options->{use_header} ? "--- #YAML:1.0\n" : '';
1442             my $indent = $options->{indent} || '';
1443             my $k_length = min(
1444             ($options->{max_key_length} || 20),
1445             max(map { length($_) + 1 } grep { !ref $hash{$_} } keys %hash)
1446             );
1447             my $customs = $options->{customs} || {};
1448              
1449             # printf format for key
1450             my $k_format = "%-${k_length}s";
1451              
1452             while( @pairs ) {
1453             my($key, $val) = splice @pairs, 0, 2;
1454             $val = '~' unless defined $val;
1455             if(ref $val eq 'HASH') {
1456             if ( keys %$val ) {
1457             my %k_options = ( # options for recursive call
1458             delta => $options->{delta},
1459             use_header => 0,
1460             indent => $indent . $options->{delta},
1461             );
1462             if (exists $customs->{$key}) {
1463             my %k_custom = %{$customs->{$key}};
1464             foreach my $k (qw(key_sort max_key_length customs)) {
1465             $k_options{$k} = $k_custom{$k} if exists $k_custom{$k};
1466             }
1467             }
1468             $yaml .= $indent . "$key:\n"
1469             . _dump_hash(\%k_options, %$val);
1470 31 50   31   67 }
1471 31         33 else {
1472 31         79 $yaml .= $indent . "$key: {}\n";
1473             }
1474             }
1475 31         32 elsif (ref $val eq 'ARRAY') {
1476             if( @$val ) {
1477             $yaml .= $indent . "$key:\n";
1478              
1479 31 100   17   72 for (@$val) {
  17         34  
1480 31 100       44 croak "only nested arrays of non-refs are supported" if ref $_;
1481 17 50       78 $yaml .= $indent . $options->{delta} . "- $_\n";
1482 17         29 }
1483             }
1484 14         27 else {
1485             $yaml .= $indent . "$key: []\n";
1486             }
1487 31 100       54 }
1488 31   100     59 elsif( ref $val and !blessed($val) ) {
1489             croak "only nested hashes, arrays and objects are supported";
1490             }
1491 31   50     89 else { # if it's an object, just stringify it
  80         101  
  106         148  
1492             $yaml .= $indent . sprintf "$k_format %s\n", "$key:", $val;
1493 31   50     76 }
1494             };
1495              
1496 31         50 return $yaml;
1497              
1498 31         46 }
1499 106         145  
1500 106 100       144 return eval { $_[0]->isa("UNIVERSAL"); };
1501 106 100 66     186 }
    100          
    100          
1502 18 100       31  
1503             return (sort { $b <=> $a } @_)[0];
1504             }
1505              
1506             return (sort { $a <=> $b } @_)[0];
1507 17         53 }
1508 17 50       27  
1509 0         0 =head3 metafile_file
  0         0  
1510 0         0  
1511 0 0       0 my $meta_yml = $mm->metafile_file(@metadata_pairs);
1512              
1513             Turns the @metadata_pairs into YAML.
1514 17         41  
1515             This method does not implement a complete YAML dumper, being limited
1516             to dump a hash with values which are strings, undef's or nested hashes
1517             and arrays of strings. No quoting/escaping is done.
1518 1         3  
1519             =cut
1520              
1521             my $self = shift;
1522 7 100       10  
1523 6         9 my %dump_options = (
1524             use_header => 1,
1525 6         10 delta => ' ' x 4,
1526 10 100       89 key_sort => undef,
1527 9         17 );
1528             return _dump_hash(\%dump_options, @_);
1529              
1530             }
1531 1         3  
1532              
1533             =head3 distmeta_target
1534              
1535 1         158 my $make_frag = $mm->distmeta_target;
1536              
1537             Generates the distmeta target to add META.yml and META.json to the MANIFEST
1538 80         233 in the distdir.
1539              
1540             =cut
1541              
1542 29         130 my $self = shift;
1543              
1544             my @add_meta = (
1545             $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']),
1546             exit unless -e q{META.yml};
1547 1     1 0 2 eval { maniadd({q{META.yml} => q{Module YAML meta-data (added by MakeMaker)}}) }
  1         10  
1548             or die "Could not add META.yml to MANIFEST: ${'@'}"
1549             CODE
1550             $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd'])
1551 31     31 0 54 exit unless -f q{META.json};
  109         144  
1552             eval { maniadd({q{META.json} => q{Module JSON meta-data (added by MakeMaker)}}) }
1553             or die "Could not add META.json to MANIFEST: ${'@'}"
1554             CODE
1555 31     31 0 43 );
  26         43  
1556              
1557             my @add_meta_to_distdir = map { $self->cd('$(DISTVNAME)', $_) } @add_meta;
1558              
1559             return sprintf <<'MAKE', @add_meta_to_distdir;
1560             distmeta : create_distdir metafile
1561             $(NOECHO) %s
1562             $(NOECHO) %s
1563              
1564             MAKE
1565              
1566             }
1567              
1568              
1569             =head3 mymeta
1570              
1571 14     14 1 28796 my $mymeta = $mm->mymeta;
1572              
1573 14         36 Generate MYMETA information as a hash either from an existing CPAN Meta file
1574             (META.json or META.yml) or from internal data.
1575              
1576             =cut
1577              
1578 14         30 my $self = shift;
1579             my $file = shift || ''; # for testing
1580              
1581             my $mymeta = $self->_mymeta_from_meta($file);
1582             my $v2 = 1;
1583              
1584             unless ( $mymeta ) {
1585             $mymeta = $self->metafile_data(
1586             $self->{META_ADD} || {},
1587             $self->{META_MERGE} || {},
1588             );
1589             $v2 = 0;
1590             }
1591              
1592             # Overwrite the non-configure dependency hashes
1593 153     153 1 427 $self->_add_requirements_to_meta($mymeta);
1594              
1595 153         1121 $mymeta->{dynamic_config} = 0;
1596              
1597             return $mymeta;
1598             }
1599              
1600              
1601             my $self = shift;
1602             my $metafile = shift || ''; # for testing
1603              
1604             return unless _has_cpan_meta();
1605              
1606             my $meta;
1607             for my $file ( $metafile, "META.json", "META.yml" ) {
1608 153         433 next unless -e $file;
  306         1403  
1609             eval {
1610 153         1224 $meta = CPAN::Meta->load_file($file)->as_struct( { version => 2 } );
1611             };
1612             last if $meta;
1613             }
1614             return unless $meta;
1615              
1616             # META.yml before 6.25_01 cannot be trusted. META.yml lived in the source directory.
1617             # There was a good chance the author accidentally uploaded a stale META.yml if they
1618             # rolled their own tarball rather than using "make dist".
1619             if ($meta->{generated_by} &&
1620             $meta->{generated_by} =~ /ExtUtils::MakeMaker version ([\d\._]+)/) {
1621             my $eummv = do { no warnings; $1+0; };
1622             if ($eummv < 6.2501) {
1623             return;
1624             }
1625             }
1626              
1627             return $meta;
1628             }
1629              
1630 155     155 1 16147 =head3 write_mymeta
1631 155   100     878  
1632             $self->write_mymeta( $mymeta );
1633 155         1281  
1634 155         282 Write MYMETA information to MYMETA.json and MYMETA.yml.
1635              
1636 155 100       364 =cut
1637              
1638             my $self = shift;
1639             my $mymeta = shift;
1640 151   50     2174  
      50        
1641 151         583 return unless _has_cpan_meta();
1642              
1643             my $meta_obj = $self->_fix_metadata_before_conversion( $mymeta );
1644              
1645 155         511 $meta_obj->save( 'MYMETA.json', { version => "2.0" } );
1646             $meta_obj->save( 'MYMETA.yml', { version => "1.4" } );
1647 155         311 return 1;
1648             }
1649 155         1205  
1650             =head3 realclean (o)
1651              
1652             Defines the realclean target.
1653              
1654 155     155   330 =cut
1655 155   100     859  
1656             my($self, %attribs) = @_;
1657 155 100       525  
1658             my @dirs = qw($(DISTVNAME));
1659 127         250 my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD));
1660 127         462  
1661 373 100       2966 # Special exception for the perl core where INST_* is not in blib.
1662 4         9 # This cleans up the files built from the ext/ directory (all XS).
1663 4         20 if( $self->{PERL_CORE} ) {
1664             push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR));
1665 4 50       49352 push @files, values %{$self->{PM}};
1666             }
1667 127 100       515  
1668             if( $self->has_link_code ){
1669             push @files, qw($(OBJECT));
1670             }
1671              
1672 4 50 33     30 if( $attribs{FILES} ) {
1673             if( ref $attribs{FILES} ) {
1674 52     52   498 push @dirs, @{ $attribs{FILES} };
  52         126  
  52         234614  
  4         6  
  4         17  
1675 4 50       10 }
1676 0         0 else {
1677             push @dirs, split /\s+/, $attribs{FILES};
1678             }
1679             }
1680 4         9  
1681             # Occasionally files are repeated several times from different sources
1682             { my(%f) = map { ($_ => 1) } @files; @files = sort keys %f; }
1683             { my(%d) = map { ($_ => 1) } @dirs; @dirs = sort keys %d; }
1684              
1685             my $rm_cmd = join "\n\t", map { "$_" }
1686             $self->split_command('- $(RM_F)', @files);
1687             my $rmf_cmd = join "\n\t", map { "$_" }
1688             $self->split_command('- $(RM_RF)', @dirs);
1689              
1690             my $m = sprintf <<'MAKE', $rm_cmd, $rmf_cmd;
1691             # Delete temporary files (via clean) and also delete dist files
1692 152     152 1 1461 realclean purge :: realclean_subdirs
1693 152         430 %s
1694             %s
1695 152 100       406 MAKE
1696              
1697 124         506 $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP};
1698              
1699 124         1775 return $m;
1700 124         405479 }
1701 124         352873  
1702              
1703             =head3 realclean_subdirs_target
1704              
1705             my $make_frag = $MM->realclean_subdirs_target;
1706              
1707             Returns the realclean_subdirs target. This is used by the realclean
1708             target to call realclean on any subdirectories which contain Makefiles.
1709              
1710             =cut
1711 153     153 1 467  
1712             my $self = shift;
1713 153         936 my @m = <<'EOF';
1714 153         962 # so clean is forced to complete before realclean_subdirs runs
1715             realclean_subdirs : clean
1716             EOF
1717             return join '', @m, "\t\$(NOECHO) \$(NOOP)\n" unless @{$self->{DIR}};
1718 153 50       673 foreach my $dir (@{$self->{DIR}}) {
1719 0         0 foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) {
1720 0         0 my $subrclean .= $self->oneliner(_sprintf562 <<'CODE', $dir, $makefile);
  0         0  
1721             chdir '%1$s'; system '$(MAKE) $(USEMAKEFILE) %2$s realclean' if -f '%2$s';
1722             CODE
1723 153 50       580 push @m, "\t- $subrclean\n";
1724 0         0 }
1725             }
1726             return join '', @m;
1727 153 50       583 }
1728 0 0       0  
1729 0         0  
  0         0  
1730             =head3 signature_target
1731              
1732 0         0 my $target = $mm->signature_target;
1733              
1734             Generate the signature target.
1735              
1736             Writes the file SIGNATURE with "cpansign -s".
1737 153         290  
  306         1247  
  153         819  
1738 153         276 =cut
  153         282  
  153         326  
  153         512  
  153         486  
1739              
1740 153         540 my $self = shift;
  153         753  
1741              
1742 153         554 return <<'MAKE_FRAG';
  153         828  
1743             signature :
1744             cpansign -s
1745 153         889 MAKE_FRAG
1746              
1747             }
1748              
1749              
1750             =head3 distsignature_target
1751              
1752 153 50       482 my $make_frag = $mm->distsignature_target;
1753              
1754 153         673 Generates the distsignature target to add SIGNATURE to the MANIFEST in the
1755             distdir.
1756              
1757             =cut
1758              
1759             my $self = shift;
1760              
1761             my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
1762             eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) }
1763             or die "Could not add SIGNATURE to MANIFEST: ${'@'}"
1764             CODE
1765              
1766             my $sign_dist = $self->cd('$(DISTVNAME)' => 'cpansign -s');
1767              
1768 153     153 1 434 # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not
1769 153         661 # exist
1770             my $touch_sig = $self->cd('$(DISTVNAME)' => '$(TOUCH) SIGNATURE');
1771             my $add_sign_to_dist = $self->cd('$(DISTVNAME)' => $add_sign );
1772              
1773 153 100       293 return sprintf <<'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist
  153         1228  
1774 56         157 distsignature : distmeta
  56         386  
1775 56         226 $(NOECHO) %s
1776 112         542 $(NOECHO) %s
1777             %s
1778              
1779 112         520 MAKE
1780              
1781             }
1782 56         291  
1783              
1784             =head3 special_targets
1785              
1786             my $make_frag = $mm->special_targets
1787              
1788             Returns a make fragment containing any targets which have special
1789             meaning to make. For example, .SUFFIXES and .PHONY.
1790              
1791             =cut
1792              
1793             my $make_frag = <<'MAKE_FRAG';
1794             .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)
1795              
1796             .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir pure_all subdirs clean_subdirs makemakerdflt manifypods realclean_subdirs subdirs_dynamic subdirs_pure_nolink subdirs_static subdirs-test_dynamic subdirs-test_static test_dynamic test_static
1797 153     153 1 732  
1798             MAKE_FRAG
1799 153         552  
1800             $make_frag .= <<'MAKE_FRAG' if $ENV{CLEARCASE_ROOT};
1801             .NO_CONFIG_REC: Makefile
1802              
1803             MAKE_FRAG
1804              
1805             return $make_frag;
1806             }
1807              
1808              
1809              
1810              
1811             =head2 Init methods
1812              
1813             Methods which help initialize the MakeMaker object and macros.
1814              
1815              
1816             =head3 init_ABSTRACT
1817 153     153 1 375  
1818             $mm->init_ABSTRACT
1819 153         749  
1820             =cut
1821              
1822             my $self = shift;
1823              
1824 153         530 if( $self->{ABSTRACT_FROM} and $self->{ABSTRACT} ) {
1825             warn "Both ABSTRACT_FROM and ABSTRACT are set. ".
1826             "Ignoring ABSTRACT_FROM.\n";
1827             return;
1828 153         548 }
1829 153         452  
1830             if ($self->{ABSTRACT_FROM}){
1831 153         932 $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or
1832             carp "WARNING: Setting ABSTRACT via file ".
1833             "'$self->{ABSTRACT_FROM}' failed\n";
1834             }
1835              
1836             if ($self->{ABSTRACT} && $self->{ABSTRACT} =~ m![[:cntrl:]]+!) {
1837             warn "WARNING: ABSTRACT contains control character(s),".
1838             " they will be removed\n";
1839             $self->{ABSTRACT} =~ s![[:cntrl:]]+!!g;
1840             return;
1841             }
1842             }
1843              
1844             =head3 init_INST
1845              
1846             $mm->init_INST;
1847              
1848             Called by init_main. Sets up all INST_* variables except those related
1849             to XS code. Those are handled in init_xs.
1850              
1851             =cut
1852 153     153 1 606  
1853             my($self) = shift;
1854              
1855             $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch");
1856             $self->{INST_BIN} ||= $self->catdir($Curdir,'blib','bin');
1857              
1858             # INST_LIB typically pre-set if building an extension after
1859 153 50       559 # perl has been built and installed. Setting INST_LIB allows
1860             # you to build directly into, say $Config{privlibexp}.
1861             unless ($self->{INST_LIB}){
1862             if ($self->{PERL_CORE}) {
1863             $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
1864 153         453 } else {
1865             $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib");
1866             }
1867             }
1868              
1869             my @parentdir = split(/::/, $self->{PARENT_NAME});
1870             $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)', @parentdir);
1871             $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)', @parentdir);
1872             $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)', 'auto',
1873             '$(FULLEXT)');
1874             $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto',
1875             '$(FULLEXT)');
1876              
1877             $self->{INST_SCRIPT} ||= $self->catdir($Curdir,'blib','script');
1878              
1879             $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1');
1880             $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3');
1881              
1882 155     155 1 374 return 1;
1883             }
1884 155 50 66     501  
1885 0         0  
1886             =head3 init_INSTALL
1887 0         0  
1888             $mm->init_INSTALL;
1889              
1890 155 100       444 Called by init_main. Sets up all INSTALL_* variables (except
1891 1 50       28 INSTALLDIRS) and *PREFIX.
1892              
1893             =cut
1894              
1895             my($self) = shift;
1896 155 50 66     648  
1897 0         0 if( $self->{ARGS}{INSTALL_BASE} and $self->{ARGS}{PREFIX} ) {
1898             die "Only one of PREFIX or INSTALL_BASE can be given. Not both.\n";
1899 0         0 }
1900 0         0  
1901             if( $self->{ARGS}{INSTALL_BASE} ) {
1902             $self->init_INSTALL_from_INSTALL_BASE;
1903             }
1904             else {
1905             $self->init_INSTALL_from_PREFIX;
1906             }
1907             }
1908              
1909              
1910             =head3 init_INSTALL_from_PREFIX
1911              
1912             $mm->init_INSTALL_from_PREFIX;
1913              
1914 156     156 1 533 =cut
1915              
1916 156   66     1695 my $self = shift;
1917 156   66     1466  
1918             $self->init_lib2arch;
1919              
1920             # There are often no Config.pm defaults for these new man variables so
1921             # we fall back to the old behavior which is to use installman*dir
1922 156 100       528 foreach my $num (1, 3) {
1923 99 50       270 my $k = 'installsiteman'.$num.'dir';
1924 0         0  
1925             $self->{uc $k} ||= uc "\$(installman${num}dir)"
1926 99         496 unless $Config{$k};
1927             }
1928              
1929             foreach my $num (1, 3) {
1930 156         1080 my $k = 'installvendorman'.$num.'dir';
1931 156         1297  
1932 156         911 unless( $Config{$k} ) {
1933 156         796 $self->{uc $k} ||= $Config{usevendorprefix}
1934             ? uc "\$(installman${num}dir)"
1935 156         774 : '';
1936             }
1937             }
1938 156   66     1451  
1939             $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)'
1940 156   66     1071 unless $Config{installsitebin};
1941 156   66     1142 $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)'
1942             unless $Config{installsitescript};
1943 156         430  
1944             unless( $Config{installvendorbin} ) {
1945             $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix}
1946             ? $Config{installbin}
1947             : '';
1948             }
1949             unless( $Config{installvendorscript} ) {
1950             $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix}
1951             ? $Config{installscript}
1952             : '';
1953             }
1954              
1955              
1956             my $iprefix = $Config{installprefixexp} || $Config{installprefix} ||
1957 155     155 1 386 $Config{prefixexp} || $Config{prefix} || '';
1958             my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : '';
1959 155 50 66     550 my $sprefix = $Config{siteprefixexp} || '';
1960 0         0  
1961             # 5.005_03 doesn't have a siteprefix.
1962             $sprefix = $iprefix unless $sprefix;
1963 155 100       512  
1964 2         30  
1965             $self->{PREFIX} ||= '';
1966              
1967 153         1618 if( $self->{PREFIX} ) {
1968             @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} =
1969             ('$(PREFIX)') x 3;
1970             }
1971             else {
1972             $self->{PERLPREFIX} ||= $iprefix;
1973             $self->{SITEPREFIX} ||= $sprefix;
1974             $self->{VENDORPREFIX} ||= $vprefix;
1975              
1976             # Lots of MM extension authors like to use $(PREFIX) so we
1977             # put something sensible in there no matter what.
1978             $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)';
1979 153     153 1 398 }
1980              
1981 153         1667 my $arch = $Config{archname};
1982             my $version = $Config{version};
1983              
1984             # default style
1985 153         875 my $libstyle = $Config{installstyle} || 'lib/perl5';
1986 306         789 my $manstyle = '';
1987              
1988             if( $self->{LIBSTYLE} ) {
1989 306 100 66     2273 $libstyle = $self->{LIBSTYLE};
1990             $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : '';
1991             }
1992 153         397  
1993 306         872 # Some systems, like VOS, set installman*dir to '' if they can't
1994             # read man pages.
1995 306 100       880 for my $num (1, 3) {
1996             $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none'
1997 304 100 100     2086 unless $Config{'installman'.$num.'dir'};
1998             }
1999              
2000             my %bin_layouts =
2001             (
2002             bin => { s => $iprefix,
2003 153 50 0     520 t => 'perl',
2004             d => 'bin' },
2005 153 50 0     389 vendorbin => { s => $vprefix,
2006             t => 'vendor',
2007 153 50       435 d => 'bin' },
2008             sitebin => { s => $sprefix,
2009             t => 'site',
2010 153 100 66     1380 d => 'bin' },
2011             script => { s => $iprefix,
2012 153 50       560 t => 'perl',
2013             d => 'bin' },
2014             vendorscript=> { s => $vprefix,
2015 153 100 66     971 t => 'vendor',
2016             d => 'bin' },
2017             sitescript => { s => $sprefix,
2018             t => 'site',
2019             d => 'bin' },
2020 153   0     897 );
2021 153 100       507  
2022 153   50     697 my %man_layouts =
2023             (
2024             man1dir => { s => $iprefix,
2025 153 50       425 t => 'perl',
2026             d => 'man/man1',
2027             style => $manstyle, },
2028 153   100     1205 siteman1dir => { s => $sprefix,
2029             t => 'site',
2030 153 100       407 d => 'man/man1',
2031 2         6 style => $manstyle, },
  2         11  
2032             vendorman1dir => { s => $vprefix,
2033             t => 'vendor',
2034             d => 'man/man1',
2035 151   33     874 style => $manstyle, },
2036 151   33     745  
2037 151   66     758 man3dir => { s => $iprefix,
2038             t => 'perl',
2039             d => 'man/man3',
2040             style => $manstyle, },
2041 151         654 siteman3dir => { s => $sprefix,
2042             t => 'site',
2043             d => 'man/man3',
2044 153         648 style => $manstyle, },
2045 153         422 vendorman3dir => { s => $vprefix,
2046             t => 'vendor',
2047             d => 'man/man3',
2048 153   50     555 style => $manstyle, },
2049 153         501 );
2050              
2051 153 50       417 my %lib_layouts =
2052 0         0 (
2053 0 0       0 privlib => { s => $iprefix,
2054             t => 'perl',
2055             d => '',
2056             style => $libstyle, },
2057             vendorlib => { s => $vprefix,
2058 153         466 t => 'vendor',
2059             d => '',
2060 306 100 100     2100 style => $libstyle, },
2061             sitelib => { s => $sprefix,
2062             t => 'site',
2063 153         4109 d => 'site_perl',
2064             style => $libstyle, },
2065              
2066             archlib => { s => $iprefix,
2067             t => 'perl',
2068             d => "$version/$arch",
2069             style => $libstyle },
2070             vendorarch => { s => $vprefix,
2071             t => 'vendor',
2072             d => "$version/$arch",
2073             style => $libstyle },
2074             sitearch => { s => $sprefix,
2075             t => 'site',
2076             d => "site_perl/$version/$arch",
2077             style => $libstyle },
2078             );
2079              
2080              
2081             # Special case for LIB.
2082             if( $self->{LIB} ) {
2083             foreach my $var (keys %lib_layouts) {
2084             my $Installvar = uc "install$var";
2085 153         3534  
2086             if( $var =~ /arch/ ) {
2087             $self->{$Installvar} ||=
2088             $self->catdir($self->{LIB}, $Config{archname});
2089             }
2090             else {
2091             $self->{$Installvar} ||= $self->{LIB};
2092             }
2093             }
2094             }
2095              
2096             my %type2prefix = ( perl => 'PERLPREFIX',
2097             site => 'SITEPREFIX',
2098             vendor => 'VENDORPREFIX'
2099             );
2100              
2101             my %layouts = (%bin_layouts, %man_layouts, %lib_layouts);
2102             while( my($var, $layout) = each(%layouts) ) {
2103             my($s, $t, $d, $style) = @{$layout}{qw(s t d style)};
2104             my $r = '$('.$type2prefix{$t}.')';
2105              
2106             warn "Prefixing $var\n" if $Verbose >= 2;
2107              
2108             my $installvar = "install$var";
2109             my $Installvar = uc $installvar;
2110             next if $self->{$Installvar};
2111              
2112             $d = "$style/$d" if $style;
2113             $self->prefixify($installvar, $s, $r, $d);
2114 153         3822  
2115             warn " $Installvar == $self->{$Installvar}\n"
2116             if $Verbose >= 2;
2117             }
2118              
2119             # Generate these if they weren't figured out.
2120             $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH};
2121             $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB};
2122              
2123             return 1;
2124             }
2125              
2126              
2127             =head3 init_from_INSTALL_BASE
2128              
2129             $mm->init_from_INSTALL_BASE
2130              
2131             =cut
2132              
2133             my %map = (
2134             lib => [qw(lib perl5)],
2135             arch => [('lib', 'perl5', $Config{archname})],
2136             bin => [qw(bin)],
2137             man1dir => [qw(man man1)],
2138             man3dir => [qw(man man3)]
2139             );
2140             $map{script} = $map{bin};
2141              
2142             my $self = shift;
2143              
2144             @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} =
2145 153 50       560 '$(INSTALL_BASE)';
2146 0         0  
2147 0         0 my %install;
2148             foreach my $thing (keys %map) {
2149 0 0       0 foreach my $dir (('', 'SITE', 'VENDOR')) {
2150             my $uc_thing = uc $thing;
2151 0   0     0 my $key = "INSTALL".$dir.$uc_thing;
2152              
2153             $install{$key} ||=
2154 0   0     0 ($thing =~ /^man.dir$/ and not $Config{lc $key})
2155             ? 'none'
2156             : $self->catdir('$(INSTALL_BASE)', @{$map{$thing}});
2157             }
2158             }
2159 153         1083  
2160             # Adjust for variable quirks.
2161             $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH};
2162             $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB};
2163              
2164 153         1588 foreach my $key (keys %install) {
2165 153         935 $self->{$key} ||= $install{$key};
2166 2754         3419 }
  2754         5294  
2167 2754         4476  
2168             return 1;
2169 2754 50       4115 }
2170              
2171 2754         3517  
2172 2754         3483 =head3 init_VERSION I<Abstract>
2173 2754 100       5309  
2174             $mm->init_VERSION
2175 2218 100       3456  
2176 2218         6265 Initialize macros representing versions of MakeMaker and other tools
2177              
2178 2218 50       6449 MAKEMAKER: path to the MakeMaker module.
2179              
2180             MM_VERSION: ExtUtils::MakeMaker Version
2181              
2182             MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards
2183 153   66     1408 compat)
2184 153   66     672  
2185             VERSION: version of your module
2186 153         1708  
2187             VERSION_MACRO: which macro represents the version (usually 'VERSION')
2188              
2189             VERSION_SYM: like version but safe for use as an RCS revision number
2190              
2191             DEFINE_VERSION: -D line to set the module version when compiling
2192              
2193             XS_VERSION: version in your .xs file. Defaults to $(VERSION)
2194              
2195             XS_VERSION_MACRO: which macro represents the XS version.
2196              
2197             XS_DEFINE_VERSION: -D line to set the xs version when compiling.
2198              
2199             Called by init_main.
2200              
2201             =cut
2202              
2203             my($self) = shift;
2204              
2205             $self->{MAKEMAKER} = $ExtUtils::MakeMaker::Filename;
2206 2     2 0 8 $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION;
2207             $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision;
2208 2         9 $self->{VERSION_FROM} ||= '';
  2         9  
2209              
2210             if ($self->{VERSION_FROM}){
2211 2         8 $self->{VERSION} = $self->parse_version($self->{VERSION_FROM});
2212 2         25 if( $self->{VERSION} eq 'undef' ) {
2213 12         25 carp("WARNING: Setting VERSION via file ".
2214 36         50 "'$self->{VERSION_FROM}' failed\n");
2215 36         55 }
2216             }
2217              
2218             if (defined $self->{VERSION}) {
2219             if ( $self->{VERSION} !~ /^\s*v?[\d_\.]+\s*$/ ) {
2220 36 100 66     150 require version;
  24   33     111  
2221             my $normal = eval { version->new( $self->{VERSION} ) };
2222             $self->{VERSION} = $normal if defined $normal;
2223             }
2224             $self->{VERSION} =~ s/^\s+//;
2225 2   33     14 $self->{VERSION} =~ s/\s+$//;
2226 2   33     23 }
2227             else {
2228 2         10 $self->{VERSION} = '';
2229 36   33     77 }
2230              
2231              
2232 2         10 $self->{VERSION_MACRO} = 'VERSION';
2233             ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
2234             $self->{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"';
2235              
2236              
2237             # Graham Barr and Paul Marquess had some ideas how to ensure
2238             # version compatibility between the *.pm file and the
2239             # corresponding *.xs file. The bottom line was, that we need an
2240             # XS_VERSION macro that defaults to VERSION:
2241             $self->{XS_VERSION} ||= $self->{VERSION};
2242              
2243             $self->{XS_VERSION_MACRO} = 'XS_VERSION';
2244             $self->{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"';
2245              
2246             }
2247              
2248              
2249             =head3 init_tools
2250              
2251             $MM->init_tools();
2252              
2253             Initializes the simple macro definitions used by tools_other() and
2254             places them in the $MM object. These use conservative cross platform
2255             versions and should be overridden with platform specific versions for
2256             performance.
2257              
2258             Defines at least these macros.
2259              
2260             Macro Description
2261              
2262             NOOP Do nothing
2263             NOECHO Tell make not to display the command itself
2264              
2265             SHELL Program used to run shell commands
2266              
2267             ECHO Print text adding a newline on the end
2268 155     155 1 429 RM_F Remove a file
2269             RM_RF Remove a directory
2270 155         702 TOUCH Update a file's timestamp
2271 155         599 TEST_F Test for a file's existence
2272 155         938 TEST_S Test the size of a file
2273 155   100     1014 CP Copy a file
2274             CP_NONEMPTY Copy a file if it is not empty
2275 155 100       509 MV Move a file
2276 94         1693 CHMOD Change permissions on a file
2277 94 50       536 FALSE Exit with non-zero
2278 0         0 TRUE Exit with zero
2279              
2280             UMASK_NULL Nullify umask
2281             DEV_NULL Suppress all command output
2282              
2283 155 100       476 =cut
2284 107 100       1189  
2285 2         12 my $self = shift;
2286 2         13  
  2         22  
2287 2 50       22 $self->{ECHO} ||= $self->oneliner('binmode STDOUT, qq{:raw}; print qq{@ARGV}', ['-l']);
2288             $self->{ECHO_N} ||= $self->oneliner('print qq{@ARGV}');
2289 107         526  
2290 107         397 $self->{TOUCH} ||= $self->oneliner('touch', ["-MExtUtils::Command"]);
2291             $self->{CHMOD} ||= $self->oneliner('chmod', ["-MExtUtils::Command"]);
2292             $self->{RM_F} ||= $self->oneliner('rm_f', ["-MExtUtils::Command"]);
2293 48         121 $self->{RM_RF} ||= $self->oneliner('rm_rf', ["-MExtUtils::Command"]);
2294             $self->{TEST_F} ||= $self->oneliner('test_f', ["-MExtUtils::Command"]);
2295             $self->{TEST_S} ||= $self->oneliner('test_s', ["-MExtUtils::Command::MM"]);
2296             $self->{CP_NONEMPTY} ||= $self->oneliner('cp_nonempty', ["-MExtUtils::Command::MM"]);
2297 155         715 $self->{FALSE} ||= $self->oneliner('exit 1');
2298 155         1145 $self->{TRUE} ||= $self->oneliner('exit 0');
2299 155         494  
2300             $self->{MKPATH} ||= $self->oneliner('mkpath', ["-MExtUtils::Command"]);
2301              
2302             $self->{CP} ||= $self->oneliner('cp', ["-MExtUtils::Command"]);
2303             $self->{MV} ||= $self->oneliner('mv', ["-MExtUtils::Command"]);
2304              
2305             $self->{MOD_INSTALL} ||=
2306 155   66     1580 $self->oneliner(<<'CODE', ['-MExtUtils::Install']);
2307             install([ from_to => {@ARGV}, verbose => '$(VERBINST)', uninstall_shadows => '$(UNINST)', dir_mode => '$(PERM_DIR)' ]);
2308 155         399 CODE
2309 155         542 $self->{DOC_INSTALL} ||= $self->oneliner('perllocal_install', ["-MExtUtils::Command::MM"]);
2310             $self->{UNINSTALL} ||= $self->oneliner('uninstall', ["-MExtUtils::Command::MM"]);
2311             $self->{WARN_IF_OLD_PACKLIST} ||=
2312             $self->oneliner('warn_if_old_packlist', ["-MExtUtils::Command::MM"]);
2313             $self->{FIXIN} ||= $self->oneliner('MY->fixin(shift)', ["-MExtUtils::MY"]);
2314             $self->{EQUALIZE_TIMESTAMP} ||= $self->oneliner('eqtime', ["-MExtUtils::Command"]);
2315              
2316             $self->{UNINST} ||= 0;
2317             $self->{VERBINST} ||= 0;
2318              
2319             $self->{SHELL} ||= $Config{sh};
2320              
2321             # UMASK_NULL is not used by MakeMaker but some CPAN modules
2322             # make use of it.
2323             $self->{UMASK_NULL} ||= "umask 0";
2324              
2325             # Not the greatest default, but its something.
2326             $self->{DEV_NULL} ||= "> /dev/null 2>&1";
2327              
2328             $self->{NOOP} ||= '$(TRUE)';
2329             $self->{NOECHO} = '@' unless defined $self->{NOECHO};
2330              
2331             $self->{FIRST_MAKEFILE} ||= $self->{MAKEFILE} || 'Makefile';
2332             $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE};
2333             $self->{MAKEFILE_OLD} ||= $self->{MAKEFILE}.'.old';
2334             $self->{MAKE_APERL_FILE} ||= $self->{MAKEFILE}.'.aperl';
2335              
2336             # Not everybody uses -f to indicate "use this Makefile instead"
2337             $self->{USEMAKEFILE} ||= '-f';
2338              
2339             # Some makes require a wrapper around macros passed in on the command
2340             # line.
2341             $self->{MACROSTART} ||= '';
2342             $self->{MACROEND} ||= '';
2343              
2344             return;
2345             }
2346              
2347              
2348             =head3 init_others
2349              
2350             $MM->init_others();
2351 156     156 1 387  
2352             Initializes the macro definitions having to do with compiling and
2353 156   33     603 linking used by tools_other() and places them in the $MM object.
2354 156   33     475  
2355             If there is no description, its the same as the parameter to
2356 156   33     422 WriteMakefile() documented in L<ExtUtils::MakeMaker>.
2357 156   33     435  
2358 156   33     396 =cut
2359 156   33     412  
2360 156   33     495 my $self = shift;
2361 156   33     529  
2362 156   33     5124 $self->{LD_RUN_PATH} = "";
2363 156   33     500  
2364 156   33     427 $self->{LIBS} = $self->_fix_libs($self->{LIBS});
2365              
2366 156   33     2394 # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
2367             foreach my $libs ( @{$self->{LIBS}} ){
2368 156   33     425 $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
2369 156   33     371 my(@libs) = $self->extliblist($libs);
2370             if ($libs[0] or $libs[1] or $libs[2]){
2371             # LD_RUN_PATH now computed by ExtUtils::Liblist
2372 156   33     5435 ($self->{EXTRALIBS}, $self->{BSLOADLIBS},
2373             $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
2374             last;
2375 156   33     1631 }
2376 156   33     1296 }
2377              
2378 156   33     1412 if ( $self->{OBJECT} ) {
2379 156   33     1727 $self->{OBJECT} = join(" ", @{$self->{OBJECT}}) if ref $self->{OBJECT};
2380 156   33     1055 $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
2381             } elsif ( ($self->{MAGICXS} || $self->{XSMULTI}) && @{$self->{O_FILES}||[]} ) {
2382 156   50     921 $self->{OBJECT} = join(" ", @{$self->{O_FILES}});
2383 156   50     1155 $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
2384             } else {
2385 156   33     1624 # init_dirscan should have found out, if we have C files
2386             $self->{OBJECT} = "";
2387             $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
2388             }
2389 156   50     1205 $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
2390              
2391             $self->{BOOTDEP} = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
2392 156   50     1022 $self->{PERLMAINCC} ||= '$(CC)';
2393             $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
2394 156   50     948  
2395 156 50       563 # Sanity check: don't define LINKTYPE = dynamic if we're skipping
2396             # the 'dynamic' section of MM. We don't have this problem with
2397 156   50     5097 # 'static', since we either must use it (%Config says we can't
      66        
2398 156   33     1764 # use dynamic loading) or the caller asked for it explicitly.
2399 156   33     1129 if (!$self->{LINKTYPE}) {
2400 156   33     1023 $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
2401             ? 'static'
2402             : ($Config{usedl} ? 'dynamic' : 'static');
2403 156   50     973 }
2404              
2405             return;
2406             }
2407 156   50     1194  
2408 156   50     730  
2409             # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
2410 156         488 # undefined. In any case we turn it into an anon array
2411             my($self, $libs) = @_;
2412              
2413             return !defined $libs ? [''] :
2414             !ref $libs ? [$libs] :
2415             !defined $libs->[0] ? [''] :
2416             $libs ;
2417             }
2418              
2419              
2420             =head3 tools_other
2421              
2422             my $make_frag = $MM->tools_other;
2423              
2424             Returns a make fragment containing definitions for the macros init_others()
2425             initializes.
2426              
2427 155     155 1 335 =cut
2428              
2429 155         948 my($self) = shift;
2430             my @m;
2431 155         1998  
2432             # We set PM_FILTER as late as possible so it can see all the earlier
2433             # on macro-order sensitive makes such as nmake.
2434 154         532 for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH
  154         783  
2435 155         485 UMASK_NULL DEV_NULL MKPATH EQUALIZE_TIMESTAMP
2436 155         2096 FALSE TRUE
2437 155 50 33     2920 ECHO ECHO_N
      33        
2438             UNINST VERBINST
2439             MOD_INSTALL DOC_INSTALL UNINSTALL
2440 0         0 WARN_IF_OLD_PACKLIST
2441 0         0 MACROSTART MACROEND
2442             USEMAKEFILE
2443             PM_FILTER
2444             FIXIN
2445 154 50 33     1990 CP_NONEMPTY
    50 33        
2446 0 0       0 } )
  0         0  
2447 0         0 {
2448 0 0       0 next unless defined $self->{$tool};
2449 0         0 push @m, "$tool = $self->{$tool}\n";
  0         0  
2450 0         0 }
2451              
2452             return join "", @m;
2453 154         509 }
2454 154 50       220  
  154 50       797  
2455              
2456 154         441 =head3 init_DIRFILESEP I<Abstract>
2457              
2458 154 50       2606 $MM->init_DIRFILESEP;
2459 154   50     1741 my $dirfilesep = $MM->{DIRFILESEP};
2460 154 50       976  
2461             Initializes the DIRFILESEP macro which is the separator between the
2462             directory and filename in a filepath. ie. / on Unix, \ on Win32 and
2463             nothing on VMS.
2464              
2465             For example:
2466 154 100       639  
2467             # instead of $(INST_ARCHAUTODIR)/extralibs.ld
2468             $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld
2469 97 50       963  
    50          
2470             Something of a hack but it prevents a lot of code duplication between
2471             MM_* variants.
2472 154         514  
2473             Do not use this as a separator between directories. Some operating
2474             systems use different separators between subdirectories as between
2475             directories and filenames (for example: VOLUME:[dir1.dir2]file on VMS).
2476              
2477             =head3 init_linker I<Abstract>
2478              
2479 163     163   4490 $mm->init_linker;
2480              
2481 163 100       1843 Initialize macros which have to do with linking.
    100          
    100          
2482              
2483             PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic
2484             extensions.
2485              
2486             PERL_ARCHIVE_AFTER: path to a library which should be put on the
2487             linker command line I<after> the external libraries to be linked to
2488             dynamic extensions. This may be needed if the linker is one-pass, and
2489             Perl includes some overrides for C RTL functions, such as malloc().
2490              
2491             EXPORT_LIST: name of a file that is passed to linker to define symbols
2492             to be exported.
2493              
2494             Some OSes do not need these in which case leave it blank.
2495              
2496              
2497             =head3 init_platform
2498 153     153 1 392  
2499 153         289 $mm->init_platform
2500              
2501             Initialize any macros which are for platform specific use only.
2502              
2503 153         875 A typical one is the version number of your OS specific module.
2504             (ie. MM_Unix_VERSION or MM_VMS_VERSION).
2505              
2506             =cut
2507              
2508             return '';
2509             }
2510              
2511              
2512             =head3 init_MAKE
2513              
2514             $mm->init_MAKE
2515              
2516             Initialize MAKE from either a MAKE environment variable or $Config{make}.
2517 4590 100       7811  
2518 4437         8659 =cut
2519              
2520             my $self = shift;
2521 153         1596  
2522             $self->{MAKE} ||= $ENV{MAKE} || $Config{make};
2523             }
2524              
2525              
2526             =head2 Tools
2527              
2528             A grab bag of methods to generate specific macros and commands.
2529              
2530              
2531              
2532             =head3 manifypods
2533              
2534             Defines targets and routines to translate the pods into manpages and
2535             put them into the INST_* directories.
2536              
2537             =cut
2538              
2539             my $self = shift;
2540              
2541             my $POD2MAN_macro = $self->POD2MAN_macro();
2542             my $manifypods_target = $self->manifypods_target();
2543              
2544             return <<END_OF_TARGET;
2545              
2546             $POD2MAN_macro
2547              
2548             $manifypods_target
2549              
2550             END_OF_TARGET
2551              
2552             }
2553              
2554              
2555             =head3 POD2MAN_macro
2556              
2557             my $pod2man_macro = $self->POD2MAN_macro
2558              
2559             Returns a definition for the POD2MAN macro. This is a program
2560             which emulates the pod2man utility. You can add more switches to the
2561             command by simply appending them on the macro.
2562              
2563             Typical usage:
2564              
2565             $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ...
2566              
2567             =cut
2568              
2569             my $self = shift;
2570              
2571             # Need the trailing '--' so perl stops gobbling arguments and - happens
2572             # to be an alternative end of line separator on VMS so we quote it
2573             return <<'END_OF_DEF';
2574             POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--"
2575             POD2MAN = $(POD2MAN_EXE)
2576             END_OF_DEF
2577             }
2578 0     0 1 0  
2579              
2580             =head3 test_via_harness
2581              
2582             my $command = $mm->test_via_harness($perl, $tests);
2583              
2584             Returns a $command line which runs the given set of $tests with
2585             Test::Harness and the given $perl.
2586              
2587             Used on the t/*.t files.
2588              
2589             =cut
2590              
2591 155     155 1 409 my($self, $perl, $tests) = @_;
2592              
2593 155   33     2449 return qq{\t$perl "-MExtUtils::Command::MM" "-MTest::Harness" }.
      33        
2594             qq{"-e" "undef *Test::Harness::Switches; test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n};
2595             }
2596              
2597             =head3 test_via_script
2598              
2599             my $command = $mm->test_via_script($perl, $script);
2600              
2601             Returns a $command line which just runs a single test without
2602             Test::Harness. No checks are done on the results, they're just
2603             printed.
2604              
2605             Used for test.pl, since they don't always follow Test::Harness
2606             formatting.
2607              
2608             =cut
2609              
2610             my($self, $perl, $script) = @_;
2611 153     153 1 353 return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n};
2612             }
2613 153         1232  
2614 153         1402  
2615             =head3 tool_autosplit
2616 153         756  
2617             Defines a simple perl call that runs autosplit. May be deprecated by
2618             pm_to_blib soon.
2619              
2620             =cut
2621              
2622             my($self, %attribs) = @_;
2623              
2624             my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};'
2625             : '';
2626              
2627             my $asplit = $self->oneliner(sprintf <<'PERL_CODE', $maxlen);
2628             use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1)
2629             PERL_CODE
2630              
2631             return sprintf <<'MAKE_FRAG', $asplit;
2632             # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
2633             AUTOSPLITFILE = %s
2634              
2635             MAKE_FRAG
2636              
2637             }
2638              
2639              
2640             =head3 arch_check
2641              
2642 153     153 1 309 my $arch_ok = $mm->arch_check(
2643             $INC{"Config.pm"},
2644             File::Spec->catfile($Config{archlibexp}, "Config.pm")
2645             );
2646 153         681  
2647             A sanity check that what Perl thinks the architecture is and what
2648             Config thinks the architecture is are the same. If they're not it
2649             will return false and show a diagnostic message.
2650              
2651             When building Perl it will always return true, as nothing is installed
2652             yet.
2653              
2654             The interface is a bit odd because this is the result of a
2655             quick refactoring. Don't rely on it.
2656              
2657             =cut
2658              
2659             my $self = shift;
2660             my($pconfig, $cconfig) = @_;
2661              
2662             return 1 if $self->{PERL_SRC};
2663              
2664             my($pvol, $pthinks) = $self->splitpath($pconfig);
2665 226     226 1 532 my($cvol, $cthinks) = $self->splitpath($cconfig);
2666              
2667 226         1213 $pthinks = $self->canonpath($pthinks);
2668             $cthinks = $self->canonpath($cthinks);
2669              
2670             my $ret = 1;
2671             if ($pthinks ne $cthinks) {
2672             print "Have $pthinks\n";
2673             print "Want $cthinks\n";
2674              
2675             $ret = 0;
2676              
2677             my $arch = (grep length, $self->splitdir($pthinks))[-1];
2678              
2679             print <<END unless $self->{UNINSTALLED_PERL};
2680             Your perl and your Config.pm seem to have different ideas about the
2681             architecture they are running on.
2682             Perl thinks: [$arch]
2683             Config says: [$Config{archname}]
2684             This may or may not cause problems. Please check your installation of perl
2685 338     338 1 785 if you have problems building this extension.
2686 338         1202 END
2687             }
2688              
2689             return $ret;
2690             }
2691              
2692              
2693              
2694             =head2 File::Spec wrappers
2695              
2696             ExtUtils::MM_Any is a subclass of L<File::Spec>. The methods noted here
2697             override File::Spec.
2698 153     153 1 381  
2699              
2700 153 50       831  
2701             =head3 catfile
2702              
2703 153         1168 File::Spec <= 0.83 has a bug where the file part of catfile is not
2704             canonicalized. This override fixes that bug.
2705              
2706             =cut
2707 153         1054  
2708             my $self = shift;
2709             return $self->canonpath($self->SUPER::catfile(@_));
2710             }
2711              
2712              
2713              
2714             =head2 Misc
2715              
2716             Methods I can't really figure out where they should go yet.
2717              
2718              
2719             =head3 find_tests
2720              
2721             my $test = $mm->find_tests;
2722              
2723             Returns a string suitable for feeding to the shell to return all
2724             tests in t/*.t.
2725              
2726             =cut
2727              
2728             my($self) = shift;
2729             return -d 't' ? 't/*.t' : '';
2730             }
2731              
2732             =head3 find_tests_recursive
2733              
2734             my $tests = $mm->find_tests_recursive;
2735              
2736 159     159 1 432 Returns a string suitable for feeding to the shell to return all
2737 159         772 tests in t/ but recursively. Equivalent to
2738              
2739 159 100       617 my $tests = $mm->find_tests_recursive_in('t');
2740              
2741 158         5253 =cut
2742 158         1923  
2743             my $self = shift;
2744 158         700 return $self->find_tests_recursive_in('t');
2745 158         554 }
2746              
2747 158         296 =head3 find_tests_recursive_in
2748 158 100       461  
2749 2         15 my $tests = $mm->find_tests_recursive_in($dir);
2750 2         19  
2751             Returns a string suitable for feeding to the shell to return all
2752 2         11 tests in $dir recursively.
2753              
2754 2         27 =cut
2755              
2756 2 100       14 my($self, $dir) = @_;
2757             return '' unless -d $dir;
2758              
2759             require File::Find;
2760              
2761             my $base_depth = grep { $_ ne '' } File::Spec->splitdir( (File::Spec->splitpath($dir))[1] );
2762             my %depths;
2763              
2764             my $wanted = sub {
2765             return unless m!\.t$!;
2766 158         820 my ($volume,$directories,$file) =
2767             File::Spec->splitpath( $File::Find::name );
2768             my $depth = grep { $_ ne '' } File::Spec->splitdir( $directories );
2769             $depth -= $base_depth;
2770             $depths{ $depth } = 1;
2771             };
2772              
2773             File::Find::find( $wanted, $dir );
2774              
2775             return join ' ',
2776             map { $dir . '/*' x $_ . '.t' }
2777             sort { $a <=> $b }
2778             keys %depths;
2779             }
2780              
2781             =head3 extra_clean_files
2782              
2783             my @files_to_clean = $MM->extra_clean_files;
2784              
2785             Returns a list of OS specific files to be removed in the clean target in
2786 3780     3780 1 10149 addition to the usual set.
2787 3780         57366  
2788             =cut
2789              
2790             # An empty method here tickled a perl 5.8.1 bug and would return its object.
2791             return;
2792             }
2793              
2794              
2795             =head3 installvars
2796              
2797             my @installvars = $mm->installvars;
2798              
2799             A list of all the INSTALL* variables without the INSTALL prefix. Useful
2800             for iteration or building related variable sets.
2801              
2802             =cut
2803              
2804             return qw(PRIVLIB SITELIB VENDORLIB
2805             ARCHLIB SITEARCH VENDORARCH
2806             BIN SITEBIN VENDORBIN
2807 113     113 1 331 SCRIPT SITESCRIPT VENDORSCRIPT
2808 113 50       1341 MAN1DIR SITEMAN1DIR VENDORMAN1DIR
2809             MAN3DIR SITEMAN3DIR VENDORMAN3DIR
2810             );
2811             }
2812              
2813              
2814             =head3 libscan
2815              
2816             my $wanted = $self->libscan($path);
2817              
2818             Takes a path to a file or dir and returns an empty string if we don't
2819             want to include this file in the library. Otherwise it returns the
2820             the $path unchanged.
2821              
2822             Mainly used to exclude version control administrative directories
2823 0     0 1 0 and base-level F<README.pod> from installation.
2824 0         0  
2825             =cut
2826              
2827             my($self,$path) = @_;
2828              
2829             if ($path =~ m<^README\.pod$>i) {
2830             warn "WARNING: Older versions of ExtUtils::MakeMaker may errantly install $path as part of this distribution. It is recommended to avoid using this path in CPAN modules.\n";
2831             return '';
2832             }
2833              
2834             my($dirs,$file) = ($self->splitpath($path))[1,2];
2835             return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/,
2836             $self->splitdir($dirs), $file;
2837 0     0 1 0  
2838 0 0       0 return $path;
2839             }
2840 0         0  
2841              
2842 0         0 =head3 platform_constants
  0         0  
2843 0         0  
2844             my $make_frag = $mm->platform_constants
2845              
2846 0 0   0   0 Returns a make fragment defining all the macros initialized in
2847 0         0 init_platform() rather than put them in constants().
2848              
2849 0         0 =cut
  0         0  
2850 0         0  
2851 0         0 return '';
2852 0         0 }
2853              
2854 0         0 =head3 post_constants (o)
2855              
2856             Returns an empty string per default. Dedicated to overrides from
2857 0         0 within Makefile.PL after all constants have been defined.
2858 0         0  
  0         0  
2859             =cut
2860              
2861             "";
2862             }
2863              
2864             =head3 post_initialize (o)
2865              
2866             Returns an empty string per default. Used in Makefile.PLs to add some
2867             chunk of text to the Makefile after the object is initialized.
2868              
2869             =cut
2870              
2871             "";
2872             }
2873 153     153 1 342  
2874             =head3 postamble (o)
2875              
2876             Returns an empty string. Can be used in Makefile.PLs to write some
2877             text to the Makefile at the end.
2878              
2879             =cut
2880              
2881             "";
2882             }
2883              
2884             =begin private
2885              
2886             =head3 _PREREQ_PRINT
2887 309     309 1 2903  
2888             $self->_PREREQ_PRINT;
2889              
2890             Implements PREREQ_PRINT.
2891              
2892             Refactored out of MakeMaker->new().
2893              
2894             =end private
2895              
2896             =cut
2897              
2898             my $self = shift;
2899              
2900             require Data::Dumper;
2901             my @what = ('PREREQ_PM');
2902             push @what, 'MIN_PERL_VERSION' if $self->{MIN_PERL_VERSION};
2903             push @what, 'BUILD_REQUIRES' if $self->{BUILD_REQUIRES};
2904             print Data::Dumper->Dump([@{$self}{@what}], \@what);
2905             exit 0;
2906             }
2907              
2908              
2909             =begin private
2910              
2911 1022     1022 1 2330 =head3 _PRINT_PREREQ
2912              
2913 1022 100       2212 $mm->_PRINT_PREREQ;
2914 6         47  
2915 6         46 Implements PRINT_PREREQ, a slightly different version of PREREQ_PRINT
2916             added by Redhat to, I think, support generating RPMs from Perl modules.
2917              
2918 1016         11933 Should not include BUILD_REQUIRES as RPMs do not include them.
2919 1016 100       7203  
2920             Refactored out of MakeMaker->new().
2921              
2922 1012         2913 =end private
2923              
2924             =cut
2925              
2926             my $self = shift;
2927              
2928             my $prereqs= $self->{PREREQ_PM};
2929             my @prereq = map { [$_, $prereqs->{$_}] } keys %$prereqs;
2930              
2931             if ( $self->{MIN_PERL_VERSION} ) {
2932             push @prereq, ['perl' => $self->{MIN_PERL_VERSION}];
2933             }
2934              
2935             print join(" ", map { "perl($_->[0])>=$_->[1] " }
2936 0     0 1 0 sort { $a->[0] cmp $b->[0] } @prereq), "\n";
2937             exit 0;
2938             }
2939              
2940              
2941             =begin private
2942              
2943             =head3 _perl_header_files
2944              
2945             my $perl_header_files= $self->_perl_header_files;
2946              
2947 154     154 1 525 returns a sorted list of header files as found in PERL_SRC or $archlibexp/CORE.
2948              
2949             Used by perldepend() in MM_Unix and MM_VMS via _perl_header_files_fragment()
2950              
2951             =end private
2952              
2953             =cut
2954              
2955             my $self = shift;
2956              
2957             my $header_dir = $self->{PERL_SRC} || $ENV{PERL_SRC} || $self->catdir($Config{archlibexp}, 'CORE');
2958 155     155 1 2190 opendir my $dh, $header_dir
2959             or die "Failed to opendir '$header_dir' to find header files: $!";
2960              
2961             # we need to use a temporary here as the sort in scalar context would have undefined results.
2962             my @perl_headers= sort grep { /\.h\z/ } readdir($dh);
2963              
2964             closedir $dh;
2965              
2966             return @perl_headers;
2967             }
2968              
2969 153     153 1 825 =begin private
2970              
2971             =head3 _perl_header_files_fragment ($o, $separator)
2972              
2973             my $perl_header_files_fragment= $self->_perl_header_files_fragment("/");
2974              
2975             return a Makefile fragment which holds the list of perl header files which
2976             XS code depends on $(PERL_INC), and sets up the dependency for the $(OBJECT) file.
2977              
2978             The $separator argument defaults to "". MM_VMS will set it to "" and MM_UNIX to "/"
2979             in perldepend(). This reason child subclasses need to control this is that in
2980             VMS the $(PERL_INC) directory will already have delimiters in it, but in
2981             UNIX $(PERL_INC) will need a slash between it an the filename. Hypothetically
2982             win32 could use "\\" (but it doesn't need to).
2983              
2984             =end private
2985              
2986             =cut
2987 0     0      
2988             my ($self, $separator)= @_;
2989 0           $separator ||= "";
2990 0           return join("\\\n",
2991 0 0         "PERL_HDRS = ",
2992 0 0         map {
2993 0           sprintf( " \$(PERL_INCDEP)%s%s ", $separator, $_ )
  0            
2994 0           } $self->_perl_header_files()
2995             ) . "\n\n"
2996             . "\$(OBJECT) : \$(PERL_HDRS)\n";
2997             }
2998              
2999              
3000             =head1 AUTHOR
3001              
3002             Michael G Schwern <schwern@pobox.com> and the denizens of
3003             makemaker@perl.org with code from ExtUtils::MM_Unix and
3004             ExtUtils::MM_Win32.
3005              
3006              
3007             =cut
3008              
3009             1;