This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade Socket to 2.002
[perl5.git] / cpan / Socket / Makefile.PL
CommitLineData
37b1de1b
CBW
1#!perl
2use strict;
3use warnings;
4
42793c05 5use ExtUtils::MakeMaker;
735631af 6use ExtUtils::Constant 0.23 'WriteConstants';
d6a66728 7use Config;
1584259f
PLE
8
9my @DEFINES;
1584259f 10
37b1de1b
CBW
11my $cb;
12my $seq = 0;
13sub check_for
14{
15 my %args = @_;
16 return if exists $Config{$args{confkey}};
17
18 require ExtUtils::CBuilder;
19 $cb ||= ExtUtils::CBuilder->new( quiet => 1 );
20
21 my $main = $args{main};
22
23 print "Checking $args{define}...\n";
1584259f 24
37b1de1b
CBW
25 my $file_base = "test-$seq"; $seq++;
26
27 my $file_source = "$file_base.c";
28
29 {
30 open( my $file_source_fh, ">", $file_source ) or die "Cannot write $file_source - $!";
31 print $file_source_fh <<"EOF";
1584259f 32#include <sys/types.h>
3be135d8
TC
33#ifdef WIN32
34# include <ws2tcpip.h>
35# include <winsock.h>
36#else
37# include <sys/socket.h>
38# include <netdb.h>
39# include <netinet/in.h>
40# include <arpa/inet.h>
41#endif
37b1de1b
CBW
42int main(int argc, char *argv[])
43 {
9dea6244
CBW
44 (void)argc;
45 (void)argv;
37b1de1b 46 $main
1584259f 47 return 0;
37b1de1b 48 }
1584259f 49EOF
1584259f
PLE
50 }
51
37b1de1b
CBW
52 my $file_obj = eval { $cb->compile( source => $file_source ) };
53 unlink $file_source;
54
55 return 0 unless defined $file_obj;
56
57 my $file_exe = eval { $cb->link_executable( objects => $file_obj ) };
58 unlink $file_obj;
59
60 return 0 unless defined $file_exe;
61
62 # Don't need to try running it
63 unlink $file_exe;
64
65 push @DEFINES, $args{define};
1584259f 66}
1584259f 67
37b1de1b
CBW
68sub check_for_func
69{
70 my %args = @_;
71 my $func = delete $args{func};
9dea6244 72 check_for( %args, main => "void *p = &$func; (void)p;" );
1584259f 73}
1584259f 74
37b1de1b
CBW
75my %defines = (
76 # -Dfoo func() $Config{key}
77 HAS_GETADDRINFO => [ "getaddrinfo", "d_getaddrinfo" ],
78 HAS_GETNAMEINFO => [ "getnameinfo", "d_getnameinfo" ],
79 HAS_INET_ATON => [ "inet_aton", "d_inetaton" ],
80 HAS_INETNTOP => [ "inet_ntop", "d_inetntop" ],
81 HAS_INETPTON => [ "inet_pton", "d_inetpton" ],
82);
83
84foreach my $define ( sort keys %defines ) {
85 my ( $func, $key ) = @{$defines{$define}};
86 check_for_func(
87 confkey => $key,
88 define => $define,
89 func => $func
90 );
1584259f
PLE
91}
92
37b1de1b
CBW
93check_for(
94 confkey => "d_sockaddr_sa_len",
95 define => "HAS_SOCKADDR_SA_LEN",
96 main => "struct sockaddr sa; sa.sa_len = 0;"
97);
98
99check_for(
eabcd9c8 100 confkey => "d_sockaddr_in6",
9dea6244
CBW
101 define => "HAS_SOCKADDR_IN6",
102 main => "struct sockaddr_in6 sin6; sin6.sin6_family = AF_INET6;"
103);
104
105check_for(
37b1de1b
CBW
106 confkey => "d_sin6_scope_id",
107 define => "HAS_SIN6_SCOPE_ID",
108 main => "struct sockaddr_in6 sin6; sin6.sin6_scope_id = 0;"
109);
110
3be135d8
TC
111# TODO: Needs adding to perl5 core before importing dual-life again
112check_for(
113 confkey => "d_ip_mreq",
114 define => "HAS_IP_MREQ",
115 main => "struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = INADDR_ANY;"
116);
117
9dea6244 118check_for(
eabcd9c8 119 confkey => "d_ipv6_mreq",
9dea6244
CBW
120 define => "HAS_IPV6_MREQ",
121 main => "struct ipv6_mreq mreq; mreq.ipv6mr_interface = 0;"
122);
123
37b1de1b
CBW
124my %makefile_args;
125
126# Since we're providing a later version of a core module, before 5.12 the
127# @INC order is wrong so we'll have to go in perl rather than site dirs
128$makefile_args{INSTALLDIRS} = "perl" if $] < 5.012;
129
4ad3186e 130WriteMakefile(
eabcd9c8
A
131 NAME => 'Socket',
132 VERSION_FROM => 'Socket.pm',
133 # ABSTRACT_FROM gets confused by C<Socket>
134 ABSTRACT => 'networking constants and support functions',
d6a66728 135 ($Config{libs} =~ /(-lsocks\S*)/ ? (LIBS => [ "$1" ] ) : ()),
eabcd9c8
A
136 XSPROTOARG => '-noprototypes', # XXX remove later?
137 realclean => {FILES=> 'const-c.inc const-xs.inc'},
138 DEFINE => join( " ", map { "-D$_" } @DEFINES ),
1584259f 139 CONFIGURE_REQUIRES => {
37b1de1b 140 'ExtUtils::CBuilder' => 0,
1584259f
PLE
141 'ExtUtils::Constant' => '0.23',
142 },
9dea6244 143 MIN_PERL_VERSION => '5.006001',
eabcd9c8 144 LICENSE => 'perl',
37b1de1b 145 %makefile_args,
4ad3186e 146);
c2654555
CBW
147my @names = (
148 qw(
149 AF_802 AF_AAL AF_APPLETALK AF_CCITT AF_CHAOS AF_CTF AF_DATAKIT
150 AF_DECnet AF_DLI AF_ECMA AF_GOSIP AF_HYLINK AF_IMPLINK AF_INET AF_INET6
151 AF_ISO AF_KEY AF_LAST AF_LAT AF_LINK AF_MAX AF_NBS AF_NIT AF_NS AF_OSI
152 AF_OSINET AF_PUP AF_ROUTE AF_SNA AF_UNIX AF_UNSPEC AF_USER AF_WAN
153 AF_X25
154
155 AI_ADDRCONFIG AI_ALL AI_CANONIDN AI_CANONNAME AI_IDN
156 AI_IDN_ALLOW_UNASSIGNED AI_IDN_USE_STD3_ASCII_RULES AI_NUMERICHOST
157 AI_NUMERICSERV AI_PASSIVE AI_V4MAPPED
158
159 EAI_ADDRFAMILY EAI_AGAIN EAI_BADFLAGS EAI_BADHINTS EAI_FAIL EAI_FAMILY
160 EAI_NODATA EAI_NONAME EAI_PROTOCOL EAI_SERVICE EAI_SOCKTYPE EAI_SYSTEM
161
162 IOV_MAX
163
3be135d8
TC
164 IP_ADD_MEMBERSHIP IP_DROP_MEMBERSHIP IP_HDRINCL IP_MULTICAST_IF
165 IP_MULTICAST_LOOP IP_MULTICAST_TTL IP_OPTIONS IP_RECVOPTS
166 IP_RECVRETOPTS IP_RETOPTS IP_TOS IP_TTL
c2654555
CBW
167
168 IPV6_ADD_MEMBERSHIP IPV6_DROP_MEMBERSHIP IPV6_MTU IPV6_MTU_DISCOVER
169 IPV6_MULTICAST_HOPS IPV6_MULTICAST_IF IPV6_MULTICAST_LOOP
170 IPV6_UNICAST_HOPS IPV6_V6ONLY
171
172 MSG_BCAST MSG_BTAG MSG_CTLFLAGS MSG_CTLIGNORE MSG_DONTWAIT MSG_EOF
173 MSG_EOR MSG_ERRQUEUE MSG_ETAG MSG_FIN MSG_MAXIOVLEN MSG_MCAST
174 MSG_NOSIGNAL MSG_RST MSG_SYN MSG_TRUNC MSG_URG MSG_WAITALL MSG_WIRE
175
176 NI_DGRAM NI_IDN NI_IDN_ALLOW_UNASSIGNED NI_IDN_USE_STD3_ASCII_RULES
177 NI_NAMEREQD NI_NOFQDN NI_NUMERICHOST NI_NUMERICSERV
178
179 PF_802 PF_AAL PF_APPLETALK PF_CCITT PF_CHAOS PF_CTF PF_DATAKIT
180 PF_DECnet PF_DLI PF_ECMA PF_GOSIP PF_HYLINK PF_IMPLINK PF_INET PF_INET6
181 PF_ISO PF_KEY PF_LAST PF_LAT PF_LINK PF_MAX PF_NBS PF_NIT PF_NS PF_OSI
182 PF_OSINET PF_PUP PF_ROUTE PF_SNA PF_UNIX PF_UNSPEC PF_USER PF_WAN
183 PF_X25
184
185 SCM_CONNECT SCM_CREDENTIALS SCM_CREDS SCM_TIMESTAMP
186
187 SOCK_DGRAM SOCK_RAW SOCK_RDM SOCK_SEQPACKET SOCK_STREAM
3be135d8 188 SOCK_NONBLOCK SOCK_CLOEXEC
c2654555
CBW
189
190 SOL_SOCKET
191
192 SOMAXCONN
193
194 SO_ACCEPTCONN SO_ATTACH_FILTER SO_BACKLOG SO_BROADCAST SO_CHAMELEON
eabcd9c8
A
195 SO_DEBUG SO_DETACH_FILTER SO_DGRAM_ERRIND SO_DOMAIN SO_DONTLINGER
196 SO_DONTROUTE SO_ERROR SO_FAMILY SO_KEEPALIVE SO_LINGER SO_OOBINLINE
197 SO_PASSCRED SO_PASSIFNAME SO_PEERCRED SO_PROTOCOL SO_PROTOTYPE
198 SO_RCVBUF SO_RCVLOWAT SO_RCVTIMEO SO_REUSEADDR SO_REUSEPORT
c2654555
CBW
199 SO_SECURITY_AUTHENTICATION SO_SECURITY_ENCRYPTION_NETWORK
200 SO_SECURITY_ENCRYPTION_TRANSPORT SO_SNDBUF SO_SNDLOWAT SO_SNDTIMEO
201 SO_STATE SO_TYPE SO_USELOOPBACK SO_XOPEN SO_XSE
202
203 TCP_KEEPALIVE TCP_MAXRT TCP_MAXSEG TCP_NODELAY TCP_STDURG TCP_CORK
204 TCP_KEEPIDLE TCP_KEEPINTVL TCP_KEEPCNT TCP_SYNCNT TCP_LINGER2
205 TCP_DEFER_ACCEPT TCP_WINDOW_CLAMP TCP_INFO TCP_QUICKACK TCP_CONGESTION
206 TCP_MD5SIG
207
208 UIO_MAXIOV
209 ),
210 {name=>"IPPROTO_IP", type=>"IV", default=>["IV", 0]},
211 {name=>"IPPROTO_IPV6", type=>"IV", default=>["IV", 41]},
212 {name=>"IPPROTO_RAW", type=>"IV", default=>["IV", 255]},
213 {name=>"IPPROTO_ICMP", type=>"IV", default=>["IV", 1]},
214 {name=>"IPPROTO_TCP", type=>"IV", default=>["IV", 6]},
215 {name=>"IPPROTO_UDP", type=>"IV", default=>["IV", 17]},
216 {name=>"SHUT_RD", type=>"IV", default=>["IV", "0"]},
217 {name=>"SHUT_WR", type=>"IV", default=>["IV", "1"]},
218 {name=>"SHUT_RDWR", type=>"IV", default=>["IV", "2"]},
0552bf3a
NC
219);
220
c2654555
CBW
221push @names, {
222 name => $_,
223 type => "IV",
224 macro => [ "#if defined($_) || defined(HAS_$_) /* might be an enum */\n",
225 "#endif\n" ]
226} foreach qw (MSG_CTRUNC MSG_DONTROUTE MSG_OOB MSG_PEEK MSG_PROXY SCM_RIGHTS);
227
228push @names, {
229 name => $_,
230 type => "SV",
231 pre => "struct in_addr ip_address; ip_address.s_addr = htonl($_);",
232 value => "newSVpvn_flags((char *)&ip_address,sizeof(ip_address), SVs_TEMP)",
233} foreach qw(INADDR_ANY INADDR_LOOPBACK INADDR_NONE INADDR_BROADCAST);
234
235push @names, {
236 name => $_,
237 type => "SV",
238 macro => [ "#ifdef ${_}_INIT\n",
239 "#endif\n" ],
240 pre => "struct in6_addr ip6_address = ${_}_INIT;",
241 value => "newSVpvn_flags((char *)&ip6_address,sizeof(ip6_address), SVs_TEMP)",
242} foreach qw(IN6ADDR_ANY IN6ADDR_LOOPBACK);
6b0aeb77 243
9dea6244
CBW
244# Work around an old Perl core bug that affects ExtUtils::Constants on
245# pre-5.8.2 Perls. EU:C should be amended to work around this itself.
246if("$]" < 5.008002) {
247 require ExtUtils::Constant::ProxySubs;
248 no warnings "once";
249 $ExtUtils::Constant::ProxySubs::type_to_C_value{$_} = sub { () }
250 foreach qw(YES NO UNDEF), "";
251}
252
0552bf3a 253WriteConstants(
7f39e0ae 254 PROXYSUBS => {autoload => 1},
0552bf3a
NC
255 NAME => 'Socket',
256 NAMES => \@names,
257);