Fix a2p manpage (from Debian)
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Any.pm
index 20c6bd6..df89c1f 100644 (file)
@@ -2,7 +2,7 @@ package ExtUtils::MM_Any;
 
 use strict;
 use vars qw($VERSION @ISA);
-$VERSION = 0.04;
+$VERSION = '0.10';
 @ISA = qw(File::Spec);
 
 use Config;
@@ -11,7 +11,7 @@ use File::Spec;
 
 =head1 NAME
 
-ExtUtils::MM_Any - Platform agnostic MM methods
+ExtUtils::MM_Any - Platform-agnostic MM methods
 
 =head1 SYNOPSIS
 
@@ -42,6 +42,99 @@ B<THIS MAY BE TEMPORARY!>
 These are methods which are by their nature cross-platform and should
 always be cross-platform.
 
+=over 4
+
+=item installvars
+
+    my @installvars = $mm->installvars;
+
+A list of all the INSTALL* variables without the INSTALL prefix.  Useful
+for iteration or building related variable sets.
+
+=cut
+
+sub installvars {
+    return qw(PRIVLIB SITELIB  VENDORLIB
+              ARCHLIB SITEARCH VENDORARCH
+              BIN     SITEBIN  VENDORBIN
+              SCRIPT
+              MAN1DIR SITEMAN1DIR VENDORMAN1DIR
+              MAN3DIR SITEMAN3DIR VENDORMAN3DIR
+             );
+}
+
+=item os_flavor_is
+
+    $mm->os_flavor_is($this_flavor);
+    $mm->os_flavor_is(@one_of_these_flavors);
+
+Checks to see if the current operating system is one of the given flavors.
+
+This is useful for code like:
+
+    if( $mm->os_flavor_is('Unix') ) {
+        $out = `foo 2>&1`;
+    }
+    else {
+        $out = `foo`;
+    }
+
+=cut
+
+sub os_flavor_is {
+    my $self = shift;
+    my %flavors = map { ($_ => 1) } $self->os_flavor;
+    return (grep { $flavors{$_} } @_) ? 1 : 0;
+}
+
+
+=item dir_target B<DEPRECATED>
+
+    my $make_frag = $mm->dir_target(@directories);
+
+I<This function is deprecated> its use is no longer necessary and is
+I<only provided for backwards compatibility>.  It is now a no-op.
+blibdirs_target provides a much simpler mechanism and pm_to_blib() can
+create its own directories anyway.
+
+=cut
+
+sub dir_target {}
+
+
+=item blibdirs_target (o)
+
+    my $make_frag = $mm->blibdirs_target;
+
+Creates the blibdirs.ts target which creates all the directories we use in
+blib/.
+
+=cut
+
+sub blibdirs_target {
+    my $self = shift;
+
+    my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib
+                                           autodir archautodir
+                                           bin script
+                                           man1dir man3dir
+                                          );
+    my @mkpath = $self->split_command('$(NOECHO) $(MKPATH)', @dirs);
+    my @chmod  = $self->split_command('$(NOECHO) $(CHMOD) 755', @dirs);
+
+    my $make = "\nblibdirs.ts :\n";
+    $make .= join "", map { "\t$_\n" } @mkpath, @chmod;
+    $make .= <<'MAKE';
+       $(NOECHO) $(TOUCH) $@
+
+MAKE
+
+    return $make;
+}
+
+
+=back
+
 =head2 File::Spec wrappers
 
 ExtUtils::MM_Any is a subclass of File::Spec.  The methods noted here
@@ -131,7 +224,7 @@ sub split_command {
         }
         chop $arg_str;
 
-        push @cmds, $self->escape_newlines("$cmd\n$arg_str");
+        push @cmds, $self->escape_newlines("$cmd \n$arg_str");
     } while @args;
 
     return @cmds;
