This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add required dependency for $(VERSION_FROM) target in Makefile.PL
[perl5.git] / dist / Devel-PPPort / Makefile.PL
index 7c2064a..97b02d0 100644 (file)
 require 5.003;
 
 use strict;
+BEGIN { $^W = 1; }
+
 use ExtUtils::MakeMaker;
+use Config;
 
 use vars '%opt';  # needs to be global, and we can't use 'our'
 
@@ -35,31 +38,64 @@ my %mf = (
   XSPROTOARG    => '-noprototypes',
   CONFIGURE     => \&configure,
 );
-delete $mf{META_MERGE} unless eval { ExtUtils::MakeMaker->VERSION (6.46) };
 WriteMakefile(%mf);
 
 sub configure
 {
   my @clean    = qw{ $(H_FILES) RealPPPort.xs RealPPPort.c PPPort.pm };
-  my %depend   = ('$(OBJECT)' => '$(H_FILES)');
+  my %depend   = (
+    '$(OBJECT)' => '$(H_FILES)',
+    'Makefile' => '$(VERSION_FROM)',
+  );
   my @C_FILES  = qw{ module2.c module3.c },
   my %PL_FILES = (
     'ppport_h.PL'  => 'ppport.h',
     'PPPort_pm.PL' => 'PPPort.pm',
     'RealPPPort_xs.PL' => 'RealPPPort.xs',
+    'mktests.PL' => 't/01_test.t',
   );
   my @moreopts;
 
-  if (eval $ExtUtils::MakeMaker::VERSION >= 6) {
+  if (eval { ExtUtils::MakeMaker->VERSION(6) }) {
     push @moreopts, AUTHOR => 'Marcus Holland-Moritz <mhx@cpan.org>';
     push @moreopts, ABSTRACT_FROM => 'PPPort_pm.PL';
   }
 
-  if (eval $ExtUtils::MakeMaker::VERSION >= 6.30_01) {
+  if (eval { ExtUtils::MakeMaker->VERSION(6.30_01) }) {
     print "Setting license tag...\n";
     push @moreopts, LICENSE => 'perl';
   }
 
+  if (eval { ExtUtils::MakeMaker->VERSION (6.46) }) {
+    open FH, '<PPPort_pm.PL' or die "cannot open PPPort_pm.PL for reading: $!";
+    my $version;
+    while (my $line = <FH>) {
+      ($version) = $line =~ /^\$VERSION = '([\d.]+)';$/ and last;
+    };
+    die 'failed to extract $VERSION from PPPort_pm.PL' if not $version;
+    close FH;
+    print "Adding META_MERGE...\n";
+    push @moreopts, META_MERGE => {
+      'meta-spec' => { version => 2 },
+      provides => {
+        'Devel::PPPort' => {
+          file    => 'PPPort_pm.PL',
+          version => $version,
+        },
+      },
+      resources => {
+        bugtracker => {
+          web => 'https://rt.perl.org/rt3/',
+        },
+        repository => {
+          type => 'git',
+          url  => 'git://perl5.git.perl.org/perl.git',
+          web  => 'https://perl5.git.perl.org/perl.git',
+        },
+      },
+    };
+  }
+
   if (not $ENV{'PERL_CORE'}) {
     # Devel::PPPort is in the core since 5.7.3
     # 5.11.0+ has site before perl
@@ -77,13 +113,11 @@ sub configure
     $depend{'apicheck.i'} = 'ppport.h';
   }
 
-  open FH, '<PPPort_pm.PL' or die "cannot open PPPort_pm.PL for reading: $!";
-  my $version;
-  while (my $line = <FH>) {
-    ($version) = $line =~ /^\$VERSION = '([\d.]+)';$/ and last;
-  };
-  die 'failed to extract $VERSION from PPPort_pm.PL' if not $version;
-  close FH;
+  if ($Config{gccversion}) {
+    my $define = '-W -Wall';
+    $define .= ' -Wdeclaration-after-statement' if $Config{gccversion} =~ /^(\d+\.\d+)\./ && $1 >= 3.4;
+    push @moreopts, DEFINE => $define;
+  }
 
   return {
     C        => \@C_FILES,
@@ -91,25 +125,6 @@ sub configure
     PL_FILES => \%PL_FILES,
     depend   => \%depend,
     clean    => { FILES => "@clean" },
-    META_MERGE    => {
-      'meta-spec' => { version => 2 },
-      provides => {
-        'Devel::PPPort' => {
-          file    => 'PPPort_pm.PL',
-          version => $version,
-        },
-      },
-      resources => {
-        bugtracker => {
-          web => 'https://rt.perl.org/rt3/',
-        },
-        repository => {
-          type => 'git',
-          url  => 'git://perl5.git.perl.org/perl.git',
-          web  => 'https://perl5.git.perl.org/perl.git',
-        },
-      },
-    },
     @moreopts,
   };
 }
@@ -141,6 +156,36 @@ POSTAMBLE
   return $post;
 }
 
+sub MY::processPL
+{
+  package MY;
+  my $original = shift->SUPER::processPL(@_);
+
+  require "./parts/ppptools.pl";
+  my $includes = join ' ', all_files_in_dir('parts/inc');
+
+  my $updated = '';
+  my @rules = split( m{^\s*$}m, $original );
+  foreach my $rule ( @rules ) {
+    if ( $rule =~ m{^\s*^PPPort\.pm\s+:}m ) {
+      $rule =~ s{^(\s*^PPPort\.pm\s+:.*)}{$1 $includes}m; # PPPort.pm depends on all files from parts/inc
+      $rule =~ s{pm_to_blib}{}m; # PPPort.pm must not depend on built PPPort.pm in blib/
+    } elsif ( $rule =~ m{^\s*^ppport\.h\s+:}m ) {
+      $rule =~ s{^(\s*^ppport\.h\s+:.*)}{$1 PPPort.pm}m; # ppport.h depends on PPPort.pm
+      $rule =~ s{pm_to_blib}{}m; # ppport.h is used to build RealPPPort.xs so cannot depend on built PPPort in blib/
+    } elsif ( $rule =~ m{^\s*^RealPPPort\.xs\s+:}m ) {
+      $rule =~ s{^(\s*^RealPPPort\.xs\s+:.*)}{$1 ppport.h}m; # RealPPPort.xs depends on ppport.h
+      $rule =~ s{pm_to_blib}{}m; # RealPPPort.xs is used to build PPPort binary, so it cannot depend on it
+    } elsif ( $rule =~ m{^\s*\S+\b01_test\.t\s+:}m ) {
+      $rule =~ s{^(\s*^\S+\b01_test\.t\s+:.*)}{$1 $includes}m; # all tests in t/ depends on all files from parts/inc
+      $rule =~ s{pm_to_blib}{}m; # Generating test files does not depend on built PPPort in blib/
+    }
+    $updated .= $rule;
+  }
+
+  return $updated;
+}
+
 sub MY::dist_core
 {
   package MY;
@@ -150,6 +195,7 @@ sub MY::dist_core
   my @rules = split( m{^\s*$}m, $dist );
   foreach my $rule ( @rules ) {
     if ( $rule =~ m{^\s*^dist\s+:}m ) {
+        $rule =~ s{:}{: manifest}; # make sure we regenerate the manifest
         $rule .= qq[\t].q[$(NOECHO) $(ECHO) "Warning: Please check '__MAX_PERL__' value in PPPort_pm.PL"].qq[\n];
     }
     $updated .= $rule;