#! perl
my
(
$fh
,
$oldstdout
);
BEGIN {
open
$fh
,
">lib/AnyEvent/constants.pl"
or
die
"lib/AnyEvent/constants.pl: $!\n"
;
$oldstdout
=
select
$fh
;
print
"# automatically generated from constants.pl.PL\n"
;
}
{
no
warnings;
use
warnings
qw(FATAL closed threads internal debugging pack malloc portable prototype
inplace io pipe unpack glob digit printf
layer reserved taint closure semicolon)
;
no
warnings
qw(exec newline unopened)
;
BEGIN {
print
"sub AnyEvent::common_sense {\n"
;
printf
" local \$^W;\n"
;
printf
" \${^WARNING_BITS} ^= \${^WARNING_BITS} ^ \"%s\";\n"
,
join
""
,
map
"\\x$_"
,
unpack
"(H2)*"
, ${^WARNING_BITS};
printf
" \$^H |= 0x%x;\n"
, $^H;
print
"}\n"
;
}
}
print
"# generated for perl $] built for $Config{archname}\n"
;
BEGIN {
eval
"use Socket ()"
}
BEGIN {
eval
"use Fcntl ()"
}
BEGIN {
eval
"use POSIX ()"
}
sub
i($$) {
print
"sub $_[0](){"
,
$_
[1]*1,
"}\n"
;
}
sub
n($$) {
print
"sub $_[0](){"
, (
defined
$_
[1] ?
$_
[1]*1 :
"undef"
),
"}\n"
;
}
print
"package AnyEvent;\n"
;
our
$WIN32
= $^O =~ /mswin32/i;
i
CYGWIN
=> $^O =~ /cygwin/i;
i
WIN32
=>
$WIN32
;
i
F_SETFD
=>
eval
{ Fcntl::F_SETFD() } || 2;
i
F_SETFL
=>
eval
{ Fcntl::F_SETFL() } || 4;
i
O_NONBLOCK
=>
eval
{ Fcntl::O_NONBLOCK() } || 04000;
i
FD_CLOEXEC
=>
eval
{ Fcntl::FD_CLOEXEC() } || 1;
print
"package AnyEvent::Base;\n"
;
i
WNOHANG
=>
eval
{ POSIX::WNOHANG() } || 1;
print
"package AnyEvent::IO;\n"
;
i
O_RDONLY
=>
eval
{ Fcntl::O_RDONLY() } || 0;
i
O_WRONLY
=>
eval
{ Fcntl::O_WRONLY() } || 1;
i
O_RDWR
=>
eval
{ Fcntl::O_RDWR () } || 2;
i
O_CREAT
=>
eval
{ Fcntl::O_CREAT () } || 64;
i
O_EXCL
=>
eval
{ Fcntl::O_EXCL () } || 128;
i
O_TRUNC
=>
eval
{ Fcntl::O_TRUNC () } || 512;
i
O_APPEND
=>
eval
{ Fcntl::O_APPEND() } || 1024;
print
"package AnyEvent::Util;\n"
;
if
(
$WIN32
) {
i
WSAEINVAL
=> 10022;
i
WSAEWOULDBLOCK
=> 10035;
i
WSAEINPROGRESS
=> 10036;
}
else
{
i
WSAEINVAL
=> -1e99;
i
WSAEWOULDBLOCK
=> -1e99;
i
WSAEINPROGRESS
=> -1e99;
}
my
$af_inet6
;
$af_inet6
||=
eval
{ Socket::AF_INET6 () };
$af_inet6
||=
eval
{
require
Socket6; Socket6::AF_INET6() };
$af_inet6
||= 10
if
$^O =~ /linux/;
$af_inet6
||= 23
if
$^O =~ /cygwin/i;
$af_inet6
||= 23
if
AnyEvent::WIN32;
$af_inet6
||= 24
if
$^O =~ /openbsd|netbsd/;
$af_inet6
||= 28
if
$^O =~ /freebsd/;
i
_AF_INET6
=>
$af_inet6
;
print
"package AnyEvent::Socket;\n"
;
my
%const
;
while
(<DATA>) {
my
(
$os
,
$name
,
$default
) =
split
/\s+/;
$const
{
$name
} ||=
undef
;
next
unless
$os
eq $^O;
my
$value
=
eval
"Socket::$name ()"
;
$value
=
eval
$default
unless
defined
$value
;
$const
{
$name
} =
$value
;
}
for
my
$k
(
sort
keys
%const
) {
n
$k
,
$const
{
$k
};
}
print
"1;\n"
;
close
$fh
;
select
$oldstdout
;
1