1 package ExtUtils::MM_Any;
4 use vars qw($VERSION @ISA);
9 BEGIN { @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')
77 Windows NT ('Win32', 'WinNT')
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 @cmds = $MM->split_command($cmd, @args);
116 Most OS have a maximum command length they can execute at once. Large
117 modules can easily generate commands well past that limit. Its
118 necessary to split long commands up into a series of shorter commands.
120 C<split_command> will return a series of @cmds each processing part of
121 the args. Collectively they will process all the arguments. Each
122 individual line in @cmds will not be longer than the
123 $self->max_exec_len being careful to take into account macro expansion.
125 $cmd should include any switches and repeated initial arguments.
127 If no @args are given, no @cmds will be returned.
129 Pairs of arguments will always be preserved in a single command, this
130 is a heuristic for things like pm_to_blib and pod2man which work on
131 pairs of arguments. This makes things like this safe:
133 $self->split_command($cmd, %pod2man);
139 my($self, $cmd, @args) = @_;
142 return(@cmds) unless @args;
144 # If the command was given as a here-doc, there's probably a trailing
148 # set aside 20% for macro expansion.
149 my $len_left = int($self->max_exec_len * 0.80);
150 $len_left -= length $self->_expand_macros($cmd);
155 while( @next_args = splice(@args, 0, 2) ) {
156 # Two at a time to preserve pairs.
157 my $next_arg_str = "\t ". join ' ', @next_args, "\n";
159 if( !length $arg_str ) {
160 $arg_str .= $next_arg_str
162 elsif( length($arg_str) + length($next_arg_str) > $len_left ) {
163 unshift @args, @next_args;
167 $arg_str .= $next_arg_str;
172 push @cmds, $self->escape_newlines("$cmd \n$arg_str");
180 my($self, $cmd) = @_;
182 $cmd =~ s{\$\((\w+)\)}{
183 defined $self->{$1} ? $self->{$1} : "\$($1)"
191 my @commands = $MM->echo($text);
192 my @commands = $MM->echo($text, $file);
193 my @commands = $MM->echo($text, $file, $appending);
195 Generates a set of @commands which print the $text to a $file.
197 If $file is not given, output goes to STDOUT.
199 If $appending is true the $file will be appended to rather than
205 my($self, $text, $file, $appending) = @_;
208 my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_) }
211 my $redirect = $appending ? '>>' : '>';
212 $cmds[0] .= " $redirect $file";
213 $_ .= " >> $file" foreach @cmds[1..$#cmds];
222 my $args = $mm->wraplist(@list);
224 Takes an array of items and turns them into a well-formatted list of
225 arguments. In most cases this is simply something like:
235 return join " \\\n\t", @_;
239 =head3 cd I<Abstract>
241 my $subdir_cmd = $MM->cd($subdir, @cmds);
243 This will generate a make fragment which runs the @cmds in the given
244 $dir. The rough equivalent to this, except cross platform.
248 Currently $dir can only go down one level. "foo" is fine. "foo/bar" is
249 not. "../foo" is right out.
251 The resulting $subdir_cmd has no leading tab nor trailing newline. This
252 makes it easier to embed in a make string. For example.
254 my $make = sprintf <<'CODE', $subdir_cmd;
262 =head3 oneliner I<Abstract>
264 my $oneliner = $MM->oneliner($perl_code);
265 my $oneliner = $MM->oneliner($perl_code, \@switches);
267 This will generate a perl one-liner safe for the particular platform
268 you're on based on the given $perl_code and @switches (a -e is
269 assumed) suitable for using in a make target. It will use the proper
270 shell quoting and escapes.
272 $(PERLRUN) will be used as perl.
274 Any newlines in $perl_code will be escaped. Leading and trailing
275 newlines will be stripped. Makes this idiom much easier:
277 my $code = $MM->oneliner(<<'CODE', [...switches...]);
282 Usage might be something like:
285 $oneliner = $MM->oneliner('print "Foo\n"');
286 $make = '$oneliner > somefile';
288 All dollar signs must be doubled in the $perl_code if you expect them
289 to be interpreted normally, otherwise it will be considered a make
290 macro. Also remember to quote make macros else it might be used as a
291 bareword. For example:
293 # Assign the value of the $(VERSION_FROM) make macro to $vf.
294 $oneliner = $MM->oneliner('$$vf = "$(VERSION_FROM)"');
296 Its currently very simple and may be expanded sometime in the figure
297 to include more flexible code and switches.
300 =head3 quote_literal I<Abstract>
302 my $safe_text = $MM->quote_literal($text);
304 This will quote $text so it is interpreted literally in the shell.
306 For example, on Unix this would escape any single-quotes in $text and
307 put single-quotes around the whole thing.
310 =head3 escape_newlines I<Abstract>
312 my $escaped_text = $MM->escape_newlines($text);
314 Shell escapes newlines in $text.
317 =head3 max_exec_len I<Abstract>
319 my $max_exec_len = $MM->max_exec_len;
321 Calculates the maximum command size the OS can exec. Effectively,
322 this is the max size of a shell command line.
325 $self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes.
330 my $make = $MM->make;
332 Returns the make variant we're generating the Makefile for. This attempts
333 to do some normalization on the information from %Config or the user.
340 my $make = lc $self->{MAKE};
342 # Truncate anything like foomake6 to just foomake.
343 $make =~ s/^(\w+make).*/$1/;
345 # Turn gnumake into gmake.
354 These are methods which produce make targets.
359 Generate the default target 'all'.
374 =head3 blibdirs_target
376 my $make_frag = $mm->blibdirs_target;
378 Creates the blibdirs target which creates all the directories we use
381 The blibdirs.ts target is deprecated. Depend on blibdirs instead.
386 sub blibdirs_target {
389 my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib
395 my @exists = map { $_.'$(DFSEP).exists' } @dirs;
397 my $make = sprintf <<'MAKE', join(' ', @exists);
401 # Backwards compat with 6.18 through 6.25
402 blibdirs.ts : blibdirs
407 $make .= $self->dir_target(@dirs);
415 Defines the clean target.
420 # --- Cleanup and Distribution Sections ---
422 my($self, %attribs) = @_;
425 # Delete temporary files but do not touch installed files. We don\'t delete
426 # the Makefile here so a later make realclean still has a makefile to use.
428 clean :: clean_subdirs
431 my @files = values %{$self->{XS}}; # .c files from *.xs files
434 # Normally these are all under blib but they might have been
436 # XXX normally this would be a good idea, but the Perl core sets
437 # INST_LIB = ../../lib rather than actually installing the files.
438 # So a "make clean" in an ext/ directory would blow away lib.
439 # Until the core is adjusted let's leave this out.
440 # push @dirs, qw($(INST_ARCHLIB) $(INST_LIB)
441 # $(INST_BIN) $(INST_SCRIPT)
442 # $(INST_MAN1DIR) $(INST_MAN3DIR)
443 # $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR)
444 # $(INST_STATIC) $(INST_DYNAMIC) $(INST_BOOT)
448 if( $attribs{FILES} ) {
449 # Use @dirs because we don't know what's in here.
450 push @dirs, ref $attribs{FILES} ?
452 split /\s+/, $attribs{FILES} ;
455 push(@files, qw[$(MAKE_APERL_FILE)
456 perlmain.c tmon.out mon.out so_locations
457 blibdirs.ts pm_to_blib pm_to_blib.ts
458 *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
459 $(BOOTSTRAP) $(BASEEXT).bso
460 $(BASEEXT).def lib$(BASEEXT).def
461 $(BASEEXT).exp $(BASEEXT).x
464 push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
465 push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld'));
468 push(@files, qw[core core.*perl.*.? *perl.core]);
469 push(@files, map { "core." . "[0-9]"x$_ } (1..5));
471 # OS specific things to clean up. Use @dirs since we don't know
472 # what might be in here.
473 push @dirs, $self->extra_clean_files;
475 # Occasionally files are repeated several times from different sources
476 { my(%f) = map { ($_ => 1) } @files; @files = keys %f; }
477 { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; }
479 push @m, map "\t$_\n", $self->split_command('- $(RM_F)', @files);
480 push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs);
482 # Leave Makefile.old around for realclean
484 - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL)
487 push(@m, "\t$attribs{POSTOP}\n") if $attribs{POSTOP};
493 =head3 clean_subdirs_target
495 my $make_frag = $MM->clean_subdirs_target;
497 Returns the clean_subdirs target. This is used by the clean target to
498 call clean on any subdirectories which contain Makefiles.
502 sub clean_subdirs_target {
505 # No subdirectories, no cleaning.
506 return <<'NOOP_FRAG' unless @{$self->{DIR}};
512 my $clean = "clean_subdirs :\n";
514 for my $dir (@{$self->{DIR}}) {
515 my $subclean = $self->oneliner(sprintf <<'CODE', $dir);
516 chdir '%s'; system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)';
519 $clean .= "\t$subclean\n";
528 my $make_frag = $mm->dir_target(@directories);
530 Generates targets to create the specified directories and set its
533 Because depending on a directory to just ensure it exists doesn't work
534 too well (the modified time changes too often) dir_target() creates a
535 .exists file in the created directory. It is this you should depend on.
536 For portability purposes you should use the $(DIRFILESEP) macro rather
537 than a '/' to seperate the directory from the file.
539 yourdirectory$(DIRFILESEP).exists
544 my($self, @dirs) = @_;
547 foreach my $dir (@dirs) {
548 $make .= sprintf <<'MAKE', ($dir) x 7;
549 %s$(DFSEP).exists :: Makefile.PL
550 $(NOECHO) $(MKPATH) %s
551 $(NOECHO) $(CHMOD) 755 %s
552 $(NOECHO) $(TOUCH) %s$(DFSEP).exists
564 Defines the scratch directory target that will hold the distribution
565 before tar-ing (or shar-ing).
569 # For backwards compatibility.
570 *dist_dir = *distdir;
575 my $meta_target = $self->{NO_META} ? '' : 'distmeta';
576 my $sign_target = !$self->{SIGN} ? '' : 'distsignature';
578 return sprintf <<'MAKE_FRAG', $meta_target, $sign_target;
580 $(RM_RF) $(DISTVNAME)
581 $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
582 -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
584 distdir : create_distdir %s %s
594 Defines a target that produces the distribution in the
595 scratchdirectory, and runs 'perl Makefile.PL; make ;make test' in that
603 my $mpl_args = join " ", map qq["$_"], @ARGV;
605 my $test = $self->cd('$(DISTVNAME)',
606 '$(ABSPERLRUN) Makefile.PL '.$mpl_args,
607 '$(MAKE) $(PASTHRU)',
608 '$(MAKE) test $(PASTHRU)'
611 return sprintf <<'MAKE_FRAG', $test;
623 Defines the dynamic target.
628 # --- Dynamic Loading Sections ---
632 dynamic :: $(FIRST_MAKEFILE) $(INST_DYNAMIC) $(INST_BOOT)
638 =head3 makemakerdflt_target
640 my $make_frag = $mm->makemakerdflt_target
642 Returns a make fragment with the makemakerdeflt_target specified.
643 This target is the first target in the Makefile, is the default target
644 and simply points off to 'all' just in case any make variant gets
645 confused or something gets snuck in before the real 'all' target.
649 sub makemakerdflt_target {
650 return <<'MAKE_FRAG';
658 =head3 manifypods_target
660 my $manifypods_target = $self->manifypods_target;
662 Generates the manifypods target. This target generates man pages from
663 all POD files in MAN1PODS and MAN3PODS.
667 sub manifypods_target {
672 my $dependencies = '';
674 # populate manXpods & dependencies:
675 foreach my $name (keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}}) {
676 $dependencies .= " \\\n\t$name";
679 foreach my $name (keys %{$self->{MAN3PODS}}) {
680 $dependencies .= " \\\n\t$name"
684 manifypods : pure_all $dependencies
688 foreach my $section (qw(1 3)) {
689 my $pods = $self->{"MAN${section}PODS"};
690 push @man_cmds, $self->split_command(<<CMD, %$pods);
691 \$(NOECHO) \$(POD2MAN) --section=$section --perm_rw=\$(PERM_RW)
695 $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds;
696 $manify .= join '', map { "$_\n" } @man_cmds;
702 =head3 metafile_target
704 my $target = $mm->metafile_target;
706 Generate the metafile target.
708 Writes the file META.yml YAML encoded meta-data about the module in
709 the distdir. The format follows Module::Build's as closely as
710 possible. Additionally, we include:
717 sub metafile_target {
720 return <<'MAKE_FRAG' if $self->{NO_META};
726 foreach my $mod ( sort { lc $a cmp lc $b } keys %{$self->{PREREQ_PM}} ) {
727 my $ver = $self->{PREREQ_PM}{$mod};
728 $prereq_pm .= sprintf "\n %-30s %s", "$mod:", $ver;
731 # Use a list to preserve order.
733 name => $self->{DISTNAME},
734 version => $self->{VERSION},
735 abstract => $self->{ABSTRACT},
736 license => $self->{LICENSE} || 'unknown',
738 "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
739 author => $self->{AUTHOR},
740 distribution_type => $self->{PM} ? 'module' : 'script',
743 my $meta = "--- #YAML:1.0\n";
745 while( @meta_to_mm ) {
746 my($key, $val) = splice @meta_to_mm, 0, 2;
748 $val = '~' unless defined $val;
750 $meta .= sprintf "%-20s %s\n", "$key:", $val;
756 url: <http://module-build.sourceforge.net/META-spec-new.html>;
760 $meta .= $self->{EXTRA_META} if $self->{EXTRA_META};
762 my @write_meta = $self->echo($meta, 'META_new.yml');
764 return sprintf <<'MAKE_FRAG', join("\n\t", @write_meta);
765 metafile : create_distdir
766 $(NOECHO) $(ECHO) Generating META.yml
768 -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml
774 =head3 distmeta_target
776 my $make_frag = $mm->distmeta_target;
778 Generates the distmeta target to add META.yml to the MANIFEST in the
783 sub distmeta_target {
786 my $add_meta = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
787 eval { maniadd({q{META.yml} => q{Module meta-data (added by MakeMaker)}}) }
788 or print "Could not add META.yml to MANIFEST: $${'@'}\n"
791 my $add_meta_to_distdir = $self->cd('$(DISTVNAME)', $add_meta);
793 return sprintf <<'MAKE', $add_meta_to_distdir;
794 distmeta : create_distdir metafile
804 Defines the realclean target.
809 my($self, %attribs) = @_;
811 my @dirs = qw($(DISTVNAME));
812 my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD));
814 # Special exception for the perl core where INST_* is not in blib.
815 # This cleans up the files built from the ext/ directory (all XS).
816 if( $self->{PERL_CORE} ) {
817 push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR));
818 push @files, values %{$self->{PM}};
821 if( $self->has_link_code ){
822 push @files, qw($(OBJECT));
825 if( $attribs{FILES} ) {
826 if( ref $attribs{FILES} ) {
827 push @dirs, @{ $attribs{FILES} };
830 push @dirs, split /\s+/, $attribs{FILES};
834 # Occasionally files are repeated several times from different sources
835 { my(%f) = map { ($_ => 1) } @files; @files = keys %f; }
836 { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; }
838 my $rm_cmd = join "\n\t", map { "$_" }
839 $self->split_command('- $(RM_F)', @files);
840 my $rmf_cmd = join "\n\t", map { "$_" }
841 $self->split_command('- $(RM_RF)', @dirs);
843 my $m = sprintf <<'MAKE', $rm_cmd, $rmf_cmd;
844 # Delete temporary files (via clean) and also delete dist files
845 realclean purge :: clean realclean_subdirs
850 $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP};
856 =head3 realclean_subdirs_target
858 my $make_frag = $MM->realclean_subdirs_target;
860 Returns the realclean_subdirs target. This is used by the realclean
861 target to call realclean on any subdirectories which contain Makefiles.
865 sub realclean_subdirs_target {
868 return <<'NOOP_FRAG' unless @{$self->{DIR}};
873 my $rclean = "realclean_subdirs :\n";
875 foreach my $dir (@{$self->{DIR}}) {
876 foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) {
877 my $subrclean .= $self->oneliner(sprintf <<'CODE', $dir, ($makefile) x 2);
878 chdir '%s'; system '$(MAKE) $(USEMAKEFILE) %s realclean' if -f '%s';
881 $rclean .= sprintf <<'RCLEAN', $subrclean;
892 =head3 signature_target
894 my $target = $mm->signature_target;
896 Generate the signature target.
898 Writes the file SIGNATURE with "cpansign -s".
902 sub signature_target {
905 return <<'MAKE_FRAG';
913 =head3 distsignature_target
915 my $make_frag = $mm->distsignature_target;
917 Generates the distsignature target to add SIGNATURE to the MANIFEST in the
922 sub distsignature_target {
925 my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
926 eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) }
927 or print "Could not add SIGNATURE to MANIFEST: $${'@'}\n"
930 my $sign_dist = $self->cd('$(DISTVNAME)' => 'cpansign -s');
932 # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not
934 my $touch_sig = $self->cd('$(DISTVNAME)' => '$(TOUCH) SIGNATURE');
935 my $add_sign_to_dist = $self->cd('$(DISTVNAME)' => $add_sign );
937 return sprintf <<'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist
938 distsignature : create_distdir
948 =head3 special_targets
950 my $make_frag = $mm->special_targets
952 Returns a make fragment containing any targets which have special
953 meaning to make. For example, .SUFFIXES and .PHONY.
957 sub special_targets {
958 my $make_frag = <<'MAKE_FRAG';
959 .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)
961 .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir
965 $make_frag .= <<'MAKE_FRAG' if $ENV{CLEARCASE_ROOT};
966 .NO_CONFIG_REC: Makefile
978 Methods which help initialize the MakeMaker object and macros.
990 if( $self->{ABSTRACT_FROM} and $self->{ABSTRACT} ) {
991 warn "Both ABSTRACT_FROM and ABSTRACT are set. ".
992 "Ignoring ABSTRACT_FROM.\n";
996 if ($self->{ABSTRACT_FROM}){
997 $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or
998 carp "WARNING: Setting ABSTRACT via file ".
999 "'$self->{ABSTRACT_FROM}' failed\n";
1007 Called by init_main. Sets up all INST_* variables except those related
1008 to XS code. Those are handled in init_xs.
1015 $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch");
1016 $self->{INST_BIN} ||= $self->catdir($Curdir,'blib','bin');
1018 # INST_LIB typically pre-set if building an extension after
1019 # perl has been built and installed. Setting INST_LIB allows
1020 # you to build directly into, say $Config{privlibexp}.
1021 unless ($self->{INST_LIB}){
1022 if ($self->{PERL_CORE}) {
1023 if (defined $Cross::platform) {
1024 $self->{INST_LIB} = $self->{INST_ARCHLIB} =
1025 $self->catdir($self->{PERL_LIB},"..","xlib",
1029 $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
1032 $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib");
1036 my @parentdir = split(/::/, $self->{PARENT_NAME});
1037 $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)', @parentdir);
1038 $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)', @parentdir);
1039 $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)', 'auto',
1041 $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto',
1044 $self->{INST_SCRIPT} ||= $self->catdir($Curdir,'blib','script');
1046 $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1');
1047 $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3');
1057 Called by init_main. Sets up all INSTALL_* variables (except
1058 INSTALLDIRS) and *PREFIX.
1065 if( $self->{ARGS}{INSTALL_BASE} and $self->{ARGS}{PREFIX} ) {
1066 die "Only one of PREFIX or INSTALL_BASE can be given. Not both.\n";
1069 if( $self->{ARGS}{INSTALL_BASE} ) {
1070 $self->init_INSTALL_from_INSTALL_BASE;
1073 $self->init_INSTALL_from_PREFIX;
1078 =head3 init_INSTALL_from_PREFIX
1080 $mm->init_INSTALL_from_PREFIX;
1084 sub init_INSTALL_from_PREFIX {
1087 $self->init_lib2arch;
1089 # There are often no Config.pm defaults for these new man variables so
1090 # we fall back to the old behavior which is to use installman*dir
1091 foreach my $num (1, 3) {
1092 my $k = 'installsiteman'.$num.'dir';
1094 $self->{uc $k} ||= uc "\$(installman${num}dir)"
1098 foreach my $num (1, 3) {
1099 my $k = 'installvendorman'.$num.'dir';
1101 unless( $Config{$k} ) {
1102 $self->{uc $k} ||= $Config{usevendorprefix}
1103 ? uc "\$(installman${num}dir)"
1108 $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)'
1109 unless $Config{installsitebin};
1110 $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)'
1111 unless $Config{installsitescript};
1113 unless( $Config{installvendorbin} ) {
1114 $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix}
1115 ? $Config{installbin}
1118 unless( $Config{installvendorscript} ) {
1119 $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix}
1120 ? $Config{installscript}
1125 my $iprefix = $Config{installprefixexp} || $Config{installprefix} ||
1126 $Config{prefixexp} || $Config{prefix} || '';
1127 my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : '';
1128 my $sprefix = $Config{siteprefixexp} || '';
1130 # 5.005_03 doesn't have a siteprefix.
1131 $sprefix = $iprefix unless $sprefix;
1134 $self->{PREFIX} ||= '';
1136 if( $self->{PREFIX} ) {
1137 @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} =
1141 $self->{PERLPREFIX} ||= $iprefix;
1142 $self->{SITEPREFIX} ||= $sprefix;
1143 $self->{VENDORPREFIX} ||= $vprefix;
1145 # Lots of MM extension authors like to use $(PREFIX) so we
1146 # put something sensible in there no matter what.
1147 $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)';
1150 my $arch = $Config{archname};
1151 my $version = $Config{version};
1154 my $libstyle = $Config{installstyle} || 'lib/perl5';
1157 if( $self->{LIBSTYLE} ) {
1158 $libstyle = $self->{LIBSTYLE};
1159 $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : '';
1162 # Some systems, like VOS, set installman*dir to '' if they can't
1164 for my $num (1, 3) {
1165 $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none'
1166 unless $Config{'installman'.$num.'dir'};
1171 bin => { s => $iprefix,
1174 vendorbin => { s => $vprefix,
1177 sitebin => { s => $sprefix,
1180 script => { s => $iprefix,
1183 vendorscript=> { s => $vprefix,
1186 sitescript => { s => $sprefix,
1193 man1dir => { s => $iprefix,
1196 style => $manstyle, },
1197 siteman1dir => { s => $sprefix,
1200 style => $manstyle, },
1201 vendorman1dir => { s => $vprefix,
1204 style => $manstyle, },
1206 man3dir => { s => $iprefix,
1209 style => $manstyle, },
1210 siteman3dir => { s => $sprefix,
1213 style => $manstyle, },
1214 vendorman3dir => { s => $vprefix,
1217 style => $manstyle, },
1222 privlib => { s => $iprefix,
1225 style => $libstyle, },
1226 vendorlib => { s => $vprefix,
1229 style => $libstyle, },
1230 sitelib => { s => $sprefix,
1233 style => $libstyle, },
1235 archlib => { s => $iprefix,
1237 d => "$version/$arch",
1238 style => $libstyle },
1239 vendorarch => { s => $vprefix,
1241 d => "$version/$arch",
1242 style => $libstyle },
1243 sitearch => { s => $sprefix,
1245 d => "site_perl/$version/$arch",
1246 style => $libstyle },
1250 # Special case for LIB.
1251 if( $self->{LIB} ) {
1252 foreach my $var (keys %lib_layouts) {
1253 my $Installvar = uc "install$var";
1255 if( $var =~ /arch/ ) {
1256 $self->{$Installvar} ||=
1257 $self->catdir($self->{LIB}, $Config{archname});
1260 $self->{$Installvar} ||= $self->{LIB};
1265 my %type2prefix = ( perl => 'PERLPREFIX',
1266 site => 'SITEPREFIX',
1267 vendor => 'VENDORPREFIX'
1270 my %layouts = (%bin_layouts, %man_layouts, %lib_layouts);
1271 while( my($var, $layout) = each(%layouts) ) {
1272 my($s, $t, $d, $style) = @{$layout}{qw(s t d style)};
1273 my $r = '$('.$type2prefix{$t}.')';
1275 print STDERR "Prefixing $var\n" if $Verbose >= 2;
1277 my $installvar = "install$var";
1278 my $Installvar = uc $installvar;
1279 next if $self->{$Installvar};
1281 $d = "$style/$d" if $style;
1282 $self->prefixify($installvar, $s, $r, $d);
1284 print STDERR " $Installvar == $self->{$Installvar}\n"
1288 # Generate these if they weren't figured out.
1289 $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH};
1290 $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB};
1296 =head3 init_from_INSTALL_BASE
1298 $mm->init_from_INSTALL_BASE
1303 lib => [qw(lib perl5)],
1304 arch => [('lib', 'perl5', $Config{archname})],
1306 man1dir => [qw(man man1)],
1307 man3dir => [qw(man man3)]
1309 $map{script} = $map{bin};
1311 sub init_INSTALL_from_INSTALL_BASE {
1314 @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} =
1318 foreach my $thing (keys %map) {
1319 foreach my $dir (('', 'SITE', 'VENDOR')) {
1320 my $uc_thing = uc $thing;
1321 my $key = "INSTALL".$dir.$uc_thing;
1324 $self->catdir('$(INSTALL_BASE)', @{$map{$thing}});
1328 # Adjust for variable quirks.
1329 $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH};
1330 $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB};
1332 foreach my $key (keys %install) {
1333 $self->{$key} ||= $install{$key};
1340 =head3 init_VERSION I<Abstract>
1344 Initialize macros representing versions of MakeMaker and other tools
1346 MAKEMAKER: path to the MakeMaker module.
1348 MM_VERSION: ExtUtils::MakeMaker Version
1350 MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards
1353 VERSION: version of your module
1355 VERSION_MACRO: which macro represents the version (usually 'VERSION')
1357 VERSION_SYM: like version but safe for use as an RCS revision number
1359 DEFINE_VERSION: -D line to set the module version when compiling
1361 XS_VERSION: version in your .xs file. Defaults to $(VERSION)
1363 XS_VERSION_MACRO: which macro represents the XS version.
1365 XS_DEFINE_VERSION: -D line to set the xs version when compiling.
1367 Called by init_main.
1374 $self->{MAKEMAKER} = $ExtUtils::MakeMaker::Filename;
1375 $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION;
1376 $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision;
1377 $self->{VERSION_FROM} ||= '';
1379 if ($self->{VERSION_FROM}){
1380 $self->{VERSION} = $self->parse_version($self->{VERSION_FROM});
1381 if( $self->{VERSION} eq 'undef' ) {
1382 carp("WARNING: Setting VERSION via file ".
1383 "'$self->{VERSION_FROM}' failed\n");
1388 if (defined $self->{VERSION}) {
1389 $self->{VERSION} =~ s/^\s+//;
1390 $self->{VERSION} =~ s/\s+$//;
1393 $self->{VERSION} = '';
1397 $self->{VERSION_MACRO} = 'VERSION';
1398 ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
1399 $self->{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"';
1402 # Graham Barr and Paul Marquess had some ideas how to ensure
1403 # version compatibility between the *.pm file and the
1404 # corresponding *.xs file. The bottomline was, that we need an
1405 # XS_VERSION macro that defaults to VERSION:
1406 $self->{XS_VERSION} ||= $self->{VERSION};
1408 $self->{XS_VERSION_MACRO} = 'XS_VERSION';
1409 $self->{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"';
1414 =head3 init_others I<Abstract>
1418 Initializes the macro definitions used by tools_other() and places them
1421 If there is no description, its the same as the parameter to
1422 WriteMakefile() documented in ExtUtils::MakeMaker.
1424 Defines at least these macros.
1429 NOECHO Tell make not to display the command itself
1434 MAKE_APERL_FILE File used by MAKE_APERL
1436 SHELL Program used to run shell commands
1438 ECHO Print text adding a newline on the end
1440 RM_RF Remove a directory
1441 TOUCH Update a file's timestamp
1442 TEST_F Test for a file's existence
1445 CHMOD Change permissions on a
1448 UMASK_NULL Nullify umask
1449 DEV_NULL Suppress all command output
1452 =head3 init_DIRFILESEP I<Abstract>
1454 $MM->init_DIRFILESEP;
1455 my $dirfilesep = $MM->{DIRFILESEP};
1457 Initializes the DIRFILESEP macro which is the seperator between the
1458 directory and filename in a filepath. ie. / on Unix, \ on Win32 and
1463 # instead of $(INST_ARCHAUTODIR)/extralibs.ld
1464 $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld
1466 Something of a hack but it prevents a lot of code duplication between
1469 Do not use this as a seperator between directories. Some operating
1470 systems use different seperators between subdirectories as between
1471 directories and filenames (for example: VOLUME:[dir1.dir2]file on VMS).
1473 =head3 init_linker I<Abstract>
1477 Initialize macros which have to do with linking.
1479 PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic
1482 PERL_ARCHIVE_AFTER: path to a library which should be put on the
1483 linker command line I<after> the external libraries to be linked to
1484 dynamic extensions. This may be needed if the linker is one-pass, and
1485 Perl includes some overrides for C RTL functions, such as malloc().
1487 EXPORT_LIST: name of a file that is passed to linker to define symbols
1490 Some OSes do not need these in which case leave it blank.
1493 =head3 init_platform
1497 Initialize any macros which are for platform specific use only.
1499 A typical one is the version number of your OS specific mocule.
1500 (ie. MM_Unix_VERSION or MM_VMS_VERSION).
1513 Initialize MAKE from either a MAKE environment variable or $Config{make}.
1520 $self->{MAKE} ||= $ENV{MAKE} || $Config{make};
1526 A grab bag of methods to generate specific macros and commands.
1532 Defines targets and routines to translate the pods into manpages and
1533 put them into the INST_* directories.
1540 my $POD2MAN_macro = $self->POD2MAN_macro();
1541 my $manifypods_target = $self->manifypods_target();
1543 return <<END_OF_TARGET;
1554 =head3 POD2MAN_macro
1556 my $pod2man_macro = $self->POD2MAN_macro
1558 Returns a definition for the POD2MAN macro. This is a program
1559 which emulates the pod2man utility. You can add more switches to the
1560 command by simply appending them on the macro.
1564 $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ...
1571 # Need the trailing '--' so perl stops gobbling arguments and - happens
1572 # to be an alternative end of line seperator on VMS so we quote it
1573 return <<'END_OF_DEF';
1574 POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--"
1575 POD2MAN = $(POD2MAN_EXE)
1580 =head3 test_via_harness
1582 my $command = $mm->test_via_harness($perl, $tests);
1584 Returns a $command line which runs the given set of $tests with
1585 Test::Harness and the given $perl.
1587 Used on the t/*.t files.
1591 sub test_via_harness {
1592 my($self, $perl, $tests) = @_;
1594 return qq{\t$perl "-MExtUtils::Command::MM" }.
1595 qq{"-e" "test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n};
1598 =head3 test_via_script
1600 my $command = $mm->test_via_script($perl, $script);
1602 Returns a $command line which just runs a single test without
1603 Test::Harness. No checks are done on the results, they're just
1606 Used for test.pl, since they don't always follow Test::Harness
1611 sub test_via_script {
1612 my($self, $perl, $script) = @_;
1613 return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n};
1617 =head3 tool_autosplit
1619 Defines a simple perl call that runs autosplit. May be deprecated by
1624 sub tool_autosplit {
1625 my($self, %attribs) = @_;
1627 my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};'
1630 my $asplit = $self->oneliner(sprintf <<'PERL_CODE', $maxlen);
1631 use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1)
1634 return sprintf <<'MAKE_FRAG', $asplit;
1635 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
1645 =head2 File::Spec wrappers
1647 ExtUtils::MM_Any is a subclass of File::Spec. The methods noted here
1648 override File::Spec.
1654 File::Spec <= 0.83 has a bug where the file part of catfile is not
1655 canonicalized. This override fixes that bug.
1661 return $self->canonpath($self->SUPER::catfile(@_));
1668 Methods I can't really figure out where they should go yet.
1673 my $test = $mm->find_tests;
1675 Returns a string suitable for feeding to the shell to return all
1682 return -d 't' ? 't/*.t' : '';
1686 =head3 extra_clean_files
1688 my @files_to_clean = $MM->extra_clean_files;
1690 Returns a list of OS specific files to be removed in the clean target in
1691 addition to the usual set.
1695 # An empty method here tickled a perl 5.8.1 bug and would return its object.
1696 sub extra_clean_files {
1703 my @installvars = $mm->installvars;
1705 A list of all the INSTALL* variables without the INSTALL prefix. Useful
1706 for iteration or building related variable sets.
1711 return qw(PRIVLIB SITELIB VENDORLIB
1712 ARCHLIB SITEARCH VENDORARCH
1713 BIN SITEBIN VENDORBIN
1714 SCRIPT SITESCRIPT VENDORSCRIPT
1715 MAN1DIR SITEMAN1DIR VENDORMAN1DIR
1716 MAN3DIR SITEMAN3DIR VENDORMAN3DIR
1723 my $wanted = $self->libscan($path);
1725 Takes a path to a file or dir and returns an empty string if we don't
1726 want to include this file in the library. Otherwise it returns the
1727 the $path unchanged.
1729 Mainly used to exclude version control administrative directories from
1735 my($self,$path) = @_;
1736 my($dirs,$file) = ($self->splitpath($path))[1,2];
1737 return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/,
1738 $self->splitdir($dirs), $file;
1744 =head3 platform_constants
1746 my $make_frag = $mm->platform_constants
1748 Returns a make fragment defining all the macros initialized in
1749 init_platform() rather than put them in constants().
1753 sub platform_constants {
1760 Michael G Schwern <schwern@pobox.com> and the denizens of
1761 makemaker@perl.org with code from ExtUtils::MM_Unix and