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