1 package ExtUtils::MM_Any;
4 our $VERSION = '7.10_01';
9 BEGIN { our @ISA = qw(File::Spec); }
12 use ExtUtils::MakeMaker qw($Verbose);
14 use ExtUtils::MakeMaker::Config;
17 # So we don't have to keep calling the methods over and over again,
18 # we have these globals to cache the values. Faster and shrtr.
19 my $Curdir = __PACKAGE__->curdir;
20 my $Rootdir = __PACKAGE__->rootdir;
21 my $Updir = __PACKAGE__->updir;
26 ExtUtils::MM_Any - Platform-agnostic MM methods
30 FOR INTERNAL USE ONLY!
32 package ExtUtils::MM_SomeOS;
34 # Temporarily, you have to subclass both. Put MM_Any first.
35 require ExtUtils::MM_Any;
36 require ExtUtils::MM_Unix;
37 @ISA = qw(ExtUtils::MM_Any ExtUtils::Unix);
41 B<FOR INTERNAL USE ONLY!>
43 ExtUtils::MM_Any is a superclass for the ExtUtils::MM_* set of
44 modules. It contains methods which are either inherently
45 cross-platform or are written in a cross-platform manner.
47 Subclass off of ExtUtils::MM_Any I<and> ExtUtils::MM_Unix. This is a
50 B<THIS MAY BE TEMPORARY!>
55 Any methods marked I<Abstract> must be implemented by subclasses.
58 =head2 Cross-platform helper methods
60 These are methods which help writing cross-platform code.
64 =head3 os_flavor I<Abstract>
66 my @os_flavor = $mm->os_flavor;
68 @os_flavor is the style of operating system this is, usually
69 corresponding to the MM_*.pm file we're using.
71 The first element of @os_flavor is the major family (ie. Unix,
72 Windows, VMS, OS/2, etc...) and the rest are sub families.
76 Cygwin98 ('Unix', 'Cygwin', 'Cygwin9x')
78 Win98 ('Win32', 'Win9x')
79 Linux ('Unix', 'Linux')
80 MacOS X ('Unix', 'Darwin', 'MacOS', 'MacOS X')
83 This is used to write code for styles of operating system.
84 See os_flavor_is() for use.
89 my $is_this_flavor = $mm->os_flavor_is($this_flavor);
90 my $is_this_flavor = $mm->os_flavor_is(@one_of_these_flavors);
92 Checks to see if the current operating system is one of the given flavors.
94 This is useful for code like:
96 if( $mm->os_flavor_is('Unix') ) {
107 my %flavors = map { ($_ => 1) } $self->os_flavor;
108 return (grep { $flavors{$_} } @_) ? 1 : 0;
114 my $can_load_xs = $self->can_load_xs;
116 Returns true if we have the ability to load XS.
118 This is important because miniperl, used to build XS modules in the
119 core, can not load XS.
124 return defined &DynaLoader::boot_DynaLoader ? 1 : 0;
131 my $runnable = MM->can_run($Config{make});
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.
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.
139 Copied from L<IPC::Cmd|IPC::Cmd/"$path = can_run( PROGRAM );">, but modified into
140 a method (and removed C<$INSTANCES> capability).
145 my ($self, $command) = @_;
147 # a lot of VMS executables have a symbol defined
149 if ( $^O eq 'VMS' ) {
151 my $syms = VMS::DCLsym->new;
152 return $command if scalar $syms->getsym( uc $command );
157 if( File::Spec->file_name_is_absolute($command) ) {
158 return $self->maybe_command($command);
165 next if ! $dir || ! -d $dir;
166 my $abs = File::Spec->catfile($self->os_flavor_is('Win32') ? Win32::GetShortPathName( $dir ) : $dir, $command);
167 push @possibles, $abs if $abs = $self->maybe_command($abs);
170 return @possibles if wantarray;
171 return shift @possibles;
175 =head3 can_redirect_error
177 $useredirect = MM->can_redirect_error;
179 True if on an OS where qx operator (or backticks) can redirect C<STDERR>
184 sub can_redirect_error {
186 $self->os_flavor_is('Unix')
187 or ($self->os_flavor_is('Win32') and !$self->os_flavor_is('Win9x'))
188 or $self->os_flavor_is('OS/2')
194 my $is_dmake = $self->is_make_type('dmake');
196 Returns true if C<<$self->make>> is the given type; possibilities are:
201 bsdmake BSD pmake-derived
206 # undocumented - so t/cd.t can still do its thing
207 sub _clear_maketype_cache { %maketype2true = () }
210 my($self, $type) = @_;
211 return $maketype2true{$type} if defined $maketype2true{$type};
212 (undef, undef, my $make_basename) = $self->splitpath($self->make);
213 return $maketype2true{$type} = 1
214 if $make_basename =~ /\b$type\b/i; # executable's filename
215 return $maketype2true{$type} = 0
216 if $make_basename =~ /\b[gdn]make\b/i; # Never fall through for dmake/nmake/gmake
217 # now have to run with "-v" and guess
218 my $redirect = $self->can_redirect_error ? '2>&1' : '';
219 my $make = $self->make || $self->{MAKE};
220 my $minus_v = `"$make" -v $redirect`;
221 return $maketype2true{$type} = 1
222 if $type eq 'gmake' and $minus_v =~ /GNU make/i;
223 return $maketype2true{$type} = 1
224 if $type eq 'bsdmake'
225 and $minus_v =~ /^usage: make \[-BeikNnqrstWwX\]/im;
226 $maketype2true{$type} = 0; # it wasn't whatever you asked
232 my $can_dep_space = $self->can_dep_space;
234 Returns true if C<make> can handle (probably by quoting)
235 dependencies that contain a space. Currently known true for GNU make,
236 false for BSD pmake derivative.
240 my $cached_dep_space;
243 return $cached_dep_space if defined $cached_dep_space;
244 return $cached_dep_space = 1 if $self->is_make_type('gmake');
245 return $cached_dep_space = 0 if $self->is_make_type('dmake'); # only on W32
246 return $cached_dep_space = 0 if $self->is_make_type('bsdmake');
247 return $cached_dep_space = 0; # assume no
253 $text = $mm->quote_dep($text);
255 Method that protects Makefile single-value constants (mainly filenames),
256 so that make will still treat them as single values even if they
257 inconveniently have spaces in. If the make program being used cannot
258 achieve such protection and the given text would need it, throws an
264 my ($self, $arg) = @_;
265 die <<EOF if $arg =~ / / and not $self->can_dep_space;
266 Tried to use make dependency with space for make that can't:
269 $arg =~ s/( )/\\$1/g; # how GNU make does it
276 my @cmds = $MM->split_command($cmd, @args);
278 Most OS have a maximum command length they can execute at once. Large
279 modules can easily generate commands well past that limit. Its
280 necessary to split long commands up into a series of shorter commands.
282 C<split_command> will return a series of @cmds each processing part of
283 the args. Collectively they will process all the arguments. Each
284 individual line in @cmds will not be longer than the
285 $self->max_exec_len being careful to take into account macro expansion.
287 $cmd should include any switches and repeated initial arguments.
289 If no @args are given, no @cmds will be returned.
291 Pairs of arguments will always be preserved in a single command, this
292 is a heuristic for things like pm_to_blib and pod2man which work on
293 pairs of arguments. This makes things like this safe:
295 $self->split_command($cmd, %pod2man);
301 my($self, $cmd, @args) = @_;
304 return(@cmds) unless @args;
306 # If the command was given as a here-doc, there's probably a trailing
310 # set aside 30% for macro expansion.
311 my $len_left = int($self->max_exec_len * 0.70);
312 $len_left -= length $self->_expand_macros($cmd);
317 while( @next_args = splice(@args, 0, 2) ) {
318 # Two at a time to preserve pairs.
319 my $next_arg_str = "\t ". join ' ', @next_args, "\n";
321 if( !length $arg_str ) {
322 $arg_str .= $next_arg_str
324 elsif( length($arg_str) + length($next_arg_str) > $len_left ) {
325 unshift @args, @next_args;
329 $arg_str .= $next_arg_str;
334 push @cmds, $self->escape_newlines("$cmd \n$arg_str");
342 my($self, $cmd) = @_;
344 $cmd =~ s{\$\((\w+)\)}{
345 defined $self->{$1} ? $self->{$1} : "\$($1)"
353 my @commands = $MM->echo($text);
354 my @commands = $MM->echo($text, $file);
355 my @commands = $MM->echo($text, $file, \%opts);
357 Generates a set of @commands which print the $text to a $file.
359 If $file is not given, output goes to STDOUT.
361 If $opts{append} is true the $file will be appended to rather than
362 overwritten. Default is to overwrite.
364 If $opts{allow_variables} is true, make variables of the form
365 C<$(...)> will not be escaped. Other C<$> will. Default is to escape
370 my $make = map "\t$_\n", $MM->echo($text, $file);
375 my($self, $text, $file, $opts) = @_;
377 # Compatibility with old options
380 $opts = { append => $append || 0 };
382 $opts->{allow_variables} = 0 unless defined $opts->{allow_variables};
384 my $ql_opts = { allow_variables => $opts->{allow_variables} };
385 my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_, $ql_opts) }
388 my $redirect = $opts->{append} ? '>>' : '>';
389 $cmds[0] .= " $redirect $file";
390 $_ .= " >> $file" foreach @cmds[1..$#cmds];
399 my $args = $mm->wraplist(@list);
401 Takes an array of items and turns them into a well-formatted list of
402 arguments. In most cases this is simply something like:
412 return join " \\\n\t", @_;
416 =head3 maketext_filter
418 my $filter_make_text = $mm->maketext_filter($make_text);
420 The text of the Makefile is run through this method before writing to
421 disk. It allows systems a chance to make portability fixes to the
424 By default it does nothing.
426 This method is protected and not intended to be called outside of
431 sub maketext_filter { return $_[1] }
434 =head3 cd I<Abstract>
436 my $subdir_cmd = $MM->cd($subdir, @cmds);
438 This will generate a make fragment which runs the @cmds in the given
439 $dir. The rough equivalent to this, except cross platform.
443 Currently $dir can only go down one level. "foo" is fine. "foo/bar" is
444 not. "../foo" is right out.
446 The resulting $subdir_cmd has no leading tab nor trailing newline. This
447 makes it easier to embed in a make string. For example.
449 my $make = sprintf <<'CODE', $subdir_cmd;
457 =head3 oneliner I<Abstract>
459 my $oneliner = $MM->oneliner($perl_code);
460 my $oneliner = $MM->oneliner($perl_code, \@switches);
462 This will generate a perl one-liner safe for the particular platform
463 you're on based on the given $perl_code and @switches (a -e is
464 assumed) suitable for using in a make target. It will use the proper
465 shell quoting and escapes.
467 $(PERLRUN) will be used as perl.
469 Any newlines in $perl_code will be escaped. Leading and trailing
470 newlines will be stripped. Makes this idiom much easier:
472 my $code = $MM->oneliner(<<'CODE', [...switches...]);
477 Usage might be something like:
480 $oneliner = $MM->oneliner('print "Foo\n"');
481 $make = '$oneliner > somefile';
483 All dollar signs must be doubled in the $perl_code if you expect them
484 to be interpreted normally, otherwise it will be considered a make
485 macro. Also remember to quote make macros else it might be used as a
486 bareword. For example:
488 # Assign the value of the $(VERSION_FROM) make macro to $vf.
489 $oneliner = $MM->oneliner('$$vf = "$(VERSION_FROM)"');
491 Its currently very simple and may be expanded sometime in the figure
492 to include more flexible code and switches.
495 =head3 quote_literal I<Abstract>
497 my $safe_text = $MM->quote_literal($text);
498 my $safe_text = $MM->quote_literal($text, \%options);
500 This will quote $text so it is interpreted literally in the shell.
502 For example, on Unix this would escape any single-quotes in $text and
503 put single-quotes around the whole thing.
505 If $options{allow_variables} is true it will leave C<'$(FOO)'> make
506 variables untouched. If false they will be escaped like any other
507 C<$>. Defaults to true.
509 =head3 escape_dollarsigns
511 my $escaped_text = $MM->escape_dollarsigns($text);
513 Escapes stray C<$> so they are not interpreted as make variables.
515 It lets by C<$(...)>.
519 sub escape_dollarsigns {
520 my($self, $text) = @_;
522 # Escape dollar signs which are not starting a variable
523 $text =~ s{\$ (?!\() }{\$\$}gx;
529 =head3 escape_all_dollarsigns
531 my $escaped_text = $MM->escape_all_dollarsigns($text);
533 Escapes all C<$> so they are not interpreted as make variables.
537 sub escape_all_dollarsigns {
538 my($self, $text) = @_;
540 # Escape dollar signs
541 $text =~ s{\$}{\$\$}gx;
547 =head3 escape_newlines I<Abstract>
549 my $escaped_text = $MM->escape_newlines($text);
551 Shell escapes newlines in $text.
554 =head3 max_exec_len I<Abstract>
556 my $max_exec_len = $MM->max_exec_len;
558 Calculates the maximum command size the OS can exec. Effectively,
559 this is the max size of a shell command line.
562 $self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes.
567 my $make = $MM->make;
569 Returns the make variant we're generating the Makefile for. This attempts
570 to do some normalization on the information from %Config or the user.
577 my $make = lc $self->{MAKE};
579 # Truncate anything like foomake6 to just foomake.
580 $make =~ s/^(\w+make).*/$1/;
582 # Turn gnumake into gmake.
591 These are methods which produce make targets.
596 Generate the default target 'all'.
611 =head3 blibdirs_target
613 my $make_frag = $mm->blibdirs_target;
615 Creates the blibdirs target which creates all the directories we use
618 The blibdirs.ts target is deprecated. Depend on blibdirs instead.
623 sub blibdirs_target {
626 my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib
632 my @exists = map { $_.'$(DFSEP).exists' } @dirs;
634 my $make = sprintf <<'MAKE', join(' ', @exists);
638 # Backwards compat with 6.18 through 6.25
639 blibdirs.ts : blibdirs
644 $make .= $self->dir_target(@dirs);
652 Defines the clean target.
657 # --- Cleanup and Distribution Sections ---
659 my($self, %attribs) = @_;
662 # Delete temporary files but do not touch installed files. We don\'t delete
663 # the Makefile here so a later make realclean still has a makefile to use.
665 clean :: clean_subdirs
668 my @files = sort values %{$self->{XS}}; # .c files from *.xs files
671 # Normally these are all under blib but they might have been
673 # XXX normally this would be a good idea, but the Perl core sets
674 # INST_LIB = ../../lib rather than actually installing the files.
675 # So a "make clean" in an ext/ directory would blow away lib.
676 # Until the core is adjusted let's leave this out.
677 # push @dirs, qw($(INST_ARCHLIB) $(INST_LIB)
678 # $(INST_BIN) $(INST_SCRIPT)
679 # $(INST_MAN1DIR) $(INST_MAN3DIR)
680 # $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR)
681 # $(INST_STATIC) $(INST_DYNAMIC)
685 if( $attribs{FILES} ) {
686 # Use @dirs because we don't know what's in here.
687 push @dirs, ref $attribs{FILES} ?
689 split /\s+/, $attribs{FILES} ;
692 push(@files, qw[$(MAKE_APERL_FILE)
693 MYMETA.json MYMETA.yml perlmain.c tmon.out mon.out so_locations
694 blibdirs.ts pm_to_blib pm_to_blib.ts
695 *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
696 $(BOOTSTRAP) $(BASEEXT).bso
697 $(BASEEXT).def lib$(BASEEXT).def
698 $(BASEEXT).exp $(BASEEXT).x
701 push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
702 push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld'));
706 push(@files, qw[perl*.kp]);
709 push(@files, qw[core core.*perl.*.? *perl.core]);
712 push(@files, map { "core." . "[0-9]"x$_ } (1..5));
714 # OS specific things to clean up. Use @dirs since we don't know
715 # what might be in here.
716 push @dirs, $self->extra_clean_files;
718 # Occasionally files are repeated several times from different sources
719 { my(%f) = map { ($_ => 1) } @files; @files = sort keys %f; }
720 { my(%d) = map { ($_ => 1) } @dirs; @dirs = sort keys %d; }
722 push @m, map "\t$_\n", $self->split_command('- $(RM_F)', @files);
723 push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs);
725 # Leave Makefile.old around for realclean
727 $(NOECHO) $(RM_F) $(MAKEFILE_OLD)
728 - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL)
731 push(@m, "\t$attribs{POSTOP}\n") if $attribs{POSTOP};
737 =head3 clean_subdirs_target
739 my $make_frag = $MM->clean_subdirs_target;
741 Returns the clean_subdirs target. This is used by the clean target to
742 call clean on any subdirectories which contain Makefiles.
746 sub clean_subdirs_target {
749 # No subdirectories, no cleaning.
750 return <<'NOOP_FRAG' unless @{$self->{DIR}};
756 my $clean = "clean_subdirs :\n";
758 for my $dir (@{$self->{DIR}}) {
759 my $subclean = $self->oneliner(sprintf <<'CODE', $dir);
760 exit 0 unless chdir '%s'; system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)';
763 $clean .= "\t$subclean\n";
772 my $make_frag = $mm->dir_target(@directories);
774 Generates targets to create the specified directories and set its
775 permission to PERM_DIR.
777 Because depending on a directory to just ensure it exists doesn't work
778 too well (the modified time changes too often) dir_target() creates a
779 .exists file in the created directory. It is this you should depend on.
780 For portability purposes you should use the $(DIRFILESEP) macro rather
781 than a '/' to separate the directory from the file.
783 yourdirectory$(DIRFILESEP).exists
788 my($self, @dirs) = @_;
791 foreach my $dir (@dirs) {
792 $make .= sprintf <<'MAKE', ($dir) x 4;
793 %s$(DFSEP).exists :: Makefile.PL
794 $(NOECHO) $(MKPATH) %s
795 $(NOECHO) $(CHMOD) $(PERM_DIR) %s
796 $(NOECHO) $(TOUCH) %s$(DFSEP).exists
808 Defines the scratch directory target that will hold the distribution
809 before tar-ing (or shar-ing).
813 # For backwards compatibility.
814 *dist_dir = *distdir;
819 my $meta_target = $self->{NO_META} ? '' : 'distmeta';
820 my $sign_target = !$self->{SIGN} ? '' : 'distsignature';
822 return sprintf <<'MAKE_FRAG', $meta_target, $sign_target;
824 $(RM_RF) $(DISTVNAME)
825 $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
826 -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
828 distdir : create_distdir %s %s
838 Defines a target that produces the distribution in the
839 scratch directory, and runs 'perl Makefile.PL; make ;make test' in that
847 my $mpl_args = join " ", map qq["$_"], @ARGV;
849 my $test = $self->cd('$(DISTVNAME)',
850 '$(ABSPERLRUN) Makefile.PL '.$mpl_args,
851 '$(MAKE) $(PASTHRU)',
852 '$(MAKE) test $(PASTHRU)'
855 return sprintf <<'MAKE_FRAG', $test;
867 Defines the dynamic target.
872 # --- Dynamic Loading Sections ---
876 dynamic :: $(FIRST_MAKEFILE) $(BOOTSTRAP) $(INST_DYNAMIC)
882 =head3 makemakerdflt_target
884 my $make_frag = $mm->makemakerdflt_target
886 Returns a make fragment with the makemakerdeflt_target specified.
887 This target is the first target in the Makefile, is the default target
888 and simply points off to 'all' just in case any make variant gets
889 confused or something gets snuck in before the real 'all' target.
893 sub makemakerdflt_target {
894 return <<'MAKE_FRAG';
902 =head3 manifypods_target
904 my $manifypods_target = $self->manifypods_target;
906 Generates the manifypods target. This target generates man pages from
907 all POD files in MAN1PODS and MAN3PODS.
911 sub manifypods_target {
916 my $dependencies = '';
918 # populate manXpods & dependencies:
919 foreach my $name (sort keys %{$self->{MAN1PODS}}, sort keys %{$self->{MAN3PODS}}) {
920 $dependencies .= " \\\n\t$name";
924 manifypods : pure_all $dependencies
928 foreach my $section (qw(1 3)) {
929 my $pods = $self->{"MAN${section}PODS"};
930 my $p2m = sprintf <<CMD, $] > 5.008 ? " -u" : "";
931 \$(NOECHO) \$(POD2MAN) --section=$section --perm_rw=\$(PERM_RW)%s
933 push @man_cmds, $self->split_command($p2m, map {($_,$pods->{$_})} sort keys %$pods);
936 $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds;
937 $manify .= join '', map { "$_\n" } @man_cmds;
945 CPAN::Meta->VERSION(2.112150);
950 =head3 metafile_target
952 my $target = $mm->metafile_target;
954 Generate the metafile target.
956 Writes the file META.yml (YAML encoded meta-data) and META.json
957 (JSON encoded meta-data) about the module in the distdir.
958 The format follows Module::Build's as closely as possible.
962 sub metafile_target {
964 return <<'MAKE_FRAG' if $self->{NO_META} or ! _has_cpan_meta();
969 my %metadata = $self->metafile_data(
970 $self->{META_ADD} || {},
971 $self->{META_MERGE} || {},
974 _fix_metadata_before_conversion( \%metadata );
976 # paper over validation issues, but still complain, necessary because
977 # there's no guarantee that the above will fix ALL errors
978 my $meta = eval { CPAN::Meta->create( \%metadata, { lazy_validation => 1 } ) };
980 $@ !~ /encountered CODE.*, but JSON can only represent references to arrays or hashes/;
982 # use the original metadata straight if the conversion failed
983 # or if it can't be stringified.
985 !eval { $meta->as_string( { version => "1.4" } ) } ||
986 !eval { $meta->as_string }
989 $meta = bless \%metadata, 'CPAN::Meta';
992 my @write_metayml = $self->echo(
993 $meta->as_string({version => "1.4"}), 'META_new.yml'
995 my @write_metajson = $self->echo(
996 $meta->as_string(), 'META_new.json'
999 my $metayml = join("\n\t", @write_metayml);
1000 my $metajson = join("\n\t", @write_metajson);
1001 return sprintf <<'MAKE_FRAG', $metayml, $metajson;
1002 metafile : create_distdir
1003 $(NOECHO) $(ECHO) Generating META.yml
1005 -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml
1006 $(NOECHO) $(ECHO) Generating META.json
1008 -$(NOECHO) $(MV) META_new.json $(DISTVNAME)/META.json
1015 =head3 _fix_metadata_before_conversion
1017 _fix_metadata_before_conversion( \%metadata );
1019 Fixes errors in the metadata before it's handed off to CPAN::Meta for
1020 conversion. This hopefully results in something that can be used further
1021 on, no guarantee is made though.
1027 sub _fix_metadata_before_conversion {
1028 my ( $metadata ) = @_;
1030 # we should never be called unless this already passed but
1031 # prefer to be defensive in case somebody else calls this
1033 return unless _has_cpan_meta;
1035 my $bad_version = $metadata->{version} &&
1036 !CPAN::Meta::Validator->new->version( 'version', $metadata->{version} );
1038 # just delete all invalid versions
1039 if( $bad_version ) {
1040 warn "Can't parse version '$metadata->{version}'\n";
1041 $metadata->{version} = '';
1044 my $validator = CPAN::Meta::Validator->new( $metadata );
1045 return if $validator->is_valid;
1047 # fix non-camelcase custom resource keys (only other trick we know)
1048 for my $error ( $validator->errors ) {
1049 my ( $key ) = ( $error =~ /Custom resource '(.*)' must be in CamelCase./ );
1052 # first try to remove all non-alphabetic chars
1053 ( my $new_key = $key ) =~ s/[^_a-zA-Z]//g;
1055 # if that doesn't work, uppercase first one
1056 $new_key = ucfirst $new_key if !$validator->custom_1( $new_key );
1058 # copy to new key if that worked
1059 $metadata->{resources}{$new_key} = $metadata->{resources}{$key}
1060 if $validator->custom_1( $new_key );
1062 # and delete old one in any case
1063 delete $metadata->{resources}{$key};
1074 my @pairs = _sort_pairs($sort_sub, \%hash);
1076 Sorts the pairs of a hash based on keys ordered according
1086 return map { $_ => $pairs->{$_} }
1092 # Taken from Module::Build::Base
1094 my ($self, $h, $k, $v) = @_;
1095 if (ref $h->{$k} eq 'ARRAY') {
1096 push @{$h->{$k}}, ref $v ? @$v : $v;
1097 } elsif (ref $h->{$k} eq 'HASH') {
1098 $self->_hash_merge($h->{$k}, $_, $v->{$_}) foreach keys %$v;
1105 =head3 metafile_data
1107 my @metadata_pairs = $mm->metafile_data(\%meta_add, \%meta_merge);
1109 Returns the data which MakeMaker turns into the META.yml file
1110 and the META.json file.
1112 Values of %meta_add will overwrite any existing metadata in those
1113 keys. %meta_merge will be merged with them.
1119 my($meta_add, $meta_merge) = @_;
1123 name => $self->{DISTNAME},
1124 version => _normalize_version($self->{VERSION}),
1125 abstract => $self->{ABSTRACT} || 'unknown',
1126 license => $self->{LICENSE} || 'unknown',
1127 dynamic_config => 1,
1130 distribution_type => $self->{PM} ? 'module' : 'script',
1133 directory => [qw(t inc)]
1136 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
1138 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
1143 # The author key is required and it takes a list.
1144 $meta{author} = defined $self->{AUTHOR} ? $self->{AUTHOR} : [];
1147 my $vers = _metaspec_version( $meta_add, $meta_merge );
1148 my $method = $vers =~ m!^2!
1149 ? '_add_requirements_to_meta_v2'
1150 : '_add_requirements_to_meta_v1_4';
1151 %meta = $self->$method( %meta );
1154 while( my($key, $val) = each %$meta_add ) {
1158 while( my($key, $val) = each %$meta_merge ) {
1159 $self->_hash_merge(\%meta, $key, $val);
1170 sub _metaspec_version {
1171 my ( $meta_add, $meta_merge ) = @_;
1172 return $meta_add->{'meta-spec'}->{version}
1173 if defined $meta_add->{'meta-spec'}
1174 and defined $meta_add->{'meta-spec'}->{version};
1175 return $meta_merge->{'meta-spec'}->{version}
1176 if defined $meta_merge->{'meta-spec'}
1177 and defined $meta_merge->{'meta-spec'}->{version};
1181 sub _add_requirements_to_meta_v1_4 {
1182 my ( $self, %meta ) = @_;
1184 # Check the original args so we can tell between the user setting it
1185 # to an empty hash and it just being initialized.
1186 if( $self->{ARGS}{CONFIGURE_REQUIRES} ) {
1187 $meta{configure_requires} = $self->{CONFIGURE_REQUIRES};
1189 $meta{configure_requires} = {
1190 'ExtUtils::MakeMaker' => 0,
1194 if( $self->{ARGS}{BUILD_REQUIRES} ) {
1195 $meta{build_requires} = $self->{BUILD_REQUIRES};
1197 $meta{build_requires} = {
1198 'ExtUtils::MakeMaker' => 0,
1202 if( $self->{ARGS}{TEST_REQUIRES} ) {
1203 $meta{build_requires} = {
1204 %{ $meta{build_requires} },
1205 %{ $self->{TEST_REQUIRES} },
1209 $meta{requires} = $self->{PREREQ_PM}
1210 if defined $self->{PREREQ_PM};
1211 $meta{requires}{perl} = _normalize_version($self->{MIN_PERL_VERSION})
1212 if $self->{MIN_PERL_VERSION};
1217 sub _add_requirements_to_meta_v2 {
1218 my ( $self, %meta ) = @_;
1220 # Check the original args so we can tell between the user setting it
1221 # to an empty hash and it just being initialized.
1222 if( $self->{ARGS}{CONFIGURE_REQUIRES} ) {
1223 $meta{prereqs}{configure}{requires} = $self->{CONFIGURE_REQUIRES};
1225 $meta{prereqs}{configure}{requires} = {
1226 'ExtUtils::MakeMaker' => 0,
1230 if( $self->{ARGS}{BUILD_REQUIRES} ) {
1231 $meta{prereqs}{build}{requires} = $self->{BUILD_REQUIRES};
1233 $meta{prereqs}{build}{requires} = {
1234 'ExtUtils::MakeMaker' => 0,
1238 if( $self->{ARGS}{TEST_REQUIRES} ) {
1239 $meta{prereqs}{test}{requires} = $self->{TEST_REQUIRES};
1242 $meta{prereqs}{runtime}{requires} = $self->{PREREQ_PM}
1243 if $self->{ARGS}{PREREQ_PM};
1244 $meta{prereqs}{runtime}{requires}{perl} = _normalize_version($self->{MIN_PERL_VERSION})
1245 if $self->{MIN_PERL_VERSION};
1250 # Adapted from Module::Build::Base
1251 sub _normalize_version {
1253 $version = 0 unless defined $version;
1255 if ( ref $version eq 'version' ) { # version objects
1256 $version = $version->is_qv ? $version->normal : $version->stringify;
1258 elsif ( $version =~ /^[^v][^.]*\.[^.]+\./ ) { # no leading v, multiple dots
1259 # normalize string tuples without "v": "1.2.3" -> "v1.2.3"
1260 $version = "v$version";
1270 $yaml = _dump_hash(\%options, %hash);
1272 Implements a fake YAML dumper for a hash given
1273 as a list of pairs. No quoting/escaping is done. Keys
1274 are supposed to be strings. Values are undef, strings,
1275 hash refs or array refs of strings.
1277 Supported options are:
1279 delta => STR - indentation delta
1280 use_header => BOOL - whether to include a YAML header
1281 indent => STR - a string of spaces
1284 max_key_length => INT - maximum key length used to align
1285 keys and values of the same hash
1287 key_sort => CODE - a sort sub
1288 It may be undef, which means no sorting by keys
1289 default: sub { lc $a cmp lc $b }
1291 customs => HASH - special options for certain keys
1292 (whose values are hashes themselves)
1293 may contain: max_key_length, key_sort, customs
1300 croak "first argument should be a hash ref" unless ref $_[0] eq 'HASH';
1301 my $options = shift;
1304 # Use a list to preserve order.
1308 = exists $options->{key_sort} ? $options->{key_sort}
1309 : sub { lc $a cmp lc $b };
1311 croak "'key_sort' should be a coderef" unless ref $k_sort eq 'CODE';
1312 @pairs = _sort_pairs($k_sort, \%hash);
1313 } else { # list of pairs, no sorting
1317 my $yaml = $options->{use_header} ? "--- #YAML:1.0\n" : '';
1318 my $indent = $options->{indent} || '';
1320 ($options->{max_key_length} || 20),
1321 max(map { length($_) + 1 } grep { !ref $hash{$_} } keys %hash)
1323 my $customs = $options->{customs} || {};
1325 # printf format for key
1326 my $k_format = "%-${k_length}s";
1329 my($key, $val) = splice @pairs, 0, 2;
1330 $val = '~' unless defined $val;
1331 if(ref $val eq 'HASH') {
1333 my %k_options = ( # options for recursive call
1334 delta => $options->{delta},
1336 indent => $indent . $options->{delta},
1338 if (exists $customs->{$key}) {
1339 my %k_custom = %{$customs->{$key}};
1340 foreach my $k (qw(key_sort max_key_length customs)) {
1341 $k_options{$k} = $k_custom{$k} if exists $k_custom{$k};
1344 $yaml .= $indent . "$key:\n"
1345 . _dump_hash(\%k_options, %$val);
1348 $yaml .= $indent . "$key: {}\n";
1351 elsif (ref $val eq 'ARRAY') {
1353 $yaml .= $indent . "$key:\n";
1356 croak "only nested arrays of non-refs are supported" if ref $_;
1357 $yaml .= $indent . $options->{delta} . "- $_\n";
1361 $yaml .= $indent . "$key: []\n";
1364 elsif( ref $val and !blessed($val) ) {
1365 croak "only nested hashes, arrays and objects are supported";
1367 else { # if it's an object, just stringify it
1368 $yaml .= $indent . sprintf "$k_format %s\n", "$key:", $val;
1377 return eval { $_[0]->isa("UNIVERSAL"); };
1381 return (sort { $b <=> $a } @_)[0];
1385 return (sort { $a <=> $b } @_)[0];
1388 =head3 metafile_file
1390 my $meta_yml = $mm->metafile_file(@metadata_pairs);
1392 Turns the @metadata_pairs into YAML.
1394 This method does not implement a complete YAML dumper, being limited
1395 to dump a hash with values which are strings, undef's or nested hashes
1396 and arrays of strings. No quoting/escaping is done.
1403 my %dump_options = (
1408 return _dump_hash(\%dump_options, @_);
1413 =head3 distmeta_target
1415 my $make_frag = $mm->distmeta_target;
1417 Generates the distmeta target to add META.yml and META.json to the MANIFEST
1422 sub distmeta_target {
1426 $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']),
1427 exit unless -e q{META.yml};
1428 eval { maniadd({q{META.yml} => q{Module YAML meta-data (added by MakeMaker)}}) }
1429 or print "Could not add META.yml to MANIFEST: $${'@'}\n"
1431 $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd'])
1432 exit unless -f q{META.json};
1433 eval { maniadd({q{META.json} => q{Module JSON meta-data (added by MakeMaker)}}) }
1434 or print "Could not add META.json to MANIFEST: $${'@'}\n"
1438 my @add_meta_to_distdir = map { $self->cd('$(DISTVNAME)', $_) } @add_meta;
1440 return sprintf <<'MAKE', @add_meta_to_distdir;
1441 distmeta : create_distdir metafile
1452 my $mymeta = $mm->mymeta;
1454 Generate MYMETA information as a hash either from an existing CPAN Meta file
1455 (META.json or META.yml) or from internal data.
1461 my $file = shift || ''; # for testing
1463 my $mymeta = $self->_mymeta_from_meta($file);
1466 unless ( $mymeta ) {
1467 my @metadata = $self->metafile_data(
1468 $self->{META_ADD} || {},
1469 $self->{META_MERGE} || {},
1471 $mymeta = {@metadata};
1475 # Overwrite the non-configure dependency hashes
1478 ? '_add_requirements_to_meta_v2'
1479 : '_add_requirements_to_meta_v1_4';
1481 $mymeta = { $self->$method( %$mymeta ) };
1483 $mymeta->{dynamic_config} = 0;
1489 sub _mymeta_from_meta {
1491 my $metafile = shift || ''; # for testing
1493 return unless _has_cpan_meta();
1496 for my $file ( $metafile, "META.json", "META.yml" ) {
1497 next unless -e $file;
1499 $meta = CPAN::Meta->load_file($file)->as_struct( { version => 2 } );
1503 return unless $meta;
1505 # META.yml before 6.25_01 cannot be trusted. META.yml lived in the source directory.
1506 # There was a good chance the author accidentally uploaded a stale META.yml if they
1507 # rolled their own tarball rather than using "make dist".
1508 if ($meta->{generated_by} &&
1509 $meta->{generated_by} =~ /ExtUtils::MakeMaker version ([\d\._]+)/) {
1510 my $eummv = do { local $^W = 0; $1+0; };
1511 if ($eummv < 6.2501) {
1521 $self->write_mymeta( $mymeta );
1523 Write MYMETA information to MYMETA.json and MYMETA.yml.
1531 return unless _has_cpan_meta();
1533 _fix_metadata_before_conversion( $mymeta );
1535 # this can still blow up
1536 # not sure if i should just eval this and skip file creation if it
1538 my $meta_obj = CPAN::Meta->new( $mymeta, { lazy_validation => 1 } );
1539 $meta_obj->save( 'MYMETA.json' );
1540 $meta_obj->save( 'MYMETA.yml', { version => "1.4" } );
1544 =head3 realclean (o)
1546 Defines the realclean target.
1551 my($self, %attribs) = @_;
1553 my @dirs = qw($(DISTVNAME));
1554 my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD));
1556 # Special exception for the perl core where INST_* is not in blib.
1557 # This cleans up the files built from the ext/ directory (all XS).
1558 if( $self->{PERL_CORE} ) {
1559 push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR));
1560 push @files, values %{$self->{PM}};
1563 if( $self->has_link_code ){
1564 push @files, qw($(OBJECT));
1567 if( $attribs{FILES} ) {
1568 if( ref $attribs{FILES} ) {
1569 push @dirs, @{ $attribs{FILES} };
1572 push @dirs, split /\s+/, $attribs{FILES};
1576 # Occasionally files are repeated several times from different sources
1577 { my(%f) = map { ($_ => 1) } @files; @files = keys %f; }
1578 { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; }
1580 my $rm_cmd = join "\n\t", map { "$_" }
1581 $self->split_command('- $(RM_F)', @files);
1582 my $rmf_cmd = join "\n\t", map { "$_" }
1583 $self->split_command('- $(RM_RF)', @dirs);
1585 my $m = sprintf <<'MAKE', $rm_cmd, $rmf_cmd;
1586 # Delete temporary files (via clean) and also delete dist files
1587 realclean purge :: clean realclean_subdirs
1592 $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP};
1598 =head3 realclean_subdirs_target
1600 my $make_frag = $MM->realclean_subdirs_target;
1602 Returns the realclean_subdirs target. This is used by the realclean
1603 target to call realclean on any subdirectories which contain Makefiles.
1607 sub realclean_subdirs_target {
1610 return <<'NOOP_FRAG' unless @{$self->{DIR}};
1615 my $rclean = "realclean_subdirs :\n";
1617 foreach my $dir (@{$self->{DIR}}) {
1618 foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) {
1619 my $subrclean .= $self->oneliner(sprintf <<'CODE', $dir, ($makefile) x 2);
1620 chdir '%s'; system '$(MAKE) $(USEMAKEFILE) %s realclean' if -f '%s';
1623 $rclean .= sprintf <<'RCLEAN', $subrclean;
1634 =head3 signature_target
1636 my $target = $mm->signature_target;
1638 Generate the signature target.
1640 Writes the file SIGNATURE with "cpansign -s".
1644 sub signature_target {
1647 return <<'MAKE_FRAG';
1655 =head3 distsignature_target
1657 my $make_frag = $mm->distsignature_target;
1659 Generates the distsignature target to add SIGNATURE to the MANIFEST in the
1664 sub distsignature_target {
1667 my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
1668 eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) }
1669 or print "Could not add SIGNATURE to MANIFEST: $${'@'}\n"
1672 my $sign_dist = $self->cd('$(DISTVNAME)' => 'cpansign -s');
1674 # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not
1676 my $touch_sig = $self->cd('$(DISTVNAME)' => '$(TOUCH) SIGNATURE');
1677 my $add_sign_to_dist = $self->cd('$(DISTVNAME)' => $add_sign );
1679 return sprintf <<'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist
1680 distsignature : distmeta
1690 =head3 special_targets
1692 my $make_frag = $mm->special_targets
1694 Returns a make fragment containing any targets which have special
1695 meaning to make. For example, .SUFFIXES and .PHONY.
1699 sub special_targets {
1700 my $make_frag = <<'MAKE_FRAG';
1701 .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)
1703 .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir
1707 $make_frag .= <<'MAKE_FRAG' if $ENV{CLEARCASE_ROOT};
1708 .NO_CONFIG_REC: Makefile
1720 Methods which help initialize the MakeMaker object and macros.
1723 =head3 init_ABSTRACT
1732 if( $self->{ABSTRACT_FROM} and $self->{ABSTRACT} ) {
1733 warn "Both ABSTRACT_FROM and ABSTRACT are set. ".
1734 "Ignoring ABSTRACT_FROM.\n";
1738 if ($self->{ABSTRACT_FROM}){
1739 $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or
1740 carp "WARNING: Setting ABSTRACT via file ".
1741 "'$self->{ABSTRACT_FROM}' failed\n";
1744 if ($self->{ABSTRACT} && $self->{ABSTRACT} =~ m![[:cntrl:]]+!) {
1745 warn "WARNING: ABSTRACT contains control character(s),".
1746 " they will be removed\n";
1747 $self->{ABSTRACT} =~ s![[:cntrl:]]+!!g;
1756 Called by init_main. Sets up all INST_* variables except those related
1757 to XS code. Those are handled in init_xs.
1764 $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch");
1765 $self->{INST_BIN} ||= $self->catdir($Curdir,'blib','bin');
1767 # INST_LIB typically pre-set if building an extension after
1768 # perl has been built and installed. Setting INST_LIB allows
1769 # you to build directly into, say $Config{privlibexp}.
1770 unless ($self->{INST_LIB}){
1771 if ($self->{PERL_CORE}) {
1772 $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
1774 $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib");
1778 my @parentdir = split(/::/, $self->{PARENT_NAME});
1779 $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)', @parentdir);
1780 $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)', @parentdir);
1781 $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)', 'auto',
1783 $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto',
1786 $self->{INST_SCRIPT} ||= $self->catdir($Curdir,'blib','script');
1788 $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1');
1789 $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3');
1799 Called by init_main. Sets up all INSTALL_* variables (except
1800 INSTALLDIRS) and *PREFIX.
1807 if( $self->{ARGS}{INSTALL_BASE} and $self->{ARGS}{PREFIX} ) {
1808 die "Only one of PREFIX or INSTALL_BASE can be given. Not both.\n";
1811 if( $self->{ARGS}{INSTALL_BASE} ) {
1812 $self->init_INSTALL_from_INSTALL_BASE;
1815 $self->init_INSTALL_from_PREFIX;
1820 =head3 init_INSTALL_from_PREFIX
1822 $mm->init_INSTALL_from_PREFIX;
1826 sub init_INSTALL_from_PREFIX {
1829 $self->init_lib2arch;
1831 # There are often no Config.pm defaults for these new man variables so
1832 # we fall back to the old behavior which is to use installman*dir
1833 foreach my $num (1, 3) {
1834 my $k = 'installsiteman'.$num.'dir';
1836 $self->{uc $k} ||= uc "\$(installman${num}dir)"
1840 foreach my $num (1, 3) {
1841 my $k = 'installvendorman'.$num.'dir';
1843 unless( $Config{$k} ) {
1844 $self->{uc $k} ||= $Config{usevendorprefix}
1845 ? uc "\$(installman${num}dir)"
1850 $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)'
1851 unless $Config{installsitebin};
1852 $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)'
1853 unless $Config{installsitescript};
1855 unless( $Config{installvendorbin} ) {
1856 $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix}
1857 ? $Config{installbin}
1860 unless( $Config{installvendorscript} ) {
1861 $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix}
1862 ? $Config{installscript}
1867 my $iprefix = $Config{installprefixexp} || $Config{installprefix} ||
1868 $Config{prefixexp} || $Config{prefix} || '';
1869 my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : '';
1870 my $sprefix = $Config{siteprefixexp} || '';
1872 # 5.005_03 doesn't have a siteprefix.
1873 $sprefix = $iprefix unless $sprefix;
1876 $self->{PREFIX} ||= '';
1878 if( $self->{PREFIX} ) {
1879 @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} =
1883 $self->{PERLPREFIX} ||= $iprefix;
1884 $self->{SITEPREFIX} ||= $sprefix;
1885 $self->{VENDORPREFIX} ||= $vprefix;
1887 # Lots of MM extension authors like to use $(PREFIX) so we
1888 # put something sensible in there no matter what.
1889 $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)';
1892 my $arch = $Config{archname};
1893 my $version = $Config{version};
1896 my $libstyle = $Config{installstyle} || 'lib/perl5';
1899 if( $self->{LIBSTYLE} ) {
1900 $libstyle = $self->{LIBSTYLE};
1901 $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : '';
1904 # Some systems, like VOS, set installman*dir to '' if they can't
1906 for my $num (1, 3) {
1907 $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none'
1908 unless $Config{'installman'.$num.'dir'};
1913 bin => { s => $iprefix,
1916 vendorbin => { s => $vprefix,
1919 sitebin => { s => $sprefix,
1922 script => { s => $iprefix,
1925 vendorscript=> { s => $vprefix,
1928 sitescript => { s => $sprefix,
1935 man1dir => { s => $iprefix,
1938 style => $manstyle, },
1939 siteman1dir => { s => $sprefix,
1942 style => $manstyle, },
1943 vendorman1dir => { s => $vprefix,
1946 style => $manstyle, },
1948 man3dir => { s => $iprefix,
1951 style => $manstyle, },
1952 siteman3dir => { s => $sprefix,
1955 style => $manstyle, },
1956 vendorman3dir => { s => $vprefix,
1959 style => $manstyle, },
1964 privlib => { s => $iprefix,
1967 style => $libstyle, },
1968 vendorlib => { s => $vprefix,
1971 style => $libstyle, },
1972 sitelib => { s => $sprefix,
1975 style => $libstyle, },
1977 archlib => { s => $iprefix,
1979 d => "$version/$arch",
1980 style => $libstyle },
1981 vendorarch => { s => $vprefix,
1983 d => "$version/$arch",
1984 style => $libstyle },
1985 sitearch => { s => $sprefix,
1987 d => "site_perl/$version/$arch",
1988 style => $libstyle },
1992 # Special case for LIB.
1993 if( $self->{LIB} ) {
1994 foreach my $var (keys %lib_layouts) {
1995 my $Installvar = uc "install$var";
1997 if( $var =~ /arch/ ) {
1998 $self->{$Installvar} ||=
1999 $self->catdir($self->{LIB}, $Config{archname});
2002 $self->{$Installvar} ||= $self->{LIB};
2007 my %type2prefix = ( perl => 'PERLPREFIX',
2008 site => 'SITEPREFIX',
2009 vendor => 'VENDORPREFIX'
2012 my %layouts = (%bin_layouts, %man_layouts, %lib_layouts);
2013 while( my($var, $layout) = each(%layouts) ) {
2014 my($s, $t, $d, $style) = @{$layout}{qw(s t d style)};
2015 my $r = '$('.$type2prefix{$t}.')';
2017 warn "Prefixing $var\n" if $Verbose >= 2;
2019 my $installvar = "install$var";
2020 my $Installvar = uc $installvar;
2021 next if $self->{$Installvar};
2023 $d = "$style/$d" if $style;
2024 $self->prefixify($installvar, $s, $r, $d);
2026 warn " $Installvar == $self->{$Installvar}\n"
2030 # Generate these if they weren't figured out.
2031 $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH};
2032 $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB};
2038 =head3 init_from_INSTALL_BASE
2040 $mm->init_from_INSTALL_BASE
2045 lib => [qw(lib perl5)],
2046 arch => [('lib', 'perl5', $Config{archname})],
2048 man1dir => [qw(man man1)],
2049 man3dir => [qw(man man3)]
2051 $map{script} = $map{bin};
2053 sub init_INSTALL_from_INSTALL_BASE {
2056 @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} =
2060 foreach my $thing (keys %map) {
2061 foreach my $dir (('', 'SITE', 'VENDOR')) {
2062 my $uc_thing = uc $thing;
2063 my $key = "INSTALL".$dir.$uc_thing;
2066 $self->catdir('$(INSTALL_BASE)', @{$map{$thing}});
2070 # Adjust for variable quirks.
2071 $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH};
2072 $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB};
2074 foreach my $key (keys %install) {
2075 $self->{$key} ||= $install{$key};
2082 =head3 init_VERSION I<Abstract>
2086 Initialize macros representing versions of MakeMaker and other tools
2088 MAKEMAKER: path to the MakeMaker module.
2090 MM_VERSION: ExtUtils::MakeMaker Version
2092 MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards
2095 VERSION: version of your module
2097 VERSION_MACRO: which macro represents the version (usually 'VERSION')
2099 VERSION_SYM: like version but safe for use as an RCS revision number
2101 DEFINE_VERSION: -D line to set the module version when compiling
2103 XS_VERSION: version in your .xs file. Defaults to $(VERSION)
2105 XS_VERSION_MACRO: which macro represents the XS version.
2107 XS_DEFINE_VERSION: -D line to set the xs version when compiling.
2109 Called by init_main.
2116 $self->{MAKEMAKER} = $ExtUtils::MakeMaker::Filename;
2117 $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION;
2118 $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision;
2119 $self->{VERSION_FROM} ||= '';
2121 if ($self->{VERSION_FROM}){
2122 $self->{VERSION} = $self->parse_version($self->{VERSION_FROM});
2123 if( $self->{VERSION} eq 'undef' ) {
2124 carp("WARNING: Setting VERSION via file ".
2125 "'$self->{VERSION_FROM}' failed\n");
2129 if (defined $self->{VERSION}) {
2130 if ( $self->{VERSION} !~ /^\s*v?[\d_\.]+\s*$/ ) {
2132 my $normal = eval { version->new( $self->{VERSION} ) };
2133 $self->{VERSION} = $normal if defined $normal;
2135 $self->{VERSION} =~ s/^\s+//;
2136 $self->{VERSION} =~ s/\s+$//;
2139 $self->{VERSION} = '';
2143 $self->{VERSION_MACRO} = 'VERSION';
2144 ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
2145 $self->{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"';
2148 # Graham Barr and Paul Marquess had some ideas how to ensure
2149 # version compatibility between the *.pm file and the
2150 # corresponding *.xs file. The bottom line was, that we need an
2151 # XS_VERSION macro that defaults to VERSION:
2152 $self->{XS_VERSION} ||= $self->{VERSION};
2154 $self->{XS_VERSION_MACRO} = 'XS_VERSION';
2155 $self->{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"';
2164 Initializes the simple macro definitions used by tools_other() and
2165 places them in the $MM object. These use conservative cross platform
2166 versions and should be overridden with platform specific versions for
2169 Defines at least these macros.
2174 NOECHO Tell make not to display the command itself
2176 SHELL Program used to run shell commands
2178 ECHO Print text adding a newline on the end
2180 RM_RF Remove a directory
2181 TOUCH Update a file's timestamp
2182 TEST_F Test for a file's existence
2183 TEST_S Test the size of a file
2185 CP_NONEMPTY Copy a file if it is not empty
2187 CHMOD Change permissions on a file
2188 FALSE Exit with non-zero
2191 UMASK_NULL Nullify umask
2192 DEV_NULL Suppress all command output
2199 $self->{ECHO} ||= $self->oneliner('binmode STDOUT, qq{:raw}; print qq{@ARGV}', ['-l']);
2200 $self->{ECHO_N} ||= $self->oneliner('print qq{@ARGV}');
2202 $self->{TOUCH} ||= $self->oneliner('touch', ["-MExtUtils::Command"]);
2203 $self->{CHMOD} ||= $self->oneliner('chmod', ["-MExtUtils::Command"]);
2204 $self->{RM_F} ||= $self->oneliner('rm_f', ["-MExtUtils::Command"]);
2205 $self->{RM_RF} ||= $self->oneliner('rm_rf', ["-MExtUtils::Command"]);
2206 $self->{TEST_F} ||= $self->oneliner('test_f', ["-MExtUtils::Command"]);
2207 $self->{TEST_S} ||= $self->oneliner('test_s', ["-MExtUtils::Command::MM"]);
2208 $self->{CP_NONEMPTY} ||= $self->oneliner('cp_nonempty', ["-MExtUtils::Command::MM"]);
2209 $self->{FALSE} ||= $self->oneliner('exit 1');
2210 $self->{TRUE} ||= $self->oneliner('exit 0');
2212 $self->{MKPATH} ||= $self->oneliner('mkpath', ["-MExtUtils::Command"]);
2214 $self->{CP} ||= $self->oneliner('cp', ["-MExtUtils::Command"]);
2215 $self->{MV} ||= $self->oneliner('mv', ["-MExtUtils::Command"]);
2217 $self->{MOD_INSTALL} ||=
2218 $self->oneliner(<<'CODE', ['-MExtUtils::Install']);
2219 install([ from_to => {@ARGV}, verbose => '$(VERBINST)', uninstall_shadows => '$(UNINST)', dir_mode => '$(PERM_DIR)' ]);
2221 $self->{DOC_INSTALL} ||= $self->oneliner('perllocal_install', ["-MExtUtils::Command::MM"]);
2222 $self->{UNINSTALL} ||= $self->oneliner('uninstall', ["-MExtUtils::Command::MM"]);
2223 $self->{WARN_IF_OLD_PACKLIST} ||=
2224 $self->oneliner('warn_if_old_packlist', ["-MExtUtils::Command::MM"]);
2225 $self->{FIXIN} ||= $self->oneliner('MY->fixin(shift)', ["-MExtUtils::MY"]);
2226 $self->{EQUALIZE_TIMESTAMP} ||= $self->oneliner('eqtime', ["-MExtUtils::Command"]);
2228 $self->{UNINST} ||= 0;
2229 $self->{VERBINST} ||= 0;
2231 $self->{SHELL} ||= $Config{sh};
2233 # UMASK_NULL is not used by MakeMaker but some CPAN modules
2235 $self->{UMASK_NULL} ||= "umask 0";
2237 # Not the greatest default, but its something.
2238 $self->{DEV_NULL} ||= "> /dev/null 2>&1";
2240 $self->{NOOP} ||= '$(TRUE)';
2241 $self->{NOECHO} = '@' unless defined $self->{NOECHO};
2243 $self->{FIRST_MAKEFILE} ||= $self->{MAKEFILE} || 'Makefile';
2244 $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE};
2245 $self->{MAKEFILE_OLD} ||= $self->{MAKEFILE}.'.old';
2246 $self->{MAKE_APERL_FILE} ||= $self->{MAKEFILE}.'.aperl';
2248 # Not everybody uses -f to indicate "use this Makefile instead"
2249 $self->{USEMAKEFILE} ||= '-f';
2251 # Some makes require a wrapper around macros passed in on the command
2253 $self->{MACROSTART} ||= '';
2254 $self->{MACROEND} ||= '';
2264 Initializes the macro definitions having to do with compiling and
2265 linking used by tools_other() and places them in the $MM object.
2267 If there is no description, its the same as the parameter to
2268 WriteMakefile() documented in ExtUtils::MakeMaker.
2275 $self->{LD_RUN_PATH} = "";
2277 $self->{LIBS} = $self->_fix_libs($self->{LIBS});
2279 # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
2280 foreach my $libs ( @{$self->{LIBS}} ){
2281 $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
2282 my(@libs) = $self->extliblist($libs);
2283 if ($libs[0] or $libs[1] or $libs[2]){
2284 # LD_RUN_PATH now computed by ExtUtils::Liblist
2285 ($self->{EXTRALIBS}, $self->{BSLOADLIBS},
2286 $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
2291 if ( $self->{OBJECT} ) {
2292 $self->{OBJECT} = join(" ", @{$self->{OBJECT}}) if ref $self->{OBJECT};
2293 $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
2294 } elsif ( $self->{MAGICXS} && @{$self->{O_FILES}||[]} ) {
2295 $self->{OBJECT} = join(" ", @{$self->{O_FILES}});
2296 $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
2298 # init_dirscan should have found out, if we have C files
2299 $self->{OBJECT} = "";
2300 $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
2302 $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
2304 $self->{BOOTDEP} = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
2305 $self->{PERLMAINCC} ||= '$(CC)';
2306 $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
2308 # Sanity check: don't define LINKTYPE = dynamic if we're skipping
2309 # the 'dynamic' section of MM. We don't have this problem with
2310 # 'static', since we either must use it (%Config says we can't
2311 # use dynamic loading) or the caller asked for it explicitly.
2312 if (!$self->{LINKTYPE}) {
2313 $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
2315 : ($Config{usedl} ? 'dynamic' : 'static');
2322 # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
2323 # undefined. In any case we turn it into an anon array
2325 my($self, $libs) = @_;
2327 return !defined $libs ? [''] :
2328 !ref $libs ? [$libs] :
2329 !defined $libs->[0] ? [''] :
2336 my $make_frag = $MM->tools_other;
2338 Returns a make fragment containing definitions for the macros init_others()
2347 # We set PM_FILTER as late as possible so it can see all the earlier
2348 # on macro-order sensitive makes such as nmake.
2349 for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH
2350 UMASK_NULL DEV_NULL MKPATH EQUALIZE_TIMESTAMP
2354 MOD_INSTALL DOC_INSTALL UNINSTALL
2355 WARN_IF_OLD_PACKLIST
2363 next unless defined $self->{$tool};
2364 push @m, "$tool = $self->{$tool}\n";
2371 =head3 init_DIRFILESEP I<Abstract>
2373 $MM->init_DIRFILESEP;
2374 my $dirfilesep = $MM->{DIRFILESEP};
2376 Initializes the DIRFILESEP macro which is the separator between the
2377 directory and filename in a filepath. ie. / on Unix, \ on Win32 and
2382 # instead of $(INST_ARCHAUTODIR)/extralibs.ld
2383 $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld
2385 Something of a hack but it prevents a lot of code duplication between
2388 Do not use this as a separator between directories. Some operating
2389 systems use different separators between subdirectories as between
2390 directories and filenames (for example: VOLUME:[dir1.dir2]file on VMS).
2392 =head3 init_linker I<Abstract>
2396 Initialize macros which have to do with linking.
2398 PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic
2401 PERL_ARCHIVE_AFTER: path to a library which should be put on the
2402 linker command line I<after> the external libraries to be linked to
2403 dynamic extensions. This may be needed if the linker is one-pass, and
2404 Perl includes some overrides for C RTL functions, such as malloc().
2406 EXPORT_LIST: name of a file that is passed to linker to define symbols
2409 Some OSes do not need these in which case leave it blank.
2412 =head3 init_platform
2416 Initialize any macros which are for platform specific use only.
2418 A typical one is the version number of your OS specific module.
2419 (ie. MM_Unix_VERSION or MM_VMS_VERSION).
2432 Initialize MAKE from either a MAKE environment variable or $Config{make}.
2439 $self->{MAKE} ||= $ENV{MAKE} || $Config{make};
2445 A grab bag of methods to generate specific macros and commands.
2451 Defines targets and routines to translate the pods into manpages and
2452 put them into the INST_* directories.
2459 my $POD2MAN_macro = $self->POD2MAN_macro();
2460 my $manifypods_target = $self->manifypods_target();
2462 return <<END_OF_TARGET;
2473 =head3 POD2MAN_macro
2475 my $pod2man_macro = $self->POD2MAN_macro
2477 Returns a definition for the POD2MAN macro. This is a program
2478 which emulates the pod2man utility. You can add more switches to the
2479 command by simply appending them on the macro.
2483 $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ...
2490 # Need the trailing '--' so perl stops gobbling arguments and - happens
2491 # to be an alternative end of line separator on VMS so we quote it
2492 return <<'END_OF_DEF';
2493 POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--"
2494 POD2MAN = $(POD2MAN_EXE)
2499 =head3 test_via_harness
2501 my $command = $mm->test_via_harness($perl, $tests);
2503 Returns a $command line which runs the given set of $tests with
2504 Test::Harness and the given $perl.
2506 Used on the t/*.t files.
2510 sub test_via_harness {
2511 my($self, $perl, $tests) = @_;
2513 return qq{\t$perl "-MExtUtils::Command::MM" "-MTest::Harness" }.
2514 qq{"-e" "undef *Test::Harness::Switches; test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n};
2517 =head3 test_via_script
2519 my $command = $mm->test_via_script($perl, $script);
2521 Returns a $command line which just runs a single test without
2522 Test::Harness. No checks are done on the results, they're just
2525 Used for test.pl, since they don't always follow Test::Harness
2530 sub test_via_script {
2531 my($self, $perl, $script) = @_;
2532 return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n};
2536 =head3 tool_autosplit
2538 Defines a simple perl call that runs autosplit. May be deprecated by
2543 sub tool_autosplit {
2544 my($self, %attribs) = @_;
2546 my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};'
2549 my $asplit = $self->oneliner(sprintf <<'PERL_CODE', $maxlen);
2550 use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1)
2553 return sprintf <<'MAKE_FRAG', $asplit;
2554 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
2564 my $arch_ok = $mm->arch_check(
2566 File::Spec->catfile($Config{archlibexp}, "Config.pm")
2569 A sanity check that what Perl thinks the architecture is and what
2570 Config thinks the architecture is are the same. If they're not it
2571 will return false and show a diagnostic message.
2573 When building Perl it will always return true, as nothing is installed
2576 The interface is a bit odd because this is the result of a
2577 quick refactoring. Don't rely on it.
2583 my($pconfig, $cconfig) = @_;
2585 return 1 if $self->{PERL_SRC};
2587 my($pvol, $pthinks) = $self->splitpath($pconfig);
2588 my($cvol, $cthinks) = $self->splitpath($cconfig);
2590 $pthinks = $self->canonpath($pthinks);
2591 $cthinks = $self->canonpath($cthinks);
2594 if ($pthinks ne $cthinks) {
2595 print "Have $pthinks\n";
2596 print "Want $cthinks\n";
2600 my $arch = (grep length, $self->splitdir($pthinks))[-1];
2602 print <<END unless $self->{UNINSTALLED_PERL};
2603 Your perl and your Config.pm seem to have different ideas about the
2604 architecture they are running on.
2605 Perl thinks: [$arch]
2606 Config says: [$Config{archname}]
2607 This may or may not cause problems. Please check your installation of perl
2608 if you have problems building this extension.
2617 =head2 File::Spec wrappers
2619 ExtUtils::MM_Any is a subclass of File::Spec. The methods noted here
2620 override File::Spec.
2626 File::Spec <= 0.83 has a bug where the file part of catfile is not
2627 canonicalized. This override fixes that bug.
2633 return $self->canonpath($self->SUPER::catfile(@_));
2640 Methods I can't really figure out where they should go yet.
2645 my $test = $mm->find_tests;
2647 Returns a string suitable for feeding to the shell to return all
2654 return -d 't' ? 't/*.t' : '';
2657 =head3 find_tests_recursive
2659 my $tests = $mm->find_tests_recursive;
2661 Returns a string suitable for feeding to the shell to return all
2662 tests in t/ but recursively.
2666 sub find_tests_recursive {
2668 return '' unless -d 't';
2675 return unless m!\.t$!;
2676 my ($volume,$directories,$file) =
2677 File::Spec->splitpath( $File::Find::name );
2678 my @dirs = File::Spec->splitdir( $directories );
2687 my $testfile = join '/', @dirs;
2688 $testfiles{ $testfile } = 1;
2691 File::Find::find( $wanted, 't' );
2693 return join ' ', sort keys %testfiles;
2696 =head3 extra_clean_files
2698 my @files_to_clean = $MM->extra_clean_files;
2700 Returns a list of OS specific files to be removed in the clean target in
2701 addition to the usual set.
2705 # An empty method here tickled a perl 5.8.1 bug and would return its object.
2706 sub extra_clean_files {
2713 my @installvars = $mm->installvars;
2715 A list of all the INSTALL* variables without the INSTALL prefix. Useful
2716 for iteration or building related variable sets.
2721 return qw(PRIVLIB SITELIB VENDORLIB
2722 ARCHLIB SITEARCH VENDORARCH
2723 BIN SITEBIN VENDORBIN
2724 SCRIPT SITESCRIPT VENDORSCRIPT
2725 MAN1DIR SITEMAN1DIR VENDORMAN1DIR
2726 MAN3DIR SITEMAN3DIR VENDORMAN3DIR
2733 my $wanted = $self->libscan($path);
2735 Takes a path to a file or dir and returns an empty string if we don't
2736 want to include this file in the library. Otherwise it returns the
2737 the $path unchanged.
2739 Mainly used to exclude version control administrative directories from
2745 my($self,$path) = @_;
2746 my($dirs,$file) = ($self->splitpath($path))[1,2];
2747 return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/,
2748 $self->splitdir($dirs), $file;
2754 =head3 platform_constants
2756 my $make_frag = $mm->platform_constants
2758 Returns a make fragment defining all the macros initialized in
2759 init_platform() rather than put them in constants().
2763 sub platform_constants {
2769 =head3 _PREREQ_PRINT
2771 $self->_PREREQ_PRINT;
2773 Implements PREREQ_PRINT.
2775 Refactored out of MakeMaker->new().
2784 require Data::Dumper;
2785 my @what = ('PREREQ_PM');
2786 push @what, 'MIN_PERL_VERSION' if $self->{MIN_PERL_VERSION};
2787 push @what, 'BUILD_REQUIRES' if $self->{BUILD_REQUIRES};
2788 print Data::Dumper->Dump([@{$self}{@what}], \@what);
2795 =head3 _PRINT_PREREQ
2799 Implements PRINT_PREREQ, a slightly different version of PREREQ_PRINT
2800 added by Redhat to, I think, support generating RPMs from Perl modules.
2802 Should not include BUILD_REQUIRES as RPMs do not incluide them.
2804 Refactored out of MakeMaker->new().
2813 my $prereqs= $self->{PREREQ_PM};
2814 my @prereq = map { [$_, $prereqs->{$_}] } keys %$prereqs;
2816 if ( $self->{MIN_PERL_VERSION} ) {
2817 push @prereq, ['perl' => $self->{MIN_PERL_VERSION}];
2820 print join(" ", map { "perl($_->[0])>=$_->[1] " }
2821 sort { $a->[0] cmp $b->[0] } @prereq), "\n";
2830 my $prereqs = $self->_all_prereqs;
2832 Returns a hash ref of both PREREQ_PM and BUILD_REQUIRES.
2841 return { %{$self->{PREREQ_PM}}, %{$self->{BUILD_REQUIRES}} };
2846 =head3 _perl_header_files
2848 my $perl_header_files= $self->_perl_header_files;
2850 returns a sorted list of header files as found in PERL_SRC or $archlibexp/CORE.
2852 Used by perldepend() in MM_Unix and MM_VMS via _perl_header_files_fragment()
2858 sub _perl_header_files {
2861 my $header_dir = $self->{PERL_SRC} || $ENV{PERL_SRC} || $self->catdir($Config{archlibexp}, 'CORE');
2862 opendir my $dh, $header_dir
2863 or die "Failed to opendir '$header_dir' to find header files: $!";
2865 # we need to use a temporary here as the sort in scalar context would have undefined results.
2866 my @perl_headers= sort grep { /\.h\z/ } readdir($dh);
2870 return @perl_headers;
2875 =head3 _perl_header_files_fragment ($o, $separator)
2877 my $perl_header_files_fragment= $self->_perl_header_files_fragment("/");
2879 return a Makefile fragment which holds the list of perl header files which
2880 XS code depends on $(PERL_INC), and sets up the dependency for the $(OBJECT) file.
2882 The $separator argument defaults to "". MM_VMS will set it to "" and MM_UNIX to "/"
2883 in perldepend(). This reason child subclasses need to control this is that in
2884 VMS the $(PERL_INC) directory will already have delimiters in it, but in
2885 UNIX $(PERL_INC) will need a slash between it an the filename. Hypothetically
2886 win32 could use "\\" (but it doesn't need to).
2892 sub _perl_header_files_fragment {
2893 my ($self, $separator)= @_;
2898 sprintf( " \$(PERL_INCDEP)%s%s ", $separator, $_ )
2899 } $self->_perl_header_files()
2901 . "\$(OBJECT) : \$(PERL_HDRS)\n";
2907 Michael G Schwern <schwern@pobox.com> and the denizens of
2908 makemaker@perl.org with code from ExtUtils::MM_Unix and