1 package ExtUtils::MM_Any;
8 BEGIN { our @ISA = qw(File::Spec); }
11 use ExtUtils::MakeMaker qw($Verbose);
13 use ExtUtils::MakeMaker::Config;
16 # So we don't have to keep calling the methods over and over again,
17 # we have these globals to cache the values. Faster and shrtr.
18 my $Curdir = __PACKAGE__->curdir;
19 my $Rootdir = __PACKAGE__->rootdir;
20 my $Updir = __PACKAGE__->updir;
25 ExtUtils::MM_Any - Platform-agnostic MM methods
29 FOR INTERNAL USE ONLY!
31 package ExtUtils::MM_SomeOS;
33 # Temporarily, you have to subclass both. Put MM_Any first.
34 require ExtUtils::MM_Any;
35 require ExtUtils::MM_Unix;
36 @ISA = qw(ExtUtils::MM_Any ExtUtils::Unix);
40 B<FOR INTERNAL USE ONLY!>
42 ExtUtils::MM_Any is a superclass for the ExtUtils::MM_* set of
43 modules. It contains methods which are either inherently
44 cross-platform or are written in a cross-platform manner.
46 Subclass off of ExtUtils::MM_Any I<and> ExtUtils::MM_Unix. This is a
49 B<THIS MAY BE TEMPORARY!>
54 Any methods marked I<Abstract> must be implemented by subclasses.
57 =head2 Cross-platform helper methods
59 These are methods which help writing cross-platform code.
63 =head3 os_flavor I<Abstract>
65 my @os_flavor = $mm->os_flavor;
67 @os_flavor is the style of operating system this is, usually
68 corresponding to the MM_*.pm file we're using.
70 The first element of @os_flavor is the major family (ie. Unix,
71 Windows, VMS, OS/2, etc...) and the rest are sub families.
75 Cygwin98 ('Unix', 'Cygwin', 'Cygwin9x')
76 Windows NT ('Win32', 'WinNT')
77 Win98 ('Win32', 'Win9x')
78 Linux ('Unix', 'Linux')
79 MacOS X ('Unix', 'Darwin', 'MacOS', 'MacOS X')
82 This is used to write code for styles of operating system.
83 See os_flavor_is() for use.
88 my $is_this_flavor = $mm->os_flavor_is($this_flavor);
89 my $is_this_flavor = $mm->os_flavor_is(@one_of_these_flavors);
91 Checks to see if the current operating system is one of the given flavors.
93 This is useful for code like:
95 if( $mm->os_flavor_is('Unix') ) {
106 my %flavors = map { ($_ => 1) } $self->os_flavor;
107 return (grep { $flavors{$_} } @_) ? 1 : 0;
113 my @cmds = $MM->split_command($cmd, @args);
115 Most OS have a maximum command length they can execute at once. Large
116 modules can easily generate commands well past that limit. Its
117 necessary to split long commands up into a series of shorter commands.
119 C<split_command> will return a series of @cmds each processing part of
120 the args. Collectively they will process all the arguments. Each
121 individual line in @cmds will not be longer than the
122 $self->max_exec_len being careful to take into account macro expansion.
124 $cmd should include any switches and repeated initial arguments.
126 If no @args are given, no @cmds will be returned.
128 Pairs of arguments will always be preserved in a single command, this
129 is a heuristic for things like pm_to_blib and pod2man which work on
130 pairs of arguments. This makes things like this safe:
132 $self->split_command($cmd, %pod2man);
138 my($self, $cmd, @args) = @_;
141 return(@cmds) unless @args;
143 # If the command was given as a here-doc, there's probably a trailing
147 # set aside 30% for macro expansion.
148 my $len_left = int($self->max_exec_len * 0.70);
149 $len_left -= length $self->_expand_macros($cmd);
154 while( @next_args = splice(@args, 0, 2) ) {
155 # Two at a time to preserve pairs.
156 my $next_arg_str = "\t ". join ' ', @next_args, "\n";
158 if( !length $arg_str ) {
159 $arg_str .= $next_arg_str
161 elsif( length($arg_str) + length($next_arg_str) > $len_left ) {
162 unshift @args, @next_args;
166 $arg_str .= $next_arg_str;
171 push @cmds, $self->escape_newlines("$cmd \n$arg_str");
179 my($self, $cmd) = @_;
181 $cmd =~ s{\$\((\w+)\)}{
182 defined $self->{$1} ? $self->{$1} : "\$($1)"
190 my @commands = $MM->echo($text);
191 my @commands = $MM->echo($text, $file);
192 my @commands = $MM->echo($text, $file, $appending);
194 Generates a set of @commands which print the $text to a $file.
196 If $file is not given, output goes to STDOUT.
198 If $appending is true the $file will be appended to rather than
204 my($self, $text, $file, $appending) = @_;
207 my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_) }
210 my $redirect = $appending ? '>>' : '>';
211 $cmds[0] .= " $redirect $file";
212 $_ .= " >> $file" foreach @cmds[1..$#cmds];
221 my $args = $mm->wraplist(@list);
223 Takes an array of items and turns them into a well-formatted list of
224 arguments. In most cases this is simply something like:
234 return join " \\\n\t", @_;
238 =head3 maketext_filter
240 my $filter_make_text = $mm->maketext_filter($make_text);
242 The text of the Makefile is run through this method before writing to
243 disk. It allows systems a chance to make portability fixes to the
246 By default it does nothing.
248 This method is protected and not intended to be called outside of
253 sub maketext_filter { return $_[1] }
256 =head3 cd I<Abstract>
258 my $subdir_cmd = $MM->cd($subdir, @cmds);
260 This will generate a make fragment which runs the @cmds in the given
261 $dir. The rough equivalent to this, except cross platform.
265 Currently $dir can only go down one level. "foo" is fine. "foo/bar" is
266 not. "../foo" is right out.
268 The resulting $subdir_cmd has no leading tab nor trailing newline. This
269 makes it easier to embed in a make string. For example.
271 my $make = sprintf <<'CODE', $subdir_cmd;
279 =head3 oneliner I<Abstract>
281 my $oneliner = $MM->oneliner($perl_code);
282 my $oneliner = $MM->oneliner($perl_code, \@switches);
284 This will generate a perl one-liner safe for the particular platform
285 you're on based on the given $perl_code and @switches (a -e is
286 assumed) suitable for using in a make target. It will use the proper
287 shell quoting and escapes.
289 $(PERLRUN) will be used as perl.
291 Any newlines in $perl_code will be escaped. Leading and trailing
292 newlines will be stripped. Makes this idiom much easier:
294 my $code = $MM->oneliner(<<'CODE', [...switches...]);
299 Usage might be something like:
302 $oneliner = $MM->oneliner('print "Foo\n"');
303 $make = '$oneliner > somefile';
305 All dollar signs must be doubled in the $perl_code if you expect them
306 to be interpreted normally, otherwise it will be considered a make
307 macro. Also remember to quote make macros else it might be used as a
308 bareword. For example:
310 # Assign the value of the $(VERSION_FROM) make macro to $vf.
311 $oneliner = $MM->oneliner('$$vf = "$(VERSION_FROM)"');
313 Its currently very simple and may be expanded sometime in the figure
314 to include more flexible code and switches.
317 =head3 quote_literal I<Abstract>
319 my $safe_text = $MM->quote_literal($text);
321 This will quote $text so it is interpreted literally in the shell.
323 For example, on Unix this would escape any single-quotes in $text and
324 put single-quotes around the whole thing.
327 =head3 escape_newlines I<Abstract>
329 my $escaped_text = $MM->escape_newlines($text);
331 Shell escapes newlines in $text.
334 =head3 max_exec_len I<Abstract>
336 my $max_exec_len = $MM->max_exec_len;
338 Calculates the maximum command size the OS can exec. Effectively,
339 this is the max size of a shell command line.
342 $self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes.
347 my $make = $MM->make;
349 Returns the make variant we're generating the Makefile for. This attempts
350 to do some normalization on the information from %Config or the user.
357 my $make = lc $self->{MAKE};
359 # Truncate anything like foomake6 to just foomake.
360 $make =~ s/^(\w+make).*/$1/;
362 # Turn gnumake into gmake.
371 These are methods which produce make targets.
376 Generate the default target 'all'.
391 =head3 blibdirs_target
393 my $make_frag = $mm->blibdirs_target;
395 Creates the blibdirs target which creates all the directories we use
398 The blibdirs.ts target is deprecated. Depend on blibdirs instead.
403 sub blibdirs_target {
406 my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib
412 my @exists = map { $_.'$(DFSEP).exists' } @dirs;
414 my $make = sprintf <<'MAKE', join(' ', @exists);
418 # Backwards compat with 6.18 through 6.25
419 blibdirs.ts : blibdirs
424 $make .= $self->dir_target(@dirs);
432 Defines the clean target.
437 # --- Cleanup and Distribution Sections ---
439 my($self, %attribs) = @_;
442 # Delete temporary files but do not touch installed files. We don\'t delete
443 # the Makefile here so a later make realclean still has a makefile to use.
445 clean :: clean_subdirs
448 my @files = values %{$self->{XS}}; # .c files from *.xs files
451 # Normally these are all under blib but they might have been
453 # XXX normally this would be a good idea, but the Perl core sets
454 # INST_LIB = ../../lib rather than actually installing the files.
455 # So a "make clean" in an ext/ directory would blow away lib.
456 # Until the core is adjusted let's leave this out.
457 # push @dirs, qw($(INST_ARCHLIB) $(INST_LIB)
458 # $(INST_BIN) $(INST_SCRIPT)
459 # $(INST_MAN1DIR) $(INST_MAN3DIR)
460 # $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR)
461 # $(INST_STATIC) $(INST_DYNAMIC) $(INST_BOOT)
465 if( $attribs{FILES} ) {
466 # Use @dirs because we don't know what's in here.
467 push @dirs, ref $attribs{FILES} ?
469 split /\s+/, $attribs{FILES} ;
472 push(@files, qw[$(MAKE_APERL_FILE)
473 perlmain.c tmon.out mon.out so_locations
474 blibdirs.ts pm_to_blib pm_to_blib.ts
475 *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
476 $(BOOTSTRAP) $(BASEEXT).bso
477 $(BASEEXT).def lib$(BASEEXT).def
478 $(BASEEXT).exp $(BASEEXT).x
481 push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
482 push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld'));
485 push(@files, qw[core core.*perl.*.? *perl.core]);
486 push(@files, map { "core." . "[0-9]"x$_ } (1..5));
488 # OS specific things to clean up. Use @dirs since we don't know
489 # what might be in here.
490 push @dirs, $self->extra_clean_files;
492 # Occasionally files are repeated several times from different sources
493 { my(%f) = map { ($_ => 1) } @files; @files = keys %f; }
494 { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; }
496 push @m, map "\t$_\n", $self->split_command('- $(RM_F)', @files);
497 push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs);
499 # Leave Makefile.old around for realclean
501 - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL)
504 push(@m, "\t$attribs{POSTOP}\n") if $attribs{POSTOP};
510 =head3 clean_subdirs_target
512 my $make_frag = $MM->clean_subdirs_target;
514 Returns the clean_subdirs target. This is used by the clean target to
515 call clean on any subdirectories which contain Makefiles.
519 sub clean_subdirs_target {
522 # No subdirectories, no cleaning.
523 return <<'NOOP_FRAG' unless @{$self->{DIR}};
529 my $clean = "clean_subdirs :\n";
531 for my $dir (@{$self->{DIR}}) {
532 my $subclean = $self->oneliner(sprintf <<'CODE', $dir);
533 chdir '%s'; system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)';
536 $clean .= "\t$subclean\n";
545 my $make_frag = $mm->dir_target(@directories);
547 Generates targets to create the specified directories and set its
550 Because depending on a directory to just ensure it exists doesn't work
551 too well (the modified time changes too often) dir_target() creates a
552 .exists file in the created directory. It is this you should depend on.
553 For portability purposes you should use the $(DIRFILESEP) macro rather
554 than a '/' to seperate the directory from the file.
556 yourdirectory$(DIRFILESEP).exists
561 my($self, @dirs) = @_;
564 foreach my $dir (@dirs) {
565 $make .= sprintf <<'MAKE', ($dir) x 7;
566 %s$(DFSEP).exists :: Makefile.PL
567 $(NOECHO) $(MKPATH) %s
568 $(NOECHO) $(CHMOD) 755 %s
569 $(NOECHO) $(TOUCH) %s$(DFSEP).exists
581 Defines the scratch directory target that will hold the distribution
582 before tar-ing (or shar-ing).
586 # For backwards compatibility.
587 *dist_dir = *distdir;
592 my $meta_target = $self->{NO_META} ? '' : 'distmeta';
593 my $sign_target = !$self->{SIGN} ? '' : 'distsignature';
595 return sprintf <<'MAKE_FRAG', $meta_target, $sign_target;
597 $(RM_RF) $(DISTVNAME)
598 $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
599 -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
601 distdir : create_distdir %s %s
611 Defines a target that produces the distribution in the
612 scratchdirectory, and runs 'perl Makefile.PL; make ;make test' in that
620 my $mpl_args = join " ", map qq["$_"], @ARGV;
622 my $test = $self->cd('$(DISTVNAME)',
623 '$(ABSPERLRUN) Makefile.PL '.$mpl_args,
624 '$(MAKE) $(PASTHRU)',
625 '$(MAKE) test $(PASTHRU)'
628 return sprintf <<'MAKE_FRAG', $test;
640 Defines the dynamic target.
645 # --- Dynamic Loading Sections ---
649 dynamic :: $(FIRST_MAKEFILE) $(INST_DYNAMIC) $(INST_BOOT)
655 =head3 makemakerdflt_target
657 my $make_frag = $mm->makemakerdflt_target
659 Returns a make fragment with the makemakerdeflt_target specified.
660 This target is the first target in the Makefile, is the default target
661 and simply points off to 'all' just in case any make variant gets
662 confused or something gets snuck in before the real 'all' target.
666 sub makemakerdflt_target {
667 return <<'MAKE_FRAG';
675 =head3 manifypods_target
677 my $manifypods_target = $self->manifypods_target;
679 Generates the manifypods target. This target generates man pages from
680 all POD files in MAN1PODS and MAN3PODS.
684 sub manifypods_target {
689 my $dependencies = '';
691 # populate manXpods & dependencies:
692 foreach my $name (keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}}) {
693 $dependencies .= " \\\n\t$name";
697 manifypods : pure_all $dependencies
701 foreach my $section (qw(1 3)) {
702 my $pods = $self->{"MAN${section}PODS"};
703 push @man_cmds, $self->split_command(<<CMD, %$pods);
704 \$(NOECHO) \$(POD2MAN) --section=$section --perm_rw=\$(PERM_RW)
708 $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds;
709 $manify .= join '', map { "$_\n" } @man_cmds;
715 =head3 metafile_target
717 my $target = $mm->metafile_target;
719 Generate the metafile target.
721 Writes the file META.yml YAML encoded meta-data about the module in
722 the distdir. The format follows Module::Build's as closely as
727 sub metafile_target {
730 return <<'MAKE_FRAG' if $self->{NO_META};
735 my @metadata = $self->metafile_data(
736 $self->{META_ADD} || {},
737 $self->{META_MERGE} || {},
739 my $meta = $self->metafile_file(@metadata);
740 my @write_meta = $self->echo($meta, 'META_new.yml');
742 return sprintf <<'MAKE_FRAG', join("\n\t", @write_meta);
743 metafile : create_distdir
744 $(NOECHO) $(ECHO) Generating META.yml
746 -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml
756 my @pairs = _sort_pairs($sort_sub, \%hash);
758 Sorts the pairs of a hash based on keys ordered according
768 return map { $_ => $pairs->{$_} }
774 # Taken from Module::Build::Base
776 my ($self, $h, $k, $v) = @_;
777 if (ref $h->{$k} eq 'ARRAY') {
778 push @{$h->{$k}}, ref $v ? @$v : $v;
779 } elsif (ref $h->{$k} eq 'HASH') {
780 $self->_hash_merge($h->{$k}, $_, $v->{$_}) foreach keys %$v;
789 my @metadata_pairs = $mm->metafile_data(\%meta_add, \%meta_merge);
791 Returns the data which MakeMaker turns into the META.yml file.
793 Values of %meta_add will overwrite any existing metadata in those
794 keys. %meta_merge will be merged with them.
800 my($meta_add, $meta_merge) = @_;
802 # The order in which standard meta keys should be written.
825 name => $self->{DISTNAME},
826 version => $self->{VERSION},
827 abstract => $self->{ABSTRACT},
828 license => $self->{LICENSE} || 'unknown',
829 distribution_type => $self->{PM} ? 'module' : 'script',
831 configure_requires => {
832 'ExtUtils::MakeMaker' => 0
836 'ExtUtils::MakeMaker' => 0
840 directory => [qw(t inc)]
843 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
845 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
850 # The author key is required and it takes a list.
851 $meta{author} = defined $self->{AUTHOR} ? [$self->{AUTHOR}] : [];
853 $meta{requires} = $self->{PREREQ_PM} if defined $self->{PREREQ_PM};
854 $meta{requires}{perl} = $self->{MIN_PERL_VERSION} if $self->{MIN_PERL_VERSION};
856 while( my($key, $val) = each %$meta_add ) {
860 while( my($key, $val) = each %$meta_merge ) {
861 $self->_hash_merge(\%meta, $key, $val);
866 # Put the standard keys first in the proper order.
867 for my $key (@meta_order) {
868 next unless exists $meta{$key};
870 push @meta_pairs, $key, delete $meta{$key};
873 # Then tack everything else onto the end, alpha sorted.
874 for my $key (sort {lc $a cmp lc $b} keys %meta) {
875 push @meta_pairs, $key, $meta{$key};
885 $yaml = _dump_hash(\%options, %hash);
887 Implements a fake YAML dumper for a hash given
888 as a list of pairs. No quoting/escaping is done. Keys
889 are supposed to be strings. Values are undef, strings,
890 hash refs or array refs of strings.
892 Supported options are:
894 delta => STR - indentation delta
895 use_header => BOOL - whether to include a YAML header
896 indent => STR - a string of spaces
899 max_key_length => INT - maximum key length used to align
900 keys and values of the same hash
902 key_sort => CODE - a sort sub
903 It may be undef, which means no sorting by keys
904 default: sub { lc $a cmp lc $b }
906 customs => HASH - special options for certain keys
907 (whose values are hashes themselves)
908 may contain: max_key_length, key_sort, customs
915 croak "first argument should be a hash ref" unless ref $_[0] eq 'HASH';
919 # Use a list to preserve order.
923 = exists $options->{key_sort} ? $options->{key_sort}
924 : sub { lc $a cmp lc $b };
926 croak "'key_sort' should be a coderef" unless ref $k_sort eq 'CODE';
927 @pairs = _sort_pairs($k_sort, \%hash);
928 } else { # list of pairs, no sorting
932 my $yaml = $options->{use_header} ? "--- #YAML:1.0\n" : '';
933 my $indent = $options->{indent} || '';
935 ($options->{max_key_length} || 20),
936 max(map { length($_) + 1 } grep { !ref $hash{$_} } keys %hash)
938 my $customs = $options->{customs} || {};
940 # printf format for key
941 my $k_format = "%-${k_length}s";
944 my($key, $val) = splice @pairs, 0, 2;
945 $val = '~' unless defined $val;
946 if(ref $val eq 'HASH') {
948 my %k_options = ( # options for recursive call
949 delta => $options->{delta},
951 indent => $indent . $options->{delta},
953 if (exists $customs->{$key}) {
954 my %k_custom = %{$customs->{$key}};
955 foreach my $k qw(key_sort max_key_length customs) {
956 $k_options{$k} = $k_custom{$k} if exists $k_custom{$k};
959 $yaml .= $indent . "$key:\n"
960 . _dump_hash(\%k_options, %$val);
963 $yaml .= $indent . "$key: {}\n";
966 elsif (ref $val eq 'ARRAY') {
968 $yaml .= $indent . "$key:\n";
971 croak "only nested arrays of non-refs are supported" if ref $_;
972 $yaml .= $indent . $options->{delta} . "- $_\n";
976 $yaml .= $indent . "$key: []\n";
979 elsif( ref $val and !blessed($val) ) {
980 croak "only nested hashes, arrays and objects are supported";
982 else { # if it's an object, just stringify it
983 $yaml .= $indent . sprintf "$k_format %s\n", "$key:", $val;
992 return eval { $_[0]->isa("UNIVERSAL"); };
996 return (sort { $b <=> $a } @_)[0];
1000 return (sort { $a <=> $b } @_)[0];
1003 =head3 metafile_file
1005 my $meta_yml = $mm->metafile_file(@metadata_pairs);
1007 Turns the @metadata_pairs into YAML.
1009 This method does not implement a complete YAML dumper, being limited
1010 to dump a hash with values which are strings, undef's or nested hashes
1011 and arrays of strings. No quoting/escaping is done.
1018 my %dump_options = (
1023 return _dump_hash(\%dump_options, @_);
1028 =head3 distmeta_target
1030 my $make_frag = $mm->distmeta_target;
1032 Generates the distmeta target to add META.yml to the MANIFEST in the
1037 sub distmeta_target {
1040 my $add_meta = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
1041 eval { maniadd({q{META.yml} => q{Module meta-data (added by MakeMaker)}}) }
1042 or print "Could not add META.yml to MANIFEST: $${'@'}\n"
1045 my $add_meta_to_distdir = $self->cd('$(DISTVNAME)', $add_meta);
1047 return sprintf <<'MAKE', $add_meta_to_distdir;
1048 distmeta : create_distdir metafile
1056 =head3 realclean (o)
1058 Defines the realclean target.
1063 my($self, %attribs) = @_;
1065 my @dirs = qw($(DISTVNAME));
1066 my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD));
1068 # Special exception for the perl core where INST_* is not in blib.
1069 # This cleans up the files built from the ext/ directory (all XS).
1070 if( $self->{PERL_CORE} ) {
1071 push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR));
1072 push @files, values %{$self->{PM}};
1075 if( $self->has_link_code ){
1076 push @files, qw($(OBJECT));
1079 if( $attribs{FILES} ) {
1080 if( ref $attribs{FILES} ) {
1081 push @dirs, @{ $attribs{FILES} };
1084 push @dirs, split /\s+/, $attribs{FILES};
1088 # Occasionally files are repeated several times from different sources
1089 { my(%f) = map { ($_ => 1) } @files; @files = keys %f; }
1090 { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; }
1092 my $rm_cmd = join "\n\t", map { "$_" }
1093 $self->split_command('- $(RM_F)', @files);
1094 my $rmf_cmd = join "\n\t", map { "$_" }
1095 $self->split_command('- $(RM_RF)', @dirs);
1097 my $m = sprintf <<'MAKE', $rm_cmd, $rmf_cmd;
1098 # Delete temporary files (via clean) and also delete dist files
1099 realclean purge :: clean realclean_subdirs
1104 $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP};
1110 =head3 realclean_subdirs_target
1112 my $make_frag = $MM->realclean_subdirs_target;
1114 Returns the realclean_subdirs target. This is used by the realclean
1115 target to call realclean on any subdirectories which contain Makefiles.
1119 sub realclean_subdirs_target {
1122 return <<'NOOP_FRAG' unless @{$self->{DIR}};
1127 my $rclean = "realclean_subdirs :\n";
1129 foreach my $dir (@{$self->{DIR}}) {
1130 foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) {
1131 my $subrclean .= $self->oneliner(sprintf <<'CODE', $dir, ($makefile) x 2);
1132 chdir '%s'; system '$(MAKE) $(USEMAKEFILE) %s realclean' if -f '%s';
1135 $rclean .= sprintf <<'RCLEAN', $subrclean;
1146 =head3 signature_target
1148 my $target = $mm->signature_target;
1150 Generate the signature target.
1152 Writes the file SIGNATURE with "cpansign -s".
1156 sub signature_target {
1159 return <<'MAKE_FRAG';
1167 =head3 distsignature_target
1169 my $make_frag = $mm->distsignature_target;
1171 Generates the distsignature target to add SIGNATURE to the MANIFEST in the
1176 sub distsignature_target {
1179 my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
1180 eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) }
1181 or print "Could not add SIGNATURE to MANIFEST: $${'@'}\n"
1184 my $sign_dist = $self->cd('$(DISTVNAME)' => 'cpansign -s');
1186 # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not
1188 my $touch_sig = $self->cd('$(DISTVNAME)' => '$(TOUCH) SIGNATURE');
1189 my $add_sign_to_dist = $self->cd('$(DISTVNAME)' => $add_sign );
1191 return sprintf <<'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist
1192 distsignature : create_distdir
1202 =head3 special_targets
1204 my $make_frag = $mm->special_targets
1206 Returns a make fragment containing any targets which have special
1207 meaning to make. For example, .SUFFIXES and .PHONY.
1211 sub special_targets {
1212 my $make_frag = <<'MAKE_FRAG';
1213 .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)
1215 .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir
1219 $make_frag .= <<'MAKE_FRAG' if $ENV{CLEARCASE_ROOT};
1220 .NO_CONFIG_REC: Makefile
1232 Methods which help initialize the MakeMaker object and macros.
1235 =head3 init_ABSTRACT
1244 if( $self->{ABSTRACT_FROM} and $self->{ABSTRACT} ) {
1245 warn "Both ABSTRACT_FROM and ABSTRACT are set. ".
1246 "Ignoring ABSTRACT_FROM.\n";
1250 if ($self->{ABSTRACT_FROM}){
1251 $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or
1252 carp "WARNING: Setting ABSTRACT via file ".
1253 "'$self->{ABSTRACT_FROM}' failed\n";
1261 Called by init_main. Sets up all INST_* variables except those related
1262 to XS code. Those are handled in init_xs.
1269 $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch");
1270 $self->{INST_BIN} ||= $self->catdir($Curdir,'blib','bin');
1272 # INST_LIB typically pre-set if building an extension after
1273 # perl has been built and installed. Setting INST_LIB allows
1274 # you to build directly into, say $Config{privlibexp}.
1275 unless ($self->{INST_LIB}){
1276 if ($self->{PERL_CORE}) {
1277 if (defined $Cross::platform) {
1278 $self->{INST_LIB} = $self->{INST_ARCHLIB} =
1279 $self->catdir($self->{PERL_LIB},"..","xlib",
1283 $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
1286 $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib");
1290 my @parentdir = split(/::/, $self->{PARENT_NAME});
1291 $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)', @parentdir);
1292 $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)', @parentdir);
1293 $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)', 'auto',
1295 $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto',
1298 $self->{INST_SCRIPT} ||= $self->catdir($Curdir,'blib','script');
1300 $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1');
1301 $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3');
1311 Called by init_main. Sets up all INSTALL_* variables (except
1312 INSTALLDIRS) and *PREFIX.
1319 if( $self->{ARGS}{INSTALL_BASE} and $self->{ARGS}{PREFIX} ) {
1320 die "Only one of PREFIX or INSTALL_BASE can be given. Not both.\n";
1323 if( $self->{ARGS}{INSTALL_BASE} ) {
1324 $self->init_INSTALL_from_INSTALL_BASE;
1327 $self->init_INSTALL_from_PREFIX;
1332 =head3 init_INSTALL_from_PREFIX
1334 $mm->init_INSTALL_from_PREFIX;
1338 sub init_INSTALL_from_PREFIX {
1341 $self->init_lib2arch;
1343 # There are often no Config.pm defaults for these new man variables so
1344 # we fall back to the old behavior which is to use installman*dir
1345 foreach my $num (1, 3) {
1346 my $k = 'installsiteman'.$num.'dir';
1348 $self->{uc $k} ||= uc "\$(installman${num}dir)"
1352 foreach my $num (1, 3) {
1353 my $k = 'installvendorman'.$num.'dir';
1355 unless( $Config{$k} ) {
1356 $self->{uc $k} ||= $Config{usevendorprefix}
1357 ? uc "\$(installman${num}dir)"
1362 $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)'
1363 unless $Config{installsitebin};
1364 $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)'
1365 unless $Config{installsitescript};
1367 unless( $Config{installvendorbin} ) {
1368 $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix}
1369 ? $Config{installbin}
1372 unless( $Config{installvendorscript} ) {
1373 $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix}
1374 ? $Config{installscript}
1379 my $iprefix = $Config{installprefixexp} || $Config{installprefix} ||
1380 $Config{prefixexp} || $Config{prefix} || '';
1381 my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : '';
1382 my $sprefix = $Config{siteprefixexp} || '';
1384 # 5.005_03 doesn't have a siteprefix.
1385 $sprefix = $iprefix unless $sprefix;
1388 $self->{PREFIX} ||= '';
1390 if( $self->{PREFIX} ) {
1391 @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} =
1395 $self->{PERLPREFIX} ||= $iprefix;
1396 $self->{SITEPREFIX} ||= $sprefix;
1397 $self->{VENDORPREFIX} ||= $vprefix;
1399 # Lots of MM extension authors like to use $(PREFIX) so we
1400 # put something sensible in there no matter what.
1401 $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)';
1404 my $arch = $Config{archname};
1405 my $version = $Config{version};
1408 my $libstyle = $Config{installstyle} || 'lib/perl5';
1411 if( $self->{LIBSTYLE} ) {
1412 $libstyle = $self->{LIBSTYLE};
1413 $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : '';
1416 # Some systems, like VOS, set installman*dir to '' if they can't
1418 for my $num (1, 3) {
1419 $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none'
1420 unless $Config{'installman'.$num.'dir'};
1425 bin => { s => $iprefix,
1428 vendorbin => { s => $vprefix,
1431 sitebin => { s => $sprefix,
1434 script => { s => $iprefix,
1437 vendorscript=> { s => $vprefix,
1440 sitescript => { s => $sprefix,
1447 man1dir => { s => $iprefix,
1450 style => $manstyle, },
1451 siteman1dir => { s => $sprefix,
1454 style => $manstyle, },
1455 vendorman1dir => { s => $vprefix,
1458 style => $manstyle, },
1460 man3dir => { s => $iprefix,
1463 style => $manstyle, },
1464 siteman3dir => { s => $sprefix,
1467 style => $manstyle, },
1468 vendorman3dir => { s => $vprefix,
1471 style => $manstyle, },
1476 privlib => { s => $iprefix,
1479 style => $libstyle, },
1480 vendorlib => { s => $vprefix,
1483 style => $libstyle, },
1484 sitelib => { s => $sprefix,
1487 style => $libstyle, },
1489 archlib => { s => $iprefix,
1491 d => "$version/$arch",
1492 style => $libstyle },
1493 vendorarch => { s => $vprefix,
1495 d => "$version/$arch",
1496 style => $libstyle },
1497 sitearch => { s => $sprefix,
1499 d => "site_perl/$version/$arch",
1500 style => $libstyle },
1504 # Special case for LIB.
1505 if( $self->{LIB} ) {
1506 foreach my $var (keys %lib_layouts) {
1507 my $Installvar = uc "install$var";
1509 if( $var =~ /arch/ ) {
1510 $self->{$Installvar} ||=
1511 $self->catdir($self->{LIB}, $Config{archname});
1514 $self->{$Installvar} ||= $self->{LIB};
1519 my %type2prefix = ( perl => 'PERLPREFIX',
1520 site => 'SITEPREFIX',
1521 vendor => 'VENDORPREFIX'
1524 my %layouts = (%bin_layouts, %man_layouts, %lib_layouts);
1525 while( my($var, $layout) = each(%layouts) ) {
1526 my($s, $t, $d, $style) = @{$layout}{qw(s t d style)};
1527 my $r = '$('.$type2prefix{$t}.')';
1529 print STDERR "Prefixing $var\n" if $Verbose >= 2;
1531 my $installvar = "install$var";
1532 my $Installvar = uc $installvar;
1533 next if $self->{$Installvar};
1535 $d = "$style/$d" if $style;
1536 $self->prefixify($installvar, $s, $r, $d);
1538 print STDERR " $Installvar == $self->{$Installvar}\n"
1542 # Generate these if they weren't figured out.
1543 $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH};
1544 $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB};
1550 =head3 init_from_INSTALL_BASE
1552 $mm->init_from_INSTALL_BASE
1557 lib => [qw(lib perl5)],
1558 arch => [('lib', 'perl5', $Config{archname})],
1560 man1dir => [qw(man man1)],
1561 man3dir => [qw(man man3)]
1563 $map{script} = $map{bin};
1565 sub init_INSTALL_from_INSTALL_BASE {
1568 @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} =
1572 foreach my $thing (keys %map) {
1573 foreach my $dir (('', 'SITE', 'VENDOR')) {
1574 my $uc_thing = uc $thing;
1575 my $key = "INSTALL".$dir.$uc_thing;
1578 $self->catdir('$(INSTALL_BASE)', @{$map{$thing}});
1582 # Adjust for variable quirks.
1583 $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH};
1584 $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB};
1586 foreach my $key (keys %install) {
1587 $self->{$key} ||= $install{$key};
1594 =head3 init_VERSION I<Abstract>
1598 Initialize macros representing versions of MakeMaker and other tools
1600 MAKEMAKER: path to the MakeMaker module.
1602 MM_VERSION: ExtUtils::MakeMaker Version
1604 MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards
1607 VERSION: version of your module
1609 VERSION_MACRO: which macro represents the version (usually 'VERSION')
1611 VERSION_SYM: like version but safe for use as an RCS revision number
1613 DEFINE_VERSION: -D line to set the module version when compiling
1615 XS_VERSION: version in your .xs file. Defaults to $(VERSION)
1617 XS_VERSION_MACRO: which macro represents the XS version.
1619 XS_DEFINE_VERSION: -D line to set the xs version when compiling.
1621 Called by init_main.
1628 $self->{MAKEMAKER} = $ExtUtils::MakeMaker::Filename;
1629 $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION;
1630 $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision;
1631 $self->{VERSION_FROM} ||= '';
1633 if ($self->{VERSION_FROM}){
1634 $self->{VERSION} = $self->parse_version($self->{VERSION_FROM});
1635 if( $self->{VERSION} eq 'undef' ) {
1636 carp("WARNING: Setting VERSION via file ".
1637 "'$self->{VERSION_FROM}' failed\n");
1642 if (defined $self->{VERSION}) {
1643 $self->{VERSION} =~ s/^\s+//;
1644 $self->{VERSION} =~ s/\s+$//;
1647 $self->{VERSION} = '';
1651 $self->{VERSION_MACRO} = 'VERSION';
1652 ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
1653 $self->{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"';
1656 # Graham Barr and Paul Marquess had some ideas how to ensure
1657 # version compatibility between the *.pm file and the
1658 # corresponding *.xs file. The bottomline was, that we need an
1659 # XS_VERSION macro that defaults to VERSION:
1660 $self->{XS_VERSION} ||= $self->{VERSION};
1662 $self->{XS_VERSION_MACRO} = 'XS_VERSION';
1663 $self->{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"';
1668 =head3 init_others I<Abstract>
1672 Initializes the macro definitions used by tools_other() and places them
1675 If there is no description, its the same as the parameter to
1676 WriteMakefile() documented in ExtUtils::MakeMaker.
1678 Defines at least these macros.
1683 NOECHO Tell make not to display the command itself
1688 MAKE_APERL_FILE File used by MAKE_APERL
1690 SHELL Program used to run shell commands
1692 ECHO Print text adding a newline on the end
1694 RM_RF Remove a directory
1695 TOUCH Update a file's timestamp
1696 TEST_F Test for a file's existence
1699 CHMOD Change permissions on a
1702 UMASK_NULL Nullify umask
1703 DEV_NULL Suppress all command output
1706 =head3 init_DIRFILESEP I<Abstract>
1708 $MM->init_DIRFILESEP;
1709 my $dirfilesep = $MM->{DIRFILESEP};
1711 Initializes the DIRFILESEP macro which is the seperator between the
1712 directory and filename in a filepath. ie. / on Unix, \ on Win32 and
1717 # instead of $(INST_ARCHAUTODIR)/extralibs.ld
1718 $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld
1720 Something of a hack but it prevents a lot of code duplication between
1723 Do not use this as a seperator between directories. Some operating
1724 systems use different seperators between subdirectories as between
1725 directories and filenames (for example: VOLUME:[dir1.dir2]file on VMS).
1727 =head3 init_linker I<Abstract>
1731 Initialize macros which have to do with linking.
1733 PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic
1736 PERL_ARCHIVE_AFTER: path to a library which should be put on the
1737 linker command line I<after> the external libraries to be linked to
1738 dynamic extensions. This may be needed if the linker is one-pass, and
1739 Perl includes some overrides for C RTL functions, such as malloc().
1741 EXPORT_LIST: name of a file that is passed to linker to define symbols
1744 Some OSes do not need these in which case leave it blank.
1747 =head3 init_platform
1751 Initialize any macros which are for platform specific use only.
1753 A typical one is the version number of your OS specific mocule.
1754 (ie. MM_Unix_VERSION or MM_VMS_VERSION).
1767 Initialize MAKE from either a MAKE environment variable or $Config{make}.
1774 $self->{MAKE} ||= $ENV{MAKE} || $Config{make};
1780 A grab bag of methods to generate specific macros and commands.
1786 Defines targets and routines to translate the pods into manpages and
1787 put them into the INST_* directories.
1794 my $POD2MAN_macro = $self->POD2MAN_macro();
1795 my $manifypods_target = $self->manifypods_target();
1797 return <<END_OF_TARGET;
1808 =head3 POD2MAN_macro
1810 my $pod2man_macro = $self->POD2MAN_macro
1812 Returns a definition for the POD2MAN macro. This is a program
1813 which emulates the pod2man utility. You can add more switches to the
1814 command by simply appending them on the macro.
1818 $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ...
1825 # Need the trailing '--' so perl stops gobbling arguments and - happens
1826 # to be an alternative end of line seperator on VMS so we quote it
1827 return <<'END_OF_DEF';
1828 POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--"
1829 POD2MAN = $(POD2MAN_EXE)
1834 =head3 test_via_harness
1836 my $command = $mm->test_via_harness($perl, $tests);
1838 Returns a $command line which runs the given set of $tests with
1839 Test::Harness and the given $perl.
1841 Used on the t/*.t files.
1845 sub test_via_harness {
1846 my($self, $perl, $tests) = @_;
1848 return qq{\t$perl "-MExtUtils::Command::MM" }.
1849 qq{"-e" "test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n};
1852 =head3 test_via_script
1854 my $command = $mm->test_via_script($perl, $script);
1856 Returns a $command line which just runs a single test without
1857 Test::Harness. No checks are done on the results, they're just
1860 Used for test.pl, since they don't always follow Test::Harness
1865 sub test_via_script {
1866 my($self, $perl, $script) = @_;
1867 return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n};
1871 =head3 tool_autosplit
1873 Defines a simple perl call that runs autosplit. May be deprecated by
1878 sub tool_autosplit {
1879 my($self, %attribs) = @_;
1881 my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};'
1884 my $asplit = $self->oneliner(sprintf <<'PERL_CODE', $maxlen);
1885 use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1)
1888 return sprintf <<'MAKE_FRAG', $asplit;
1889 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
1899 =head2 File::Spec wrappers
1901 ExtUtils::MM_Any is a subclass of File::Spec. The methods noted here
1902 override File::Spec.
1908 File::Spec <= 0.83 has a bug where the file part of catfile is not
1909 canonicalized. This override fixes that bug.
1915 return $self->canonpath($self->SUPER::catfile(@_));
1922 Methods I can't really figure out where they should go yet.
1927 my $test = $mm->find_tests;
1929 Returns a string suitable for feeding to the shell to return all
1936 return -d 't' ? 't/*.t' : '';
1940 =head3 extra_clean_files
1942 my @files_to_clean = $MM->extra_clean_files;
1944 Returns a list of OS specific files to be removed in the clean target in
1945 addition to the usual set.
1949 # An empty method here tickled a perl 5.8.1 bug and would return its object.
1950 sub extra_clean_files {
1957 my @installvars = $mm->installvars;
1959 A list of all the INSTALL* variables without the INSTALL prefix. Useful
1960 for iteration or building related variable sets.
1965 return qw(PRIVLIB SITELIB VENDORLIB
1966 ARCHLIB SITEARCH VENDORARCH
1967 BIN SITEBIN VENDORBIN
1968 SCRIPT SITESCRIPT VENDORSCRIPT
1969 MAN1DIR SITEMAN1DIR VENDORMAN1DIR
1970 MAN3DIR SITEMAN3DIR VENDORMAN3DIR
1977 my $wanted = $self->libscan($path);
1979 Takes a path to a file or dir and returns an empty string if we don't
1980 want to include this file in the library. Otherwise it returns the
1981 the $path unchanged.
1983 Mainly used to exclude version control administrative directories from
1989 my($self,$path) = @_;
1990 my($dirs,$file) = ($self->splitpath($path))[1,2];
1991 return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/,
1992 $self->splitdir($dirs), $file;
1998 =head3 platform_constants
2000 my $make_frag = $mm->platform_constants
2002 Returns a make fragment defining all the macros initialized in
2003 init_platform() rather than put them in constants().
2007 sub platform_constants {
2014 Michael G Schwern <schwern@pobox.com> and the denizens of
2015 makemaker@perl.org with code from ExtUtils::MM_Unix and