This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #113940] Make make_ext delete Makefiles when version changes
authorFather Chrysostomos <sprout@cpan.org>
Sun, 29 Jul 2012 05:48:27 +0000 (22:48 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 29 Jul 2012 17:51:30 +0000 (10:51 -0700)
This eliminates this annoyance:

$ ./perl -Ilib -MStorable -e0
Storable object version 2.37 does not match bootstrap parameter 2.38 at lib/XSLoader.pm line 95.
Compilation failed in require.
BEGIN failed--compilation aborted.

make_ext.pl

index 28a67a3..3254628 100644 (file)
@@ -281,6 +281,28 @@ sub build_extension {
        $makefile = 'Makefile';
     }
     
+    if (-f $makefile) {
+       open my $mfh, $makefile or die "Cannot open $makefile: $!";
+       while (<$mfh>) {
+           # Plagiarised from CPAN::Distribution
+           last if /MakeMaker post_initialize section/;
+           next unless /^#\s+VERSION_FROM\s+=>\s+(.+)/;
+           my $vmod = eval $1;
+           my $oldv;
+           while (<$mfh>) {
+               next unless /^XS_VERSION = (\S+)/;
+               $oldv = $1;
+               last;
+           }
+           last unless defined $oldv;
+           require ExtUtils::MM_Unix;
+           defined (my $newv = parse_version MM $vmod) or last;
+           if ($newv ne $oldv) {
+               1 while unlink $makefile
+           }
+       }
+    }
+
     if (!-f $makefile) {
        if (!-f 'Makefile.PL') {
            print "\nCreating Makefile.PL in $ext_dir for $mname\n";