@@ -213,7 +306,7 @@ Called by init_main.
 sub init_VERSION {
     my($self) = shift;
 
-    $self->{MAKEMAKER}  = $INC{'ExtUtils/MakeMaker.pm'};
+    $self->{MAKEMAKER}  = $ExtUtils::MakeMaker::Filename;
     $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION;
     $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision;
     $self->{VERSION_FROM} ||= '';
@@ -279,18 +372,15 @@ put them into the INST_* directories.
 sub manifypods {
     my $self          = shift;
 
-    my $POD2MAN_EXE_macro = $self->POD2MAN_EXE_macro();
+    my $POD2MAN_macro = $self->POD2MAN_macro();
     my $manifypods_target = $self->manifypods_target();
 
     return <<END_OF_TARGET;
 
-# --- Begin manifypods section:
-$POD2MAN_EXE_macro
+$POD2MAN_macro
 
 $manifypods_target
 
-# --- End manifypods section --- #
-
 END_OF_TARGET
 
 }
@@ -329,10 +419,11 @@ END
     foreach my $section (qw(1 3)) {
         my $pods = $self->{"MAN${section}PODS"};
         push @man_cmds, $self->split_command(<<CMD, %$pods);
-       \$(NOECHO) \$(POD2MAN_EXE) --section=$section --perm_rw=\$(PERM_RW)
+       \$(NOECHO) \$(POD2MAN) --section=$section --perm_rw=\$(PERM_RW)
 CMD
     }
 
+    $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds;
     $manify .= join '', map { "$_\n" } @man_cmds;
 
     return $manify;
@@ -384,27 +475,28 @@ MAKE_FRAG
     return $make_frag;
 }
 
-=item POD2MAN_EXE_macro
+=item POD2MAN_macro
 
-  my $pod2man_exe_macro = $self->POD2MAN_EXE_macro
+  my $pod2man_macro = $self->POD2MAN_macro
 
-Returns a definition for the POD2MAN_EXE macro.  This is a program
+Returns a definition for the POD2MAN macro.  This is a program
 which emulates the pod2man utility.  You can add more switches to the
 command by simply appending them on the macro.
 
 Typical usage:
 
-    $(POD2MAN_EXE) --section=3 --perm_rw=$(PERM_RW) podfile man_page
+    $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ...
 
 =cut
 
