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