This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Generate Errno and Pod::Functions with deterministic order.
[perl5.git] / ext / Errno / Errno_pm.PL
index e0e328f..b372875 100644 (file)
@@ -2,7 +2,7 @@ use ExtUtils::MakeMaker;
 use Config;
 use strict;
 
-our $VERSION = "1.12";
+our $VERSION = "1.19";
 
 my %err = ();
 my %wsa = ();
@@ -81,19 +81,12 @@ sub process_file {
        }
     }
     
-    if ($^O eq 'MacOS') {
-       while(<FH>) {
-           $err{$1} = $2
-               if /^\s*#\s*define\s+(E\w+)\s+(\d+)/;
-       }
-    } else {
-       while(<FH>) {
-           $err{$1} = 1
-               if /^\s*#\s*define\s+(E\w+)\s+/;
-            if ($IsMSWin32) {
-               $wsa{$1} = 1
-                   if /^\s*#\s*define\s+WSA(E\w+)\s+/;
-            }
+    while(<FH>) {
+       $err{$1} = 1
+           if /^\s*#\s*define\s+(E\w+)\s+/;
+       if ($IsMSWin32) {
+           $wsa{$1} = 1
+               if /^\s*#\s*define\s+WSA(E\w+)\s+/;
        }
     }
 
@@ -132,12 +125,6 @@ sub get_files {
     } elsif ($^O eq 'os390') {
        # OS/390 C compiler doesn't generate #file or #line directives
        $file{'/usr/include/errno.h'} = 1;
-    } elsif ($^O eq 'vmesa') {
-       # OS/390 C compiler doesn't generate #file or #line directives
-       $file{'../../vmesa/errno.h'} = 1;
-    } elsif ($Config{archname} eq 'epoc') {
-       # Watch out for cross compiling for EPOC (usually done on linux)
-       $file{'/usr/local/epocemx/epocsdk/include/libc/sys/errno.h'} = 1;
     } elsif ($Config{archname} eq 'arm-riscos') {
        # Watch out for cross compiling for RISC OS
        my $dep = `echo "#include <errno.h>" | gcc -E -M -`;
@@ -154,12 +141,7 @@ sub get_files {
        my $linux_errno_h = -e '/usr/include/errno.h' ?
            '/usr/include/errno.h' : '/usr/local/include/errno.h';
        $file{$linux_errno_h} = 1;
-    } elsif ($^O eq 'MacOS') {
-       # note that we are only getting the GUSI errno's here ...
-       # we might miss out on compiler-specific ones
-       $file{"$ENV{GUSI}include:sys:errno.h"} = 1;
-
-    } elsif ($^O eq 'beos' || $^O eq 'haiku') {
+    } elsif ($^O eq 'haiku') {
        # hidden in a special place
        $file{'/boot/develop/headers/posix/errno.h'} = 1;
 
@@ -196,13 +178,7 @@ sub get_files {
                die "Cannot exec $cpp";
        }
 
-       my $pat;
-       if (($IsMSWin32 || $^O eq 'NetWare') and $Config{cc} =~ /^bcc/i) {
-           $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
-       }
-       else {
-           $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
-       }
+       my $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
        while(<CPPO>) {
            if ($^O eq 'os2' or $IsMSWin32 or $^O eq 'NetWare') {
                if (/$pat/o) {
@@ -241,6 +217,9 @@ sub write_errno_pm {
     if ($IsMSWin32) {
        print CPPI "#include <winsock.h>\n";
        foreach $err (keys %wsa) {
+           print CPPI "#if defined($err) && $err >= 100\n";
+           print CPPI "#undef $err\n";
+           print CPPI "#endif\n";
            print CPPI "#ifndef $err\n";
            print CPPI "#define $err WSA$err\n";
            print CPPI "#endif\n";
@@ -254,7 +233,7 @@ sub write_errno_pm {
 
     close(CPPI);
 
-    unless ($^O eq 'MacOS' || $^O eq 'beos') { # trust what we have / get later
+    {  # BeOS (support now removed) did not enter this block
     # invoke CPP and read the output
 
        if ($^O eq 'VMS') {
@@ -295,70 +274,39 @@ sub write_errno_pm {
        close(CPPO);
     }
 
-    # Many of the E constants (including ENOENT, which is being
-    # used in the Perl test suite a lot), are available only as
-    # enums in BeOS, so compiling and executing some code is about
-    # only way to find out what the numeric Evalues are. In fact above, we
-    # didn't even bother to get the values of the ones that have numeric
-    # values, since we can get all of them here, anyway.
-
-    if ($^O eq 'beos') {
-       if (open(C, ">errno.c")) {
-           my @allerrs = keys %err;
-           print C <<EOF;
-#include <errno.h>
-#include <stdio.h>
-int main() {
-EOF
-            for (@allerrs) {
-               print C qq[printf("$_ %d\n", $_);]
-           }
-            print C "}\n";
-            close C;
-            system("cc -o errno errno.c");
-            unlink("errno.c");
-            if (open(C, "./errno|")) {
-               while (<C>) {
-                   if (/^(\w+) (-?\d+)$/) { $err{$1} = $2 }
-               }
-               close(C);
-           } else {
-               die "failed to execute ./errno: $!\n";
-           }
-            unlink("errno");
-        } else {
-           die "failed to create errno.c: $!\n";
-       }
-    }
+    # escape $Config{'archname'}
+    my $archname = $Config{'archname'};
+    $archname =~ s/([@%\$])/\\\1/g;
 
     # Write Errno.pm
 
     print <<"EDQ";
+# -*- buffer-read-only: t -*-
 #
 # This file is auto-generated. ***ANY*** changes here will be lost
 #
 
 package Errno;
-our (\@ISA,\$VERSION);
-use Exporter ();
+require Exporter;
 use Config;
 use strict;
 
 "\$Config{'archname'}-\$Config{'osvers'}" eq
-"$Config{'archname'}-$Config{'osvers'}" or
-       die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
+"$archname-$Config{'osvers'}" or
+       die "Errno architecture ($archname-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
 
-\$VERSION = "$VERSION";
+our \$VERSION = "$VERSION";
 \$VERSION = eval \$VERSION;
-\@ISA = qw(Exporter);
+our \@ISA = 'Exporter';
 
 my %err;
 
 BEGIN {
     %err = (
 EDQ
-   
-    my @err = sort { $err{$a} <=> $err{$b} } keys %err;
+
+    my @err = sort { $err{$a} <=> $err{$b} || $a cmp $b }
+       grep { $err{$_} =~ /-?\d+$/ } keys %err;
 
     foreach $err (@err) {
        print "\t$err => $err{$err},\n";
@@ -367,22 +315,29 @@ EDQ
 print <<'ESQ';
     );
     # Generate proxy constant subroutines for all the values.
-    # We assume at this point that our symbol table is empty.
+    # Well, almost all the values. Unfortunately we can't assume that at this
+    # point that our symbol table is empty, as code such as if the parser has
+    # seen code such as C<exists &Errno::EINVAL>, it will have created the
+    # typeglob.
     # Doing this before defining @EXPORT_OK etc means that even if a platform is
     # crazy enough to define EXPORT_OK as an error constant, everything will
     # still work, because the parser will upgrade the PCS to a real typeglob.
     # We rely on the subroutine definitions below to update the internal caches.
     # Don't use %each, as we don't want a copy of the value.
     foreach my $name (keys %err) {
-        $Errno::{$name} = \$err{$name};
+        if ($Errno::{$name}) {
+            # We expect this to be reached fairly rarely, so take an approach
+            # which uses the least compile time effort in the common case:
+            eval "sub $name() { $err{$name} }; 1" or die $@;
+        } else {
+            $Errno::{$name} = \$err{$name};
+        }
     }
 }
 
-our (@EXPORT_OK, %EXPORT_TAGS);
-
-@EXPORT_OK = keys %err;
+our @EXPORT_OK = keys %err;
 
-%EXPORT_TAGS = (
+our %EXPORT_TAGS = (
     POSIX => [qw(
 ESQ
 
@@ -419,8 +374,7 @@ sub STORE {
     Carp::confess("ERRNO hash is read only!");
 }
 
-*CLEAR = \&STORE;
-*DELETE = \&STORE;
+*CLEAR = *DELETE = \*STORE; # Typeglob aliasing uses less space
 
 sub NEXTKEY {
     each %err;
@@ -493,6 +447,7 @@ under the same terms as Perl itself.
 
 =cut
 
+# ex: set ro:
 ESQ
 
 }