-sub POD2MAN_EXE_macro {
+sub POD2MAN_macro {
     my $self = shift;
 
 # Need the trailing '--' so perl stops gobbling arguments and - happens
 # to be an alternative end of line seperator on VMS so we quote it
     return <<'END_OF_DEF';
 POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--"
+POD2MAN = $(POD2MAN_EXE)
 END_OF_DEF
 }
 
@@ -461,7 +553,7 @@ installation.
 sub libscan {
     my($self,$path) = @_;
     my($dirs,$file) = ($self->splitpath($path))[1,2];
-    return '' if grep /^RCS|CVS|SCCS|\.svn$/, 
+    return '' if grep /^(?:RCS|CVS|SCCS|\.svn)$/, 
                      $self->splitdir($dirs), $file;
 
     return $path;
@@ -528,12 +620,19 @@ include:
 sub metafile_target {
     my $self = shift;
 
+    return <<'MAKE_FRAG' if $self->{NO_META};
+metafile:
+       $(NOECHO) $(NOOP)
+MAKE_FRAG
+
     my $prereq_pm = '';
-    while( my($mod, $ver) = each %{$self->{PREREQ_PM}} ) {
+    foreach my $mod ( sort { lc $a cmp lc $b } keys %{$self->{PREREQ_PM}} ) {
+        my $ver = $self->{PREREQ_PM}{$mod};
         $prereq_pm .= sprintf "    %-30s %s\n", "$mod:", $ver;
     }
-    
+
     my $meta = <<YAML;
+# http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         $self->{DISTNAME}
 version:      $self->{VERSION}
@@ -545,10 +644,42 @@ distribution_type: module
 generated_by: ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION
 YAML
 
-    my @write_meta = $self->echo($meta, 'META.yml');
-    return sprintf <<'MAKE_FRAG', join "\n\t", @write_meta;
+    my @write_meta = $self->echo($meta, 'META_new.yml');
+    my $move = $self->oneliner(<<'CODE', ['-MExtUtils::Command', '-MFile::Compare']);
+compare(@ARGV) != 0 ? (mv or warn "Cannot move @ARGV: $$!\n") : unlink(shift);
+CODE
+
+    return sprintf <<'MAKE_FRAG', join("\n\t", @write_meta), $move;
 metafile :
+       $(NOECHO) $(ECHO) Generating META.yml
        %s
+       -$(NOECHO) %s META_new.yml META.yml
+MAKE_FRAG
+
+}
+
+
+=item signature_target
+
+    my $target = $mm->signature_target;
+
+Generate the signature target.
+
+Writes the file SIGNATURE with "cpansign -s".
+
+=cut
+
+sub signature_target {
+    my $self = shift;
+
+    return <<'MAKE_FRAG' if !$self->{SIGN};
+signature :
+       $(NOECHO) $(NOOP)
+MAKE_FRAG
+
+    return <<'MAKE_FRAG';
+signature :  signature_addtomanifest
+       cpansign -s
 MAKE_FRAG
 
 }
@@ -565,12 +696,49 @@ Adds the META.yml file to the MANIFEST.
 sub metafile_addtomanifest_target {
     my $self = shift;
 
+    return <<'MAKE_FRAG' if $self->{NO_META};
+metafile_addtomanifest:
+       $(NOECHO) $(NOOP)
+MAKE_FRAG
+
     my $add_meta = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
-maniadd({q{META.yml} => q{Module meta-data in YAML}});
+eval { maniadd({q{META.yml} => q{Module meta-data (added by MakeMaker)}}) } 
+    or print "Could not add META.yml to MANIFEST: $${'@'}\n"
 CODE
 
     return sprintf <<'MAKE_FRAG', $add_meta;
 metafile_addtomanifest:
+       $(NOECHO) $(ECHO) Adding META.yml to MANIFEST
+       $(NOECHO) %s
+MAKE_FRAG
+
+}
+
+
+=item signature_addtomanifest_target
+
+  my $target = $mm->signature_addtomanifest_target
+
+Adds the META.yml file to the MANIFEST.
+
+=cut
+
+sub signature_addtomanifest_target {
+    my $self = shift;
+
+    return <<'MAKE_FRAG' if !$self->{SIGN};
+signature_addtomanifest :
+       $(NOECHO) $(NOOP)
+MAKE_FRAG
+
+    my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
+eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) } 
+    or print "Could not add SIGNATURE to MANIFEST: $${'@'}\n"
+CODE
+
+    return sprintf <<'MAKE_FRAG', $add_sign;
+signature_addtomanifest :
+       $(NOECHO) $(ECHO) Adding SIGNATURE to MANIFEST
        $(NOECHO) %s
 MAKE_FRAG
 
@@ -665,8 +833,8 @@ Defines at least these macros.
 
   Macro             Description
 
-  NOOP              
-  NOECHO                                        
+  NOOP              Do nothing
+  NOECHO            Tell make not to display the command itself
 
   MAKEFILE
   FIRST_MAKEFILE
@@ -676,6 +844,7 @@ Defines at least these macros.
   SHELL             Program used to run
                     shell commands
 
+  ECHO              Print text adding a newline on the end
   RM_F              Remove a file 
   RM_RF             Remove a directory          
   TOUCH             Update a file's timestamp   
@@ -755,6 +924,28 @@ sub platform_constants {
     return '';
 }
 
+=item os_flavor
+
+    my @os_flavor = $mm->os_flavor;
+
+@os_flavor is the style of operating system this is, usually
+corresponding to the MM_*.pm file we're using.  
+
+The first element of @os_flavor is the major family (ie. Unix,
+Windows, VMS, OS/2, etc...) and the rest are sub families.
+
+Some examples:
+
+    Cygwin98       ('Unix',  'Cygwin', 'Cygwin9x')
+    Windows NT     ('Win32', 'WinNT')
+    Win98          ('Win32', 'Win9x')
+    Linux          ('Unix',  'Linux')
+    MacOS X        ('Unix',  'Darwin', 'MacOS', 'MacOS X')
+    OS/2           ('OS/2')
+
+This is used to write code for styles of operating system.  
+See os_flavor_is() for use.
+
 
 =back