home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / perl / 5.8.8 / ExtUtils / MM_Any.pm < prev    next >
Encoding:
Perl POD Document  |  2006-07-07  |  41.2 KB  |  1,696 lines

  1. package ExtUtils::MM_Any;
  2.  
  3. use strict;
  4. use vars qw($VERSION @ISA);
  5. $VERSION = '0.13_01';
  6.  
  7. use File::Spec;
  8. BEGIN { @ISA = qw(File::Spec); }
  9.  
  10. # We need $Verbose
  11. use ExtUtils::MakeMaker qw($Verbose);
  12.  
  13. use ExtUtils::MakeMaker::Config;
  14.  
  15.  
  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;
  21.  
  22.  
  23. =head1 NAME
  24.  
  25. ExtUtils::MM_Any - Platform-agnostic MM methods
  26.  
  27. =head1 SYNOPSIS
  28.  
  29.   FOR INTERNAL USE ONLY!
  30.  
  31.   package ExtUtils::MM_SomeOS;
  32.  
  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);
  37.  
  38. =head1 DESCRIPTION
  39.  
  40. B<FOR INTERNAL USE ONLY!>
  41.  
  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.
  45.  
  46. Subclass off of ExtUtils::MM_Any I<and> ExtUtils::MM_Unix.  This is a
  47. temporary solution.
  48.  
  49. B<THIS MAY BE TEMPORARY!>
  50.  
  51.  
  52. =head1 METHODS
  53.  
  54. Any methods marked I<Abstract> must be implemented by subclasses.
  55.  
  56.  
  57. =head2 Cross-platform helper methods
  58.  
  59. These are methods which help writing cross-platform code.
  60.  
  61.  
  62.  
  63. =head3 os_flavor  I<Abstract>
  64.  
  65.     my @os_flavor = $mm->os_flavor;
  66.  
  67. @os_flavor is the style of operating system this is, usually
  68. corresponding to the MM_*.pm file we're using.  
  69.  
  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.
  72.  
  73. Some examples:
  74.  
  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')
  80.     OS/2           ('OS/2')
  81.  
  82. This is used to write code for styles of operating system.  
  83. See os_flavor_is() for use.
  84.  
  85.  
  86. =head3 os_flavor_is
  87.  
  88.     my $is_this_flavor = $mm->os_flavor_is($this_flavor);
  89.     my $is_this_flavor = $mm->os_flavor_is(@one_of_these_flavors);
  90.  
  91. Checks to see if the current operating system is one of the given flavors.
  92.  
  93. This is useful for code like:
  94.  
  95.     if( $mm->os_flavor_is('Unix') ) {
  96.         $out = `foo 2>&1`;
  97.     }
  98.     else {
  99.         $out = `foo`;
  100.     }
  101.  
  102. =cut
  103.  
  104. sub os_flavor_is {
  105.     my $self = shift;
  106.     my %flavors = map { ($_ => 1) } $self->os_flavor;
  107.     return (grep { $flavors{$_} } @_) ? 1 : 0;
  108. }
  109.  
  110.  
  111. =head3 split_command
  112.  
  113.     my @cmds = $MM->split_command($cmd, @args);
  114.  
  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.
  118.  
  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.
  123.  
  124. $cmd should include any switches and repeated initial arguments.
  125.  
  126. If no @args are given, no @cmds will be returned.
  127.  
  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:
  131.  
  132.     $self->split_command($cmd, %pod2man);
  133.  
  134.  
  135. =cut
  136.  
  137. sub split_command {
  138.     my($self, $cmd, @args) = @_;
  139.  
  140.     my @cmds = ();
  141.     return(@cmds) unless @args;
  142.  
  143.     # If the command was given as a here-doc, there's probably a trailing
  144.     # newline.
  145.     chomp $cmd;
  146.  
  147.     # set aside 20% for macro expansion.
  148.     my $len_left = int($self->max_exec_len * 0.80);
  149.     $len_left -= length $self->_expand_macros($cmd);
  150.  
  151.     do {
  152.         my $arg_str = '';
  153.         my @next_args;
  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";
  157.  
  158.             if( !length $arg_str ) {
  159.                 $arg_str .= $next_arg_str
  160.             }
  161.             elsif( length($arg_str) + length($next_arg_str) > $len_left ) {
  162.                 unshift @args, @next_args;
  163.                 last;
  164.             }
  165.             else {
  166.                 $arg_str .= $next_arg_str;
  167.             }
  168.         }
  169.         chop $arg_str;
  170.  
  171.         push @cmds, $self->escape_newlines("$cmd \n$arg_str");
  172.     } while @args;
  173.  
  174.     return @cmds;
  175. }
  176.  
  177.  
  178. sub _expand_macros {
  179.     my($self, $cmd) = @_;
  180.  
  181.     $cmd =~ s{\$\((\w+)\)}{
  182.         defined $self->{$1} ? $self->{$1} : "\$($1)"
  183.     }e;
  184.     return $cmd;
  185. }
  186.  
  187.  
  188. =head3 echo
  189.  
  190.     my @commands = $MM->echo($text);
  191.     my @commands = $MM->echo($text, $file);
  192.     my @commands = $MM->echo($text, $file, $appending);
  193.  
  194. Generates a set of @commands which print the $text to a $file.
  195.  
  196. If $file is not given, output goes to STDOUT.
  197.  
  198. If $appending is true the $file will be appended to rather than
  199. overwritten.
  200.  
  201. =cut
  202.  
  203. sub echo {
  204.     my($self, $text, $file, $appending) = @_;
  205.     $appending ||= 0;
  206.  
  207.     my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_) } 
  208.                split /\n/, $text;
  209.     if( $file ) {
  210.         my $redirect = $appending ? '>>' : '>';
  211.         $cmds[0] .= " $redirect $file";
  212.         $_ .= " >> $file" foreach @cmds[1..$#cmds];
  213.     }
  214.  
  215.     return @cmds;
  216. }
  217.  
  218.  
  219. =head3 wraplist
  220.  
  221.   my $args = $mm->wraplist(@list);
  222.  
  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:
  225.  
  226.     FOO \
  227.     BAR \
  228.     BAZ
  229.  
  230. =cut
  231.  
  232. sub wraplist {
  233.     my $self = shift;
  234.     return join " \\\n\t", @_;
  235. }
  236.  
  237.  
  238. =head3 cd  I<Abstract>
  239.  
  240.   my $subdir_cmd = $MM->cd($subdir, @cmds);
  241.  
  242. This will generate a make fragment which runs the @cmds in the given
  243. $dir.  The rough equivalent to this, except cross platform.
  244.  
  245.   cd $subdir && $cmd
  246.  
  247. Currently $dir can only go down one level.  "foo" is fine.  "foo/bar" is
  248. not.  "../foo" is right out.
  249.  
  250. The resulting $subdir_cmd has no leading tab nor trailing newline.  This
  251. makes it easier to embed in a make string.  For example.
  252.  
  253.       my $make = sprintf <<'CODE', $subdir_cmd;
  254.   foo :
  255.       $(ECHO) what
  256.       %s
  257.       $(ECHO) mouche
  258.   CODE
  259.  
  260.  
  261. =head3 oneliner  I<Abstract>
  262.  
  263.   my $oneliner = $MM->oneliner($perl_code);
  264.   my $oneliner = $MM->oneliner($perl_code, \@switches);
  265.  
  266. This will generate a perl one-liner safe for the particular platform
  267. you're on based on the given $perl_code and @switches (a -e is
  268. assumed) suitable for using in a make target.  It will use the proper
  269. shell quoting and escapes.
  270.  
  271. $(PERLRUN) will be used as perl.
  272.  
  273. Any newlines in $perl_code will be escaped.  Leading and trailing
  274. newlines will be stripped.  Makes this idiom much easier:
  275.  
  276.     my $code = $MM->oneliner(<<'CODE', [...switches...]);
  277. some code here
  278. another line here
  279. CODE
  280.  
  281. Usage might be something like:
  282.  
  283.     # an echo emulation
  284.     $oneliner = $MM->oneliner('print "Foo\n"');
  285.     $make = '$oneliner > somefile';
  286.  
  287. All dollar signs must be doubled in the $perl_code if you expect them
  288. to be interpreted normally, otherwise it will be considered a make
  289. macro.  Also remember to quote make macros else it might be used as a
  290. bareword.  For example:
  291.  
  292.     # Assign the value of the $(VERSION_FROM) make macro to $vf.
  293.     $oneliner = $MM->oneliner('$$vf = "$(VERSION_FROM)"');
  294.  
  295. Its currently very simple and may be expanded sometime in the figure
  296. to include more flexible code and switches.
  297.  
  298.  
  299. =head3 quote_literal  I<Abstract>
  300.  
  301.     my $safe_text = $MM->quote_literal($text);
  302.  
  303. This will quote $text so it is interpreted literally in the shell.
  304.  
  305. For example, on Unix this would escape any single-quotes in $text and
  306. put single-quotes around the whole thing.
  307.  
  308.  
  309. =head3 escape_newlines  I<Abstract>
  310.  
  311.     my $escaped_text = $MM->escape_newlines($text);
  312.  
  313. Shell escapes newlines in $text.
  314.  
  315.  
  316. =head3 max_exec_len  I<Abstract>
  317.  
  318.     my $max_exec_len = $MM->max_exec_len;
  319.  
  320. Calculates the maximum command size the OS can exec.  Effectively,
  321. this is the max size of a shell command line.
  322.  
  323. =for _private
  324. $self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes.
  325.  
  326.  
  327.  
  328.  
  329.  
  330. =head2 Targets
  331.  
  332. These are methods which produce make targets.
  333.  
  334.  
  335. =head3 all_target
  336.  
  337. Generate the default target 'all'.
  338.  
  339. =cut
  340.  
  341. sub all_target {
  342.     my $self = shift;
  343.  
  344.     return <<'MAKE_EXT';
  345. all :: pure_all
  346.     $(NOECHO) $(NOOP)
  347. MAKE_EXT
  348.  
  349. }
  350.  
  351.  
  352. =head3 blibdirs_target
  353.  
  354.     my $make_frag = $mm->blibdirs_target;
  355.  
  356. Creates the blibdirs target which creates all the directories we use
  357. in blib/.
  358.  
  359. The blibdirs.ts target is deprecated.  Depend on blibdirs instead.
  360.  
  361.  
  362. =cut
  363.  
  364. sub blibdirs_target {
  365.     my $self = shift;
  366.  
  367.     my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib
  368.                                            autodir archautodir
  369.                                            bin script
  370.                                            man1dir man3dir
  371.                                           );
  372.  
  373.     my @exists = map { $_.'$(DFSEP).exists' } @dirs;
  374.  
  375.     my $make = sprintf <<'MAKE', join(' ', @exists);
  376. blibdirs : %s
  377.     $(NOECHO) $(NOOP)
  378.  
  379. # Backwards compat with 6.18 through 6.25
  380. blibdirs.ts : blibdirs
  381.     $(NOECHO) $(NOOP)
  382.  
  383. MAKE
  384.  
  385.     $make .= $self->dir_target(@dirs);
  386.  
  387.     return $make;
  388. }
  389.  
  390.  
  391. =head3 clean (o)
  392.  
  393. Defines the clean target.
  394.  
  395. =cut
  396.  
  397. sub clean {
  398. # --- Cleanup and Distribution Sections ---
  399.  
  400.     my($self, %attribs) = @_;
  401.     my @m;
  402.     push(@m, '
  403. # Delete temporary files but do not touch installed files. We don\'t delete
  404. # the Makefile here so a later make realclean still has a makefile to use.
  405.  
  406. clean :: clean_subdirs
  407. ');
  408.  
  409.     my @files = values %{$self->{XS}}; # .c files from *.xs files
  410.     my @dirs  = qw(blib);
  411.  
  412.     # Normally these are all under blib but they might have been
  413.     # redefined.
  414.     # XXX normally this would be a good idea, but the Perl core sets
  415.     # INST_LIB = ../../lib rather than actually installing the files.
  416.     # So a "make clean" in an ext/ directory would blow away lib.
  417.     # Until the core is adjusted let's leave this out.
  418. #     push @dirs, qw($(INST_ARCHLIB) $(INST_LIB)
  419. #                    $(INST_BIN) $(INST_SCRIPT)
  420. #                    $(INST_MAN1DIR) $(INST_MAN3DIR)
  421. #                    $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR) 
  422. #                    $(INST_STATIC) $(INST_DYNAMIC) $(INST_BOOT)
  423. #                 );
  424.                   
  425.  
  426.     if( $attribs{FILES} ) {
  427.         # Use @dirs because we don't know what's in here.
  428.         push @dirs, ref $attribs{FILES}                ?
  429.                         @{$attribs{FILES}}             :
  430.                         split /\s+/, $attribs{FILES}   ;
  431.     }
  432.  
  433.     push(@files, qw[$(MAKE_APERL_FILE) 
  434.                     perlmain.c tmon.out mon.out so_locations 
  435.                     blibdirs.ts pm_to_blib pm_to_blib.ts
  436.                     *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
  437.                     $(BOOTSTRAP) $(BASEEXT).bso
  438.                     $(BASEEXT).def lib$(BASEEXT).def
  439.                     $(BASEEXT).exp $(BASEEXT).x
  440.                    ]);
  441.  
  442.     push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
  443.     push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld'));
  444.  
  445.     # core files
  446.     push(@files, qw[core core.*perl.*.? *perl.core]);
  447.     push(@files, map { "core." . "[0-9]"x$_ } (1..5));
  448.  
  449.     # OS specific things to clean up.  Use @dirs since we don't know
  450.     # what might be in here.
  451.     push @dirs, $self->extra_clean_files;
  452.  
  453.     # Occasionally files are repeated several times from different sources
  454.     { my(%f) = map { ($_ => 1) } @files; @files = keys %f; }
  455.     { my(%d) = map { ($_ => 1) } @dirs;  @dirs  = keys %d; }
  456.  
  457.     push @m, map "\t$_\n", $self->split_command('- $(RM_F)',  @files);
  458.     push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs);
  459.  
  460.     # Leave Makefile.old around for realclean
  461.     push @m, <<'MAKE';
  462.     - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL)
  463. MAKE
  464.  
  465.     push(@m, "\t$attribs{POSTOP}\n")   if $attribs{POSTOP};
  466.  
  467.     join("", @m);
  468. }
  469.  
  470.  
  471. =head3 clean_subdirs_target
  472.  
  473.   my $make_frag = $MM->clean_subdirs_target;
  474.  
  475. Returns the clean_subdirs target.  This is used by the clean target to
  476. call clean on any subdirectories which contain Makefiles.
  477.  
  478. =cut
  479.  
  480. sub clean_subdirs_target {
  481.     my($self) = shift;
  482.  
  483.     # No subdirectories, no cleaning.
  484.     return <<'NOOP_FRAG' unless @{$self->{DIR}};
  485. clean_subdirs :
  486.     $(NOECHO) $(NOOP)
  487. NOOP_FRAG
  488.  
  489.  
  490.     my $clean = "clean_subdirs :\n";
  491.  
  492.     for my $dir (@{$self->{DIR}}) {
  493.         my $subclean = $self->oneliner(sprintf <<'CODE', $dir);
  494. chdir '%s';  system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)';
  495. CODE
  496.  
  497.         $clean .= "\t$subclean\n";
  498.     }
  499.  
  500.     return $clean;
  501. }
  502.  
  503.  
  504. =head3 dir_target
  505.  
  506.     my $make_frag = $mm->dir_target(@directories);
  507.  
  508. Generates targets to create the specified directories and set its
  509. permission to 0755.
  510.  
  511. Because depending on a directory to just ensure it exists doesn't work
  512. too well (the modified time changes too often) dir_target() creates a
  513. .exists file in the created directory.  It is this you should depend on.
  514. For portability purposes you should use the $(DIRFILESEP) macro rather
  515. than a '/' to seperate the directory from the file.
  516.  
  517.     yourdirectory$(DIRFILESEP).exists
  518.  
  519. =cut
  520.  
  521. sub dir_target {
  522.     my($self, @dirs) = @_;
  523.  
  524.     my $make = '';
  525.     foreach my $dir (@dirs) {
  526.         $make .= sprintf <<'MAKE', ($dir) x 7;
  527. %s$(DFSEP).exists :: Makefile.PL
  528.     $(NOECHO) $(MKPATH) %s
  529.     $(NOECHO) $(CHMOD) 755 %s
  530.     $(NOECHO) $(TOUCH) %s$(DFSEP).exists
  531.  
  532. MAKE
  533.  
  534.     }
  535.  
  536.     return $make;
  537. }
  538.  
  539.  
  540. =head3 distdir
  541.  
  542. Defines the scratch directory target that will hold the distribution
  543. before tar-ing (or shar-ing).
  544.  
  545. =cut
  546.  
  547. # For backwards compatibility.
  548. *dist_dir = *distdir;
  549.  
  550. sub distdir {
  551.     my($self) = shift;
  552.  
  553.     my $meta_target = $self->{NO_META} ? '' : 'distmeta';
  554.     my $sign_target = !$self->{SIGN}   ? '' : 'distsignature';
  555.  
  556.     return sprintf <<'MAKE_FRAG', $meta_target, $sign_target;
  557. create_distdir :
  558.     $(RM_RF) $(DISTVNAME)
  559.     $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
  560.         -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
  561.  
  562. distdir : create_distdir %s %s
  563.     $(NOECHO) $(NOOP)
  564.  
  565. MAKE_FRAG
  566.  
  567. }
  568.  
  569.  
  570. =head3 dist_test
  571.  
  572. Defines a target that produces the distribution in the
  573. scratchdirectory, and runs 'perl Makefile.PL; make ;make test' in that
  574. subdirectory.
  575.  
  576. =cut
  577.  
  578. sub dist_test {
  579.     my($self) = shift;
  580.  
  581.     my $mpl_args = join " ", map qq["$_"], @ARGV;
  582.  
  583.     my $test = $self->cd('$(DISTVNAME)',
  584.                          '$(ABSPERLRUN) Makefile.PL '.$mpl_args,
  585.                          '$(MAKE) $(PASTHRU)',
  586.                          '$(MAKE) test $(PASTHRU)'
  587.                         );
  588.  
  589.     return sprintf <<'MAKE_FRAG', $test;
  590. disttest : distdir
  591.     %s
  592.  
  593. MAKE_FRAG
  594.  
  595.  
  596. }
  597.  
  598.  
  599. =head3 dynamic (o)
  600.  
  601. Defines the dynamic target.
  602.  
  603. =cut
  604.  
  605. sub dynamic {
  606. # --- Dynamic Loading Sections ---
  607.  
  608.     my($self) = shift;
  609.     '
  610. dynamic :: $(FIRST_MAKEFILE) $(INST_DYNAMIC) $(INST_BOOT)
  611.     $(NOECHO) $(NOOP)
  612. ';
  613. }
  614.  
  615.  
  616. =head3 makemakerdflt_target
  617.  
  618.   my $make_frag = $mm->makemakerdflt_target
  619.  
  620. Returns a make fragment with the makemakerdeflt_target specified.
  621. This target is the first target in the Makefile, is the default target
  622. and simply points off to 'all' just in case any make variant gets
  623. confused or something gets snuck in before the real 'all' target.
  624.  
  625. =cut
  626.  
  627. sub makemakerdflt_target {
  628.     return <<'MAKE_FRAG';
  629. makemakerdflt: all
  630.     $(NOECHO) $(NOOP)
  631. MAKE_FRAG
  632.  
  633. }
  634.  
  635.  
  636. =head3 manifypods_target
  637.  
  638.   my $manifypods_target = $self->manifypods_target;
  639.  
  640. Generates the manifypods target.  This target generates man pages from
  641. all POD files in MAN1PODS and MAN3PODS.
  642.  
  643. =cut
  644.  
  645. sub manifypods_target {
  646.     my($self) = shift;
  647.  
  648.     my $dependencies  = '';
  649.  
  650.     # populate manXpods & dependencies:
  651.     foreach my $name (keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}}) {
  652.         $dependencies .= " \\\n\t$name";
  653.     }
  654.  
  655.     foreach my $name (keys %{$self->{MAN3PODS}}) {
  656.         $dependencies .= " \\\n\t$name"
  657.     }
  658.  
  659.     my $manify = <<END;
  660. manifypods : pure_all $dependencies
  661. END
  662.  
  663.     my @man_cmds;
  664.     foreach my $section (qw(1 3)) {
  665.         my $pods = $self->{"MAN${section}PODS"};
  666.         push @man_cmds, $self->split_command(<<CMD, %$pods);
  667.     \$(NOECHO) \$(POD2MAN) --section=\$(MAN${section}EXT) --perm_rw=\$(PERM_RW)
  668. CMD
  669.     }
  670.  
  671.     $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds;
  672.     $manify .= join '', map { "$_\n" } @man_cmds;
  673.  
  674.     return $manify;
  675. }
  676.  
  677.  
  678. =head3 metafile_target
  679.  
  680.     my $target = $mm->metafile_target;
  681.  
  682. Generate the metafile target.
  683.  
  684. Writes the file META.yml YAML encoded meta-data about the module in
  685. the distdir.  The format follows Module::Build's as closely as
  686. possible.  Additionally, we include:
  687.  
  688.     version_from
  689.     installdirs
  690.  
  691. =cut
  692.  
  693. sub metafile_target {
  694.     my $self = shift;
  695.  
  696.     return <<'MAKE_FRAG' if $self->{NO_META};
  697. metafile:
  698.     $(NOECHO) $(NOOP)
  699. MAKE_FRAG
  700.  
  701.     my $prereq_pm = '';
  702.     foreach my $mod ( sort { lc $a cmp lc $b } keys %{$self->{PREREQ_PM}} ) {
  703.         my $ver = $self->{PREREQ_PM}{$mod};
  704.         $prereq_pm .= sprintf "    %-30s %s\n", "$mod:", $ver;
  705.     }
  706.  
  707.     my $meta = <<YAML;
  708. # http://module-build.sourceforge.net/META-spec.html
  709. #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
  710. name:         $self->{DISTNAME}
  711. version:      $self->{VERSION}
  712. version_from: $self->{VERSION_FROM}
  713. installdirs:  $self->{INSTALLDIRS}
  714. requires:
  715. $prereq_pm
  716. distribution_type: module
  717. generated_by: ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION
  718. YAML
  719.  
  720.     my @write_meta = $self->echo($meta, 'META_new.yml');
  721.  
  722.     return sprintf <<'MAKE_FRAG', join("\n\t", @write_meta);
  723. metafile : create_distdir
  724.     $(NOECHO) $(ECHO) Generating META.yml
  725.     %s
  726.     -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml
  727. MAKE_FRAG
  728.  
  729. }
  730.  
  731.  
  732. =head3 distmeta_target
  733.  
  734.     my $make_frag = $mm->distmeta_target;
  735.  
  736. Generates the distmeta target to add META.yml to the MANIFEST in the
  737. distdir.
  738.  
  739. =cut
  740.  
  741. sub distmeta_target {
  742.     my $self = shift;
  743.  
  744.     my $add_meta = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
  745. eval { maniadd({q{META.yml} => q{Module meta-data (added by MakeMaker)}}) } 
  746.     or print "Could not add META.yml to MANIFEST: $${'@'}\n"
  747. CODE
  748.  
  749.     my $add_meta_to_distdir = $self->cd('$(DISTVNAME)', $add_meta);
  750.  
  751.     return sprintf <<'MAKE', $add_meta_to_distdir;
  752. distmeta : create_distdir metafile
  753.     $(NOECHO) %s
  754.  
  755. MAKE
  756.  
  757. }
  758.  
  759.  
  760. =head3 realclean (o)
  761.  
  762. Defines the realclean target.
  763.  
  764. =cut
  765.  
  766. sub realclean {
  767.     my($self, %attribs) = @_;
  768.  
  769.     my @dirs  = qw($(DISTVNAME));
  770.     my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD));
  771.  
  772.     # Special exception for the perl core where INST_* is not in blib.
  773.     # This cleans up the files built from the ext/ directory (all XS).
  774.     if( $self->{PERL_CORE} ) {
  775.     push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR));
  776.         push @files, values %{$self->{PM}};
  777.     }
  778.  
  779.     if( $self->has_link_code ){
  780.         push @files, qw($(OBJECT));
  781.     }
  782.  
  783.     if( $attribs{FILES} ) {
  784.         if( ref $attribs{FILES} ) {
  785.             push @dirs, @{ $attribs{FILES} };
  786.         }
  787.         else {
  788.             push @dirs, split /\s+/, $attribs{FILES};
  789.         }
  790.     }
  791.  
  792.     # Occasionally files are repeated several times from different sources
  793.     { my(%f) = map { ($_ => 1) } @files;  @files = keys %f; }
  794.     { my(%d) = map { ($_ => 1) } @dirs;   @dirs  = keys %d; }
  795.  
  796.     my $rm_cmd  = join "\n\t", map { "$_" } 
  797.                     $self->split_command('- $(RM_F)',  @files);
  798.     my $rmf_cmd = join "\n\t", map { "$_" } 
  799.                     $self->split_command('- $(RM_RF)', @dirs);
  800.  
  801.     my $m = sprintf <<'MAKE', $rm_cmd, $rmf_cmd;
  802. # Delete temporary files (via clean) and also delete dist files
  803. realclean purge ::  clean realclean_subdirs
  804.     %s
  805.     %s
  806. MAKE
  807.  
  808.     $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP};
  809.  
  810.     return $m;
  811. }
  812.  
  813.  
  814. =head3 realclean_subdirs_target
  815.  
  816.   my $make_frag = $MM->realclean_subdirs_target;
  817.  
  818. Returns the realclean_subdirs target.  This is used by the realclean
  819. target to call realclean on any subdirectories which contain Makefiles.
  820.  
  821. =cut
  822.  
  823. sub realclean_subdirs_target {
  824.     my $self = shift;
  825.  
  826.     return <<'NOOP_FRAG' unless @{$self->{DIR}};
  827. realclean_subdirs :
  828.     $(NOECHO) $(NOOP)
  829. NOOP_FRAG
  830.  
  831.     my $rclean = "realclean_subdirs :\n";
  832.  
  833.     foreach my $dir (@{$self->{DIR}}) {
  834.         foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) {
  835.             my $subrclean .= $self->oneliner(sprintf <<'CODE', $dir, ($makefile) x 2);
  836. chdir '%s';  system '$(MAKE) $(USEMAKEFILE) %s realclean' if -f '%s';
  837. CODE
  838.  
  839.             $rclean .= sprintf <<'RCLEAN', $subrclean;
  840.     - %s
  841. RCLEAN
  842.  
  843.         }
  844.     }
  845.  
  846.     return $rclean;
  847. }
  848.  
  849.  
  850. =head3 signature_target
  851.  
  852.     my $target = $mm->signature_target;
  853.  
  854. Generate the signature target.
  855.  
  856. Writes the file SIGNATURE with "cpansign -s".
  857.  
  858. =cut
  859.  
  860. sub signature_target {
  861.     my $self = shift;
  862.  
  863.     return <<'MAKE_FRAG';
  864. signature :
  865.     cpansign -s
  866. MAKE_FRAG
  867.  
  868. }
  869.  
  870.  
  871. =head3 distsignature_target
  872.  
  873.     my $make_frag = $mm->distsignature_target;
  874.  
  875. Generates the distsignature target to add SIGNATURE to the MANIFEST in the
  876. distdir.
  877.  
  878. =cut
  879.  
  880. sub distsignature_target {
  881.     my $self = shift;
  882.  
  883.     my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
  884. eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) } 
  885.     or print "Could not add SIGNATURE to MANIFEST: $${'@'}\n"
  886. CODE
  887.  
  888.     my $sign_dist        = $self->cd('$(DISTVNAME)' => 'cpansign -s');
  889.  
  890.     # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not
  891.     # exist
  892.     my $touch_sig        = $self->cd('$(DISTVNAME)' => '$(TOUCH) SIGNATURE');
  893.     my $add_sign_to_dist = $self->cd('$(DISTVNAME)' => $add_sign );
  894.  
  895.     return sprintf <<'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist
  896. distsignature : create_distdir
  897.     $(NOECHO) %s
  898.     $(NOECHO) %s
  899.     %s
  900.  
  901. MAKE
  902.  
  903. }
  904.  
  905.  
  906. =head3 special_targets
  907.  
  908.   my $make_frag = $mm->special_targets
  909.  
  910. Returns a make fragment containing any targets which have special
  911. meaning to make.  For example, .SUFFIXES and .PHONY.
  912.  
  913. =cut
  914.  
  915. sub special_targets {
  916.     my $make_frag = <<'MAKE_FRAG';
  917. .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)
  918.  
  919. .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir
  920.  
  921. MAKE_FRAG
  922.  
  923.     $make_frag .= <<'MAKE_FRAG' if $ENV{CLEARCASE_ROOT};
  924. .NO_CONFIG_REC: Makefile
  925.  
  926. MAKE_FRAG
  927.  
  928.     return $make_frag;
  929. }
  930.  
  931.  
  932.  
  933.  
  934. =head2 Init methods
  935.  
  936. Methods which help initialize the MakeMaker object and macros.
  937.  
  938.  
  939. =head3 init_INST
  940.  
  941.     $mm->init_INST;
  942.  
  943. Called by init_main.  Sets up all INST_* variables except those related
  944. to XS code.  Those are handled in init_xs.
  945.  
  946. =cut
  947.  
  948. sub init_INST {
  949.     my($self) = shift;
  950.  
  951.     $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch");
  952.     $self->{INST_BIN}     ||= $self->catdir($Curdir,'blib','bin');
  953.  
  954.     # INST_LIB typically pre-set if building an extension after
  955.     # perl has been built and installed. Setting INST_LIB allows
  956.     # you to build directly into, say $Config{privlibexp}.
  957.     unless ($self->{INST_LIB}){
  958.     if ($self->{PERL_CORE}) {
  959.             if (defined $Cross::platform) {
  960.                 $self->{INST_LIB} = $self->{INST_ARCHLIB} = 
  961.                   $self->catdir($self->{PERL_LIB},"..","xlib",
  962.                                      $Cross::platform);
  963.             }
  964.             else {
  965.                 $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
  966.             }
  967.     } else {
  968.         $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib");
  969.     }
  970.     }
  971.  
  972.     my @parentdir = split(/::/, $self->{PARENT_NAME});
  973.     $self->{INST_LIBDIR}      = $self->catdir('$(INST_LIB)',     @parentdir);
  974.     $self->{INST_ARCHLIBDIR}  = $self->catdir('$(INST_ARCHLIB)', @parentdir);
  975.     $self->{INST_AUTODIR}     = $self->catdir('$(INST_LIB)', 'auto', 
  976.                                               '$(FULLEXT)');
  977.     $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto',
  978.                                               '$(FULLEXT)');
  979.  
  980.     $self->{INST_SCRIPT}  ||= $self->catdir($Curdir,'blib','script');
  981.  
  982.     $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1');
  983.     $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3');
  984.  
  985.     return 1;
  986. }
  987.  
  988.  
  989. =head3 init_INSTALL
  990.  
  991.     $mm->init_INSTALL;
  992.  
  993. Called by init_main.  Sets up all INSTALL_* variables (except
  994. INSTALLDIRS) and *PREFIX.
  995.  
  996. =cut
  997.  
  998. sub init_INSTALL {
  999.     my($self) = shift;
  1000.  
  1001.     if( $self->{ARGS}{INSTALLBASE} and $self->{ARGS}{PREFIX} ) {
  1002.         die "Only one of PREFIX or INSTALLBASE can be given.  Not both.\n";
  1003.     }
  1004.  
  1005.     if( $self->{ARGS}{INSTALLBASE} ) {
  1006.         $self->init_INSTALL_from_INSTALLBASE;
  1007.     }
  1008.     else {
  1009.         $self->init_INSTALL_from_PREFIX;
  1010.     }
  1011. }
  1012.  
  1013.  
  1014. =head3 init_INSTALL_from_PREFIX
  1015.  
  1016.   $mm->init_INSTALL_from_PREFIX;
  1017.  
  1018. =cut
  1019.  
  1020. sub init_INSTALL_from_PREFIX {
  1021.     my $self = shift;
  1022.  
  1023.     $self->init_lib2arch;
  1024.  
  1025.     # There are often no Config.pm defaults for these new man variables so 
  1026.     # we fall back to the old behavior which is to use installman*dir
  1027.     foreach my $num (1, 3) {
  1028.         my $k = 'installsiteman'.$num.'dir';
  1029.  
  1030.         $self->{uc $k} ||= uc "\$(installman${num}dir)"
  1031.           unless $Config{$k};
  1032.     }
  1033.  
  1034.     foreach my $num (1, 3) {
  1035.         my $k = 'installvendorman'.$num.'dir';
  1036.  
  1037.         unless( $Config{$k} ) {
  1038.             $self->{uc $k}  ||= $Config{usevendorprefix}
  1039.                               ? uc "\$(installman${num}dir)"
  1040.                               : '';
  1041.         }
  1042.     }
  1043.  
  1044.     $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)'
  1045.       unless $Config{installsitebin};
  1046.     $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)'
  1047.       unless $Config{installsitescript};
  1048.  
  1049.     unless( $Config{installvendorbin} ) {
  1050.         $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix} 
  1051.                                     ? $Config{installbin}
  1052.                                     : '';
  1053.     }
  1054.     unless( $Config{installvendorscript} ) {
  1055.         $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix}
  1056.                                        ? $Config{installscript}
  1057.                                        : '';
  1058.     }
  1059.  
  1060.  
  1061.     my $iprefix = $Config{installprefixexp} || $Config{installprefix} || 
  1062.                   $Config{prefixexp}        || $Config{prefix} || '';
  1063.     my $vprefix = $Config{usevendorprefix}  ? $Config{vendorprefixexp} : '';
  1064.     my $sprefix = $Config{siteprefixexp}    || '';
  1065.  
  1066.     # 5.005_03 doesn't have a siteprefix.
  1067.     $sprefix = $iprefix unless $sprefix;
  1068.  
  1069.  
  1070.     $self->{PREFIX}       ||= '';
  1071.  
  1072.     if( $self->{PREFIX} ) {
  1073.         @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} =
  1074.           ('$(PREFIX)') x 3;
  1075.     }
  1076.     else {
  1077.         $self->{PERLPREFIX}   ||= $iprefix;
  1078.         $self->{SITEPREFIX}   ||= $sprefix;
  1079.         $self->{VENDORPREFIX} ||= $vprefix;
  1080.  
  1081.     my $p = $self->{PREFIX} = $self->{PERLPREFIX};
  1082.     for my $t (qw/PERL SITE VENDOR/)
  1083.     {
  1084.         $self->{"${t}PREFIX"} =~ s!^\Q$p\E(?=/|$)!\$(PREFIX)!;
  1085.     }
  1086.     }
  1087.  
  1088.     my $arch    = $Config{archname};
  1089.     my $version = $Config{version};
  1090.  
  1091.     # default style
  1092.     my $libstyle = $Config{installstyle} || 'lib/perl5';
  1093.     my $manstyle = '';
  1094.  
  1095.     if( $self->{LIBSTYLE} ) {
  1096.         $libstyle = $self->{LIBSTYLE};
  1097.         $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : '';
  1098.     }
  1099.  
  1100.     # Some systems, like VOS, set installman*dir to '' if they can't
  1101.     # read man pages.
  1102.     for my $num (1, 3) {
  1103.         $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none'
  1104.           unless $Config{'installman'.$num.'dir'};
  1105.     }
  1106.  
  1107.     my %bin_layouts = 
  1108.     (
  1109.         bin         => { s => $iprefix,
  1110.                          t => 'perl',
  1111.                          d => 'bin' },
  1112.         vendorbin   => { s => $vprefix,
  1113.                          t => 'vendor',
  1114.                          d => 'bin' },
  1115.         sitebin     => { s => $sprefix,
  1116.                          t => 'site',
  1117.                          d => 'bin' },
  1118.         script      => { s => $iprefix,
  1119.                          t => 'perl',
  1120.                          d => 'bin' },
  1121.         vendorscript=> { s => $vprefix,
  1122.                          t => 'vendor',
  1123.                          d => 'bin' },
  1124.         sitescript  => { s => $sprefix,
  1125.                          t => 'site',
  1126.                          d => 'bin' },
  1127.     );
  1128.     
  1129.     my %man_layouts =
  1130.     (
  1131.         man1dir         => { s => $iprefix,
  1132.                              t => 'perl',
  1133.                              d => 'man/man1',
  1134.                              style => $manstyle, },
  1135.         siteman1dir     => { s => $sprefix,
  1136.                              t => 'site',
  1137.                              d => 'man/man1',
  1138.                              style => $manstyle, },
  1139.         vendorman1dir   => { s => $vprefix,
  1140.                              t => 'vendor',
  1141.                              d => 'man/man1',
  1142.                              style => $manstyle, },
  1143.  
  1144.         man3dir         => { s => $iprefix,
  1145.                              t => 'perl',
  1146.                              d => 'man/man3',
  1147.                              style => $manstyle, },
  1148.         siteman3dir     => { s => $sprefix,
  1149.                              t => 'site',
  1150.                              d => 'man/man3',
  1151.                              style => $manstyle, },
  1152.         vendorman3dir   => { s => $vprefix,
  1153.                              t => 'vendor',
  1154.                              d => 'man/man3',
  1155.                              style => $manstyle, },
  1156.     );
  1157.  
  1158.     my %lib_layouts =
  1159.     (
  1160.         privlib     => { s => $iprefix,
  1161.                          t => 'perl',
  1162.                          d => '',
  1163.                          style => $libstyle, },
  1164.         vendorlib   => { s => $vprefix,
  1165.                          t => 'vendor',
  1166.                          d => '',
  1167.                          style => $libstyle, },
  1168.         sitelib     => { s => $sprefix,
  1169.                          t => 'site',
  1170.                          d => 'site_perl',
  1171.                          style => $libstyle, },
  1172.         
  1173.         archlib     => { s => $iprefix,
  1174.                          t => 'perl',
  1175.                          d => "$version/$arch",
  1176.                          style => $libstyle },
  1177.         vendorarch  => { s => $vprefix,
  1178.                          t => 'vendor',
  1179.                          d => "$version/$arch",
  1180.                          style => $libstyle },
  1181.         sitearch    => { s => $sprefix,
  1182.                          t => 'site',
  1183.                          d => "site_perl/$version/$arch",
  1184.                          style => $libstyle },
  1185.     );
  1186.  
  1187.  
  1188.     # Special case for LIB.
  1189.     if( $self->{LIB} ) {
  1190.         foreach my $var (keys %lib_layouts) {
  1191.             my $Installvar = uc "install$var";
  1192.  
  1193.             if( $var =~ /arch/ ) {
  1194.                 $self->{$Installvar} ||= 
  1195.                   $self->catdir($self->{LIB}, $Config{archname});
  1196.             }
  1197.             else {
  1198.                 $self->{$Installvar} ||= $self->{LIB};
  1199.             }
  1200.         }
  1201.     }
  1202.  
  1203.     my %type2prefix = ( perl    => 'PERLPREFIX',
  1204.                         site    => 'SITEPREFIX',
  1205.                         vendor  => 'VENDORPREFIX'
  1206.                       );
  1207.  
  1208.     my %layouts = (%bin_layouts, %man_layouts, %lib_layouts);
  1209.     while( my($var, $layout) = each(%layouts) ) {
  1210.         my($s, $t, $d, $style) = @{$layout}{qw(s t d style)};
  1211.         my $r = '$('.$type2prefix{$t}.')';
  1212.  
  1213.         print STDERR "Prefixing $var\n" if $Verbose >= 2;
  1214.  
  1215.         my $installvar = "install$var";
  1216.         my $Installvar = uc $installvar;
  1217.         next if $self->{$Installvar};
  1218.  
  1219.         $d = "$style/$d" if $style;
  1220.         $self->prefixify($installvar, $s, $r, $d);
  1221.  
  1222.         print STDERR "  $Installvar == $self->{$Installvar}\n" 
  1223.           if $Verbose >= 2;
  1224.     }
  1225.  
  1226.     # Generate these if they weren't figured out.
  1227.     $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH};
  1228.     $self->{VENDORLIBEXP}  ||= $self->{INSTALLVENDORLIB};
  1229.  
  1230.     return 1;
  1231. }
  1232.  
  1233.  
  1234. =head3 init_from_INSTALLBASE
  1235.  
  1236.     $mm->init_from_INSTALLBASE
  1237.  
  1238. =cut
  1239.  
  1240. my %map = (
  1241.            lib      => [qw(lib perl5)],
  1242.            arch     => [('lib', 'perl5', $Config{archname})],
  1243.            bin      => [qw(bin)],
  1244.            man1dir  => [qw(man man1)],
  1245.            man3dir  => [qw(man man3)]
  1246.           );
  1247. $map{script} = $map{bin};
  1248.  
  1249. sub init_INSTALL_from_INSTALLBASE {
  1250.     my $self = shift;
  1251.  
  1252.     @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} = 
  1253.                                                          '$(INSTALLBASE)';
  1254.  
  1255.     my %install;
  1256.     foreach my $thing (keys %map) {
  1257.         foreach my $dir (('', 'SITE', 'VENDOR')) {
  1258.             my $uc_thing = uc $thing;
  1259.             my $key = "INSTALL".$dir.$uc_thing;
  1260.  
  1261.             $install{$key} ||= 
  1262.               $self->catdir('$(INSTALLBASE)', @{$map{$thing}});
  1263.         }
  1264.     }
  1265.  
  1266.     # Adjust for variable quirks.
  1267.     $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH};
  1268.     $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB};
  1269.  
  1270.     foreach my $key (keys %install) {
  1271.         $self->{$key} ||= $install{$key};
  1272.     }
  1273.  
  1274.     return 1;
  1275. }
  1276.  
  1277.  
  1278. =head3 init_VERSION  I<Abstract>
  1279.  
  1280.     $mm->init_VERSION
  1281.  
  1282. Initialize macros representing versions of MakeMaker and other tools
  1283.  
  1284. MAKEMAKER: path to the MakeMaker module.
  1285.  
  1286. MM_VERSION: ExtUtils::MakeMaker Version
  1287.  
  1288. MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards 
  1289.              compat)
  1290.  
  1291. VERSION: version of your module
  1292.  
  1293. VERSION_MACRO: which macro represents the version (usually 'VERSION')
  1294.  
  1295. VERSION_SYM: like version but safe for use as an RCS revision number
  1296.  
  1297. DEFINE_VERSION: -D line to set the module version when compiling
  1298.  
  1299. XS_VERSION: version in your .xs file.  Defaults to $(VERSION)
  1300.  
  1301. XS_VERSION_MACRO: which macro represents the XS version.
  1302.  
  1303. XS_DEFINE_VERSION: -D line to set the xs version when compiling.
  1304.  
  1305. Called by init_main.
  1306.  
  1307. =cut
  1308.  
  1309. sub init_VERSION {
  1310.     my($self) = shift;
  1311.  
  1312.     $self->{MAKEMAKER}  = $ExtUtils::MakeMaker::Filename;
  1313.     $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION;
  1314.     $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision;
  1315.     $self->{VERSION_FROM} ||= '';
  1316.  
  1317.     if ($self->{VERSION_FROM}){
  1318.         $self->{VERSION} = $self->parse_version($self->{VERSION_FROM});
  1319.         if( $self->{VERSION} eq 'undef' ) {
  1320.             require Carp;
  1321.             Carp::carp("WARNING: Setting VERSION via file ".
  1322.                        "'$self->{VERSION_FROM}' failed\n");
  1323.         }
  1324.     }
  1325.  
  1326.     # strip blanks
  1327.     if (defined $self->{VERSION}) {
  1328.         $self->{VERSION} =~ s/^\s+//;
  1329.         $self->{VERSION} =~ s/\s+$//;
  1330.     }
  1331.     else {
  1332.         $self->{VERSION} = '';
  1333.     }
  1334.  
  1335.  
  1336.     $self->{VERSION_MACRO}  = 'VERSION';
  1337.     ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
  1338.     $self->{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"';
  1339.  
  1340.  
  1341.     # Graham Barr and Paul Marquess had some ideas how to ensure
  1342.     # version compatibility between the *.pm file and the
  1343.     # corresponding *.xs file. The bottomline was, that we need an
  1344.     # XS_VERSION macro that defaults to VERSION:
  1345.     $self->{XS_VERSION} ||= $self->{VERSION};
  1346.  
  1347.     $self->{XS_VERSION_MACRO}  = 'XS_VERSION';
  1348.     $self->{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"';
  1349.  
  1350. }
  1351.  
  1352.  
  1353. =head3 init_others  I<Abstract>
  1354.  
  1355.     $MM->init_others();
  1356.  
  1357. Initializes the macro definitions used by tools_other() and places them
  1358. in the $MM object.
  1359.  
  1360. If there is no description, its the same as the parameter to
  1361. WriteMakefile() documented in ExtUtils::MakeMaker.
  1362.  
  1363. Defines at least these macros.
  1364.  
  1365.   Macro             Description
  1366.  
  1367.   NOOP              Do nothing
  1368.   NOECHO            Tell make not to display the command itself
  1369.  
  1370.   MAKEFILE
  1371.   FIRST_MAKEFILE
  1372.   MAKEFILE_OLD
  1373.   MAKE_APERL_FILE   File used by MAKE_APERL
  1374.  
  1375.   SHELL             Program used to run
  1376.                     shell commands
  1377.  
  1378.   ECHO              Print text adding a newline on the end
  1379.   RM_F              Remove a file 
  1380.   RM_RF             Remove a directory          
  1381.   TOUCH             Update a file's timestamp   
  1382.   TEST_F            Test for a file's existence 
  1383.   CP                Copy a file                 
  1384.   MV                Move a file                 
  1385.   CHMOD             Change permissions on a     
  1386.                     file
  1387.  
  1388.   UMASK_NULL        Nullify umask
  1389.   DEV_NULL          Supress all command output
  1390.  
  1391.  
  1392. =head3 init_DIRFILESEP  I<Abstract>
  1393.  
  1394.   $MM->init_DIRFILESEP;
  1395.   my $dirfilesep = $MM->{DIRFILESEP};
  1396.  
  1397. Initializes the DIRFILESEP macro which is the seperator between the
  1398. directory and filename in a filepath.  ie. / on Unix, \ on Win32 and
  1399. nothing on VMS.
  1400.  
  1401. For example:
  1402.  
  1403.     # instead of $(INST_ARCHAUTODIR)/extralibs.ld
  1404.     $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld
  1405.  
  1406. Something of a hack but it prevents a lot of code duplication between
  1407. MM_* variants.
  1408.  
  1409. Do not use this as a seperator between directories.  Some operating
  1410. systems use different seperators between subdirectories as between
  1411. directories and filenames (for example:  VOLUME:[dir1.dir2]file on VMS).
  1412.  
  1413. =head3 init_linker  I<Abstract>
  1414.  
  1415.     $mm->init_linker;
  1416.  
  1417. Initialize macros which have to do with linking.
  1418.  
  1419. PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic
  1420. extensions.
  1421.  
  1422. PERL_ARCHIVE_AFTER: path to a library which should be put on the
  1423. linker command line I<after> the external libraries to be linked to
  1424. dynamic extensions.  This may be needed if the linker is one-pass, and
  1425. Perl includes some overrides for C RTL functions, such as malloc().
  1426.  
  1427. EXPORT_LIST: name of a file that is passed to linker to define symbols
  1428. to be exported.
  1429.  
  1430. Some OSes do not need these in which case leave it blank.
  1431.  
  1432.  
  1433. =head3 init_platform
  1434.  
  1435.     $mm->init_platform
  1436.  
  1437. Initialize any macros which are for platform specific use only.
  1438.  
  1439. A typical one is the version number of your OS specific mocule.
  1440. (ie. MM_Unix_VERSION or MM_VMS_VERSION).
  1441.  
  1442. =cut
  1443.  
  1444. sub init_platform {
  1445.     return '';
  1446. }
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452. =head2 Tools
  1453.  
  1454. A grab bag of methods to generate specific macros and commands.
  1455.  
  1456.  
  1457.  
  1458. =head3 manifypods
  1459.  
  1460. Defines targets and routines to translate the pods into manpages and
  1461. put them into the INST_* directories.
  1462.  
  1463. =cut
  1464.  
  1465. sub manifypods {
  1466.     my $self          = shift;
  1467.  
  1468.     my $POD2MAN_macro = $self->POD2MAN_macro();
  1469.     my $manifypods_target = $self->manifypods_target();
  1470.  
  1471.     return <<END_OF_TARGET;
  1472.  
  1473. $POD2MAN_macro
  1474.  
  1475. $manifypods_target
  1476.  
  1477. END_OF_TARGET
  1478.  
  1479. }
  1480.  
  1481.  
  1482. =head3 POD2MAN_macro
  1483.  
  1484.   my $pod2man_macro = $self->POD2MAN_macro
  1485.  
  1486. Returns a definition for the POD2MAN macro.  This is a program
  1487. which emulates the pod2man utility.  You can add more switches to the
  1488. command by simply appending them on the macro.
  1489.  
  1490. Typical usage:
  1491.  
  1492.     $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ...
  1493.  
  1494. =cut
  1495.  
  1496. sub POD2MAN_macro {
  1497.     my $self = shift;
  1498.  
  1499. # Need the trailing '--' so perl stops gobbling arguments and - happens
  1500. # to be an alternative end of line seperator on VMS so we quote it
  1501.     return <<'END_OF_DEF';
  1502. POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--"
  1503. POD2MAN = $(POD2MAN_EXE)
  1504. END_OF_DEF
  1505. }
  1506.  
  1507.  
  1508. =head3 test_via_harness
  1509.  
  1510.   my $command = $mm->test_via_harness($perl, $tests);
  1511.  
  1512. Returns a $command line which runs the given set of $tests with
  1513. Test::Harness and the given $perl.
  1514.  
  1515. Used on the t/*.t files.
  1516.  
  1517. =cut
  1518.  
  1519. sub test_via_harness {
  1520.     my($self, $perl, $tests) = @_;
  1521.  
  1522.     return qq{\t$perl "-MExtUtils::Command::MM" }.
  1523.            qq{"-e" "test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n};
  1524. }
  1525.  
  1526. =head3 test_via_script
  1527.  
  1528.   my $command = $mm->test_via_script($perl, $script);
  1529.  
  1530. Returns a $command line which just runs a single test without
  1531. Test::Harness.  No checks are done on the results, they're just
  1532. printed.
  1533.  
  1534. Used for test.pl, since they don't always follow Test::Harness
  1535. formatting.
  1536.  
  1537. =cut
  1538.  
  1539. sub test_via_script {
  1540.     my($self, $perl, $script) = @_;
  1541.     return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n};
  1542. }
  1543.  
  1544.  
  1545. =head3 tool_autosplit
  1546.  
  1547. Defines a simple perl call that runs autosplit. May be deprecated by
  1548. pm_to_blib soon.
  1549.  
  1550. =cut
  1551.  
  1552. sub tool_autosplit {
  1553.     my($self, %attribs) = @_;
  1554.  
  1555.     my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};' 
  1556.                                   : '';
  1557.  
  1558.     my $asplit = $self->oneliner(sprintf <<'PERL_CODE', $maxlen);
  1559. use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1)
  1560. PERL_CODE
  1561.  
  1562.     return sprintf <<'MAKE_FRAG', $asplit;
  1563. # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
  1564. AUTOSPLITFILE = %s
  1565.  
  1566. MAKE_FRAG
  1567.  
  1568. }
  1569.  
  1570.  
  1571.  
  1572.  
  1573. =head2 File::Spec wrappers
  1574.  
  1575. ExtUtils::MM_Any is a subclass of File::Spec.  The methods noted here
  1576. override File::Spec.
  1577.  
  1578.  
  1579.  
  1580. =head3 catfile
  1581.  
  1582. File::Spec <= 0.83 has a bug where the file part of catfile is not
  1583. canonicalized.  This override fixes that bug.
  1584.  
  1585. =cut
  1586.  
  1587. sub catfile {
  1588.     my $self = shift;
  1589.     return $self->canonpath($self->SUPER::catfile(@_));
  1590. }
  1591.  
  1592.  
  1593.  
  1594. =head2 Misc
  1595.  
  1596. Methods I can't really figure out where they should go yet.
  1597.  
  1598.  
  1599. =head3 find_tests
  1600.  
  1601.   my $test = $mm->find_tests;
  1602.  
  1603. Returns a string suitable for feeding to the shell to return all
  1604. tests in t/*.t.
  1605.  
  1606. =cut
  1607.  
  1608. sub find_tests {
  1609.     my($self) = shift;
  1610.     return -d 't' ? 't/*.t' : '';
  1611. }
  1612.  
  1613.  
  1614. =head3 extra_clean_files
  1615.  
  1616.     my @files_to_clean = $MM->extra_clean_files;
  1617.  
  1618. Returns a list of OS specific files to be removed in the clean target in
  1619. addition to the usual set.
  1620.  
  1621. =cut
  1622.  
  1623. # An empty method here tickled a perl 5.8.1 bug and would return its object.
  1624. sub extra_clean_files { 
  1625.     return;
  1626. }
  1627.  
  1628.  
  1629. =head3 installvars
  1630.  
  1631.     my @installvars = $mm->installvars;
  1632.  
  1633. A list of all the INSTALL* variables without the INSTALL prefix.  Useful
  1634. for iteration or building related variable sets.
  1635.  
  1636. =cut
  1637.  
  1638. sub installvars {
  1639.     return qw(PRIVLIB SITELIB  VENDORLIB
  1640.               ARCHLIB SITEARCH VENDORARCH
  1641.               BIN     SITEBIN  VENDORBIN
  1642.               SCRIPT  SITESCRIPT  VENDORSCRIPT
  1643.               MAN1DIR SITEMAN1DIR VENDORMAN1DIR
  1644.               MAN3DIR SITEMAN3DIR VENDORMAN3DIR
  1645.              );
  1646. }
  1647.  
  1648.  
  1649. =head3 libscan
  1650.  
  1651.   my $wanted = $self->libscan($path);
  1652.  
  1653. Takes a path to a file or dir and returns an empty string if we don't
  1654. want to include this file in the library.  Otherwise it returns the
  1655. the $path unchanged.
  1656.  
  1657. Mainly used to exclude version control administrative directories from
  1658. installation.
  1659.  
  1660. =cut
  1661.  
  1662. sub libscan {
  1663.     my($self,$path) = @_;
  1664.     my($dirs,$file) = ($self->splitpath($path))[1,2];
  1665.     return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/, 
  1666.                      $self->splitdir($dirs), $file;
  1667.  
  1668.     return $path;
  1669. }
  1670.  
  1671.  
  1672. =head3 platform_constants
  1673.  
  1674.     my $make_frag = $mm->platform_constants
  1675.  
  1676. Returns a make fragment defining all the macros initialized in
  1677. init_platform() rather than put them in constants().
  1678.  
  1679. =cut
  1680.  
  1681. sub platform_constants {
  1682.     return '';
  1683. }
  1684.  
  1685.  
  1686. =head1 AUTHOR
  1687.  
  1688. Michael G Schwern <schwern@pobox.com> and the denizens of
  1689. makemaker@perl.org with code from ExtUtils::MM_Unix and
  1690. ExtUtils::MM_Win32.
  1691.  
  1692.  
  1693. =cut
  1694.  
  1695. 1;
  1696.