This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sync with the latest MakeMaker snapshot.
[perl5.git] / lib / ExtUtils / MM_Any.pm
index c0ffb2f..971fb8d 100644 (file)
@@ -2,7 +2,7 @@ package ExtUtils::MM_Any;
 
 use strict;
 use vars qw($VERSION @ISA);
-$VERSION = 0.05;
+$VERSION = 0.09;
 @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
 
@@ -44,6 +44,25 @@ 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);
@@ -68,6 +87,34 @@ sub os_flavor_is {
     return (grep { $flavors{$_} } @_) ? 1 : 0;
 }
 
+=item blibdirs_target (o)
+
+    my $make_frag = $mm->blibdirs_target;
+
+Creates the blibdirs target which creates all the directories we use in
+blib/.
+
+=cut
+
+sub blibdirs_target {
+    my $self = shift;
+
+    my @dirs = map { uc "\$(INST_$_)" } qw(libdir
+                                       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 :: Makefile.PL \n";
+    $make .= join "", map { "\t$_\n" } @mkpath, @chmod;
+    $make .= "\t\$(NOECHO) \$(TOUCH) blibdirs\n\n";
+
+    return $make;
+}
+
+
 =back
 
 =head2 File::Spec wrappers
@@ -159,7 +206,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;
@@ -307,18 +354,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
 
 }
@@ -357,7 +401,7 @@ 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
     }
 
@@ -413,27 +457,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
 }
 
@@ -490,7 +535,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;
@@ -557,12 +602,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}
@@ -574,10 +626,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
 
 }
@@ -594,12 +678,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