This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Unicode-Collate to CPAN version 1.00
[perl5.git] / make_ext.pl
index 3254628..a5ece30 100644 (file)
@@ -1,6 +1,7 @@
 #!./miniperl
 use strict;
 use warnings;
+use constant IS_CROSS => defined $::Cross::platform ? 1 : 0;
 use Config;
 
 my $is_Win32 = $^O eq 'MSWin32';
@@ -43,8 +44,9 @@ my $ext_dirs_re = '(?:' . join('|', @ext_dirs) . ')';
 # Mostly because they still not ported to specified platform.
 # 
 # If any extensions are listed with a '+' char then only those
-# extensions will be built, but only if they arent countermanded
+# extensions will be built, but only if they aren't countermanded
 # by an '!ext' and are appropriate to the type of building being done.
+# An extensions follows the format of Foo/Bar, which would be extension Foo::Bar
 
 # It may be deleted in a later release of perl so try to
 # avoid using it for other purposes.
@@ -154,7 +156,7 @@ if ($is_Win32) {
     unless (-f "$pl2bat.bat") {
        my @args = ($perl, "-I$topdir\\lib", ("$pl2bat.pl") x 2);
        print "@args\n";
-       system(@args) unless defined $::Cross::platform;
+       system(@args) unless IS_CROSS;
     }
 
     print "In $build";
@@ -298,12 +300,43 @@ sub build_extension {
            require ExtUtils::MM_Unix;
            defined (my $newv = parse_version MM $vmod) or last;
            if ($newv ne $oldv) {
-               1 while unlink $makefile
+               close $mfh or die "close $makefile: $!";
+               _unlink($makefile);
+               {
+                   no warnings 'deprecated';
+                   goto NO_MAKEFILE;
+               }
            }
        }
+       if(IS_CROSS){
+           seek($mfh, 0, 0) or die "Cannot seek $makefile: $!";
+           while (<$mfh>) {
+               #this is used to stop the while loop early for efficiency when
+               #the line is reached, and possibly match a cross build
+               my $header = quotemeta '# These definitions are from config.sh (via ';
+               if(/^$header.+?
+                   (xlib[\/\\]
+                   $::Cross::platform\Q\/Config.pm\E)?\)\./x) {
+                   unless (defined $1){
+                       print "Deleting non-Cross makefile\n";
+                       close $mfh or die "close $makefile: $!";
+                       _unlink($makefile);
+                       {
+                           no warnings 'deprecated';
+                           goto NO_MAKEFILE;
+                       }
+                   } else { #have a cross makefile
+                       goto CROSS_OK_MF;
+                   }
+               }
+           } #catch breakage from future changes
+           die "non-standard makefile found in $mname";
+           CROSS_OK_MF:
+       }
     }
 
     if (!-f $makefile) {
+       NO_MAKEFILE:
        if (!-f 'Makefile.PL') {
            print "\nCreating Makefile.PL in $ext_dir for $mname\n";
            my ($fromname, $key, $value);
@@ -323,6 +356,7 @@ sub build_extension {
                my $leafname = "$leaf.pm";
                my $pathname = join '/', @dirs, $leafname;
                my @locations = ($leafname, $pathname, "lib/$pathname");
+               unshift @locations, 'lib/IO/Compress/Base.pm' if $mname eq 'IO::Compress';
                foreach (@locations) {
                    if (-f $_) {
                        $fromname = $_;
@@ -407,7 +441,7 @@ EOM
 
        # Presumably this can be simplified
        my @cross;
-       if (defined $::Cross::platform) {
+       if (IS_CROSS) {
            # Inherited from win32/buildext.pl
            @cross = "-MCross=$::Cross::platform";
        } elsif ($opts{cross}) {
@@ -503,3 +537,11 @@ sub _quote_args {
     } @{$args}
     ;
 }
+
+#guarentee that a file is deleted or die, void _unlink($filename)
+#xxx replace with _unlink_or_rename from EU::Install?
+sub _unlink {
+    1 while unlink $_[0];
+    my $err = $!;
+    die "Can't unlink $_[0]: $err" if -f $_[0];
